नोट: OpenXML 2.0 एसडीके CTP में है और Office2010 तक उत्पादन में इस्तेमाल के लिए लाइसेंस नहीं है।
ओपनएक्सएमएल एसडीके से निपटने के लिए मेरा सामान्य पद्धति एक रिक्त दस्तावेज़ और एक दस्तावेज़ बनाना है जिसमें आप सीखना चाहते हैं कि कैसे कार्यान्वित करना है (पृष्ठभूमि रंग की तरह) और एसडीके के ओपनएक्सएमएलडीफ़ का उपयोग यह देखने के लिए कि किन परिवर्तनों की आवश्यकता है सुविधा को लागू करने के लिए बनाया जाना चाहिए।
आप स्क्रैच से एक दस्तावेज़ पैदा कर रहे हैं, तो आप DocumentReflector का उपयोग डिफ़ॉल्ट स्टाइलशीट वस्तु के लिए कोड उत्पन्न करने के लिए और फिर शैलियों आप की जरूरत जोड़ सकते हैं।
डिफ़ॉल्ट के साथ शुरू:
new Stylesheet(
new Fonts(
new Font(
new FontSize() { Val = 10D },
new Color() { Theme = (UInt32Value)1U },
new FontName() { Val = "Arial" },
new FontFamilyNumbering() { Val = 2 })
) { Count = (UInt32Value)1U },
new Fills(
new Fill(
new PatternFill() { PatternType = PatternValues.None }),
new Fill(
new PatternFill() { PatternType = PatternValues.Gray125 })
) { Count = (UInt32Value)2U },
new Borders(...
...
...
new CellFormats(
new CellFormat() { NumberFormatId = (UInt32Value)0U, FontId = (UInt32Value)0U, FillId = (UInt32Value)0U, BorderId = (UInt32Value)0U, FormatId = (UInt32Value)0U }) { Count = (UInt32Value)1U }, ...
मैं नए CellFormats कि नए के सूचकांक संदर्भ आकार 12 का एक नया फ़ॉन्ट जोड़ दिया है और लाल रंग की पृष्ठभूमि (इंडेक्स मूल्य 64) के साथ एक नया भरें, और जोड़ा फ़ॉन्ट और भरें। (भी गिनता अपडेट करना सुनिश्चित करें)
new Stylesheet(
new Fonts(
new Font(
new FontSize() { Val = 10D },
new Color() { Theme = (UInt32Value)1U },
new FontName() { Val = "Arial" },
new FontFamilyNumbering() { Val = 2 }),
new Font(
new FontSize() { Val = 12D },
new Color() { Theme = (UInt32Value)1U },
new FontName() { Val = "Arial" },
new FontFamilyNumbering() { Val = 2 })
) { Count = (UInt32Value)2U },
new Fills(
new Fill(
new PatternFill() { PatternType = PatternValues.None }),
new Fill(
new PatternFill() { PatternType = PatternValues.Gray125 }),
new Fill(
new PatternFill() { PatternType = PatternValues.Solid, ForegroundColor = new ForegroundColor() { Rgb = "FFFF0000" }, BackgroundColor = new BackgroundColor() { Indexed = 64 } })
) { Count = (UInt32Value)3U },
new Borders(
new Border(
new LeftBorder(), new RightBorder(), new TopBorder(), new BottomBorder(), new DiagonalBorder())
) { Count = (UInt32Value)1U },
new CellStyleFormats(
new CellFormat() { NumberFormatId = (UInt32Value)0U, FontId = (UInt32Value)0U, FillId = (UInt32Value)0U, BorderId = (UInt32Value)0U }
) { Count = (UInt32Value)1U },
new CellFormats(
new CellFormat() { NumberFormatId = (UInt32Value)0U, FontId = (UInt32Value)0U, FillId = (UInt32Value)0U, BorderId = (UInt32Value)0U, FormatId = (UInt32Value)0U },
new CellFormat() { NumberFormatId = (UInt32Value)0U, FontId = (UInt32Value)1U, FillId = (UInt32Value)0U, BorderId = (UInt32Value)0U, FormatId = (UInt32Value)0U },
new CellFormat() { NumberFormatId = (UInt32Value)0U, FontId = (UInt32Value)0U, FillId = (UInt32Value)2U, BorderId = (UInt32Value)0U, FormatId = (UInt32Value)0U }
) { Count = (UInt32Value)3U },
new CellStyles(
new CellStyle() { Name = "Normal", FormatId = (UInt32Value)0U, BuiltinId = (UInt32Value)0U }
) { Count = (UInt32Value)1U },
new DifferentialFormats() { Count = (UInt32Value)0U },
new TableStyles() { Count = (UInt32Value)0U, DefaultTableStyle = "TableStyleMedium9", DefaultPivotStyle = "PivotStyleLight16" });
फिर, कोड में, मैं CellStyle सूचकांक कोशिकाओं के लिए लागू मैं स्वरूपित करना चाहते हैं:। (वहां पहले से ही कोशिकाओं में डेटा ए 2 और ए 3 था सेल A2 हो जाता है बड़ा आकार, ए 3 लाल पृष्ठभूमि हो जाता है)
SheetData sheetData = worksheetPart.Worksheet.GetFirstChild<SheetData>();
sheetData.Descendants<Row>().Where(r => r.RowIndex == 2U).First().Descendants<Cell>().First().StyleIndex = 1U;
sheetData.Descendants<Row>().Where(r => r.RowIndex == 3U).First().Descendants<Cell>().First().StyleIndex = 2U;
+1 आपको बहुत बहुत धन्यवाद। आपकी पोस्ट ने मुझे वास्तव में अच्छी शुरुआत की। – horgh