2013-07-16 6 views
5

मैं इस प्रकार तालिका सेल बना रहा हूं:मैं ओपनएक्सएमएल टेबलसेल के अग्रभूमि और पृष्ठभूमि रंग को कैसे संशोधित कर सकता हूं?

private static TableCell GetHeaderCell(string cellText) 
{ 
    var tc = new TableCell(new Paragraph(new Run(new Text(cellText)))); 
    return tc; 
} 

मैं इसे सफेद पाठ के साथ नीले रंग होना चाहता हूँ।

मैंने निम्नलिखित की कोशिश की है, लेकिन यह काम नहीं करता है;

private static TableCell GetHeaderCell(string cellText) 
{ 
    var props = new TableCellProperties(); 
    var solidFill = new SolidFill(); 
    var rgbColorHex = new RgbColorModelHex() { Val = "FF0000" };//Red Background for Single TableCell. 

    solidFill.Append(rgbColorHex);   
    props.Append(solidFill); 

    var paragraph = new Paragraph(new Run(new Text(cellText))); 

    var tc = new TableCell(paragraph, props); 

    return tc; 
} 

पूर्ण त्रुटि इस प्रकार है के रूप में:

enter image description here

+0

क्या आप हमें पूर्ण त्रुटि संदेश और त्रुटि जो फेंकने वाली रेखा को बता सकते हैं। –

+0

मैंने त्रुटि की एक छवि शामिल की है। वहां वास्तव में बहुत अधिक जानकारी नहीं है। क्या मैं कहीं और पा सकता हूं? – DaveDev

+0

आपकी फ़ाइल दूषित हो सकती है। मैन्युअल रूप से एक ही फ़ाइल खोलने का प्रयास करें। यदि यह खुलता है तो कोड में कुछ गलती हो सकती है। –

उत्तर

11

यह एक दो भाग सवाल यह है कि जब मैं दस्तावेज़ को खोलने का प्रयास मैं वहाँ सामग्री के साथ एक समस्या यह है कि कोई त्रुटि मिलती है:

1) मैं एक OpenXML TableCell

foregroun के अग्रभाग को कैसे संशोधित कर सकते हैं ओपनएक्सएमएल TableCell का डी Run के गुणों द्वारा परिभाषित किया गया है, जिसे RunProperties कहा जाता है। रन में रंग जोड़ने के लिए, आपको Val संपत्ति का उपयोग करके Color ऑब्जेक्ट जोड़ना होगा।

// Create the RunProperties object for your run 
DocumentFormat.OpenXml.Wordprocessing.RunProperties rp = 
    new DocumentFormat.OpenXml.Wordprocessing.RunProperties(); 
// Add the Color object for your run into the RunProperties 
rp.Append(DocumentFormat.OpenXml.Wordprocessing.Color() { Val = "ABCDEF" }); 
// Create the Run object 
DocumentFormat.OpenXml.WordProcessing.Run run = 
    new DocumentFormat.OpenXml.WordProcessing.Run(); 
// Assign your RunProperties to your Run 
run.RunProperties = rp; 
// Add your text to your Run 
run.Append(new Text("My Text")); 

reference question देखें।

2) मैं एक OpenXML TableCell

TableCell पृष्ठभूमि की पृष्ठभूमि कैसे संशोधित कर सकते हैं TableCellProperties, ऊपर Run, जो RunProperties का उपयोग करता है के लिए इसी तरह का उपयोग कर संशोधित किया जा सकता। हालांकि, आप अपने TableCellProperties पर Shading ऑब्जेक्ट लागू करते हैं।

// Create the TableCell object 
DocumentFormat.OpenXml.Wordprocessing.TableCell tc = 
    new DocumentFormat.OpenXml.Wordprocessing.TableCell(); 
// Create the TableCellProperties object 
TableCellProperties tcp = new TableCellProperties(
    new TableCellWidth { Type = TableWidthUnitValues.Auto, } 
); 
// Create the Shading object 
DocumentFormat.OpenXml.Wordprocessing.Shading shading = 
    new DocumentFormat.OpenXml.Wordprocessing.Shading() { 
    Color = "auto", 
    Fill = "ABCDEF", 
    Val = ShadingPatternValues.Clear 
}; 
// Add the Shading object to the TableCellProperties object 
tcp.Append(shading); 
// Add the TableCellProperties object to the TableCell object 
tc.Append(tcp); 

// also need to ensure you include the text, otherwise it causes an error (it did for me!) 
tc.Append(new Paragraph(new Run(new Text(cellText)))); 

reference question देखें।

+0

@ डेवडेव हाहा, ठीक है, ओह खोल सकते हैं। आपको विचार मिला! –

-1
DocumentFormat.OpenXml.WordProcessingRunProperties rp = 
    new DocumentFormat.OpenXml.WordProcessingRunProperties(); 

=

DocumentFormat.OpenXml.WordProcessing.RunProperties rp = 
    new DocumentFormat.OpenXml.WordProcessing.RunProperties(); 

??

संबंधित मुद्दे

 संबंधित मुद्दे