public XSSFDxfStyleProvider(CT_Dxf dxf, int stripeSize, IIndexedColorMap colorMap)
 {
     this.stripeSize = stripeSize;
     this.colorMap   = colorMap;
     if (dxf == null)
     {
         border = null;
         font   = null;
         number = null;
         fill   = null;
     }
     else
     {
         border = dxf.IsSetBorder() ? new XSSFBorderFormatting(dxf.border) : null;
         font   = dxf.IsSetFont() ? new XSSFFontFormatting(dxf.font) : null;
         if (dxf.IsSetNumFmt())
         {
             CT_NumFmt numFmt = dxf.numFmt;
             number = new ExcelNumberFormat((int)numFmt.numFmtId, numFmt.formatCode);
         }
         else
         {
             number = null;
         }
         fill = dxf.IsSetFill() ? new XSSFPatternFormatting(dxf.fill) : null;
     }
 }
 public void Cleanup()
 {
     foreach (KeyValuePair <uint, XMLStyleModel> pair in _styles.GetPairs())
     {
         pair.Value.Cleanup();
         _stylesheet.CellXfs.Xf.Add(pair.Value.Data);
     }
     foreach (KeyValuePair <string, uint> item in _namedlookup)
     {
         CT_CellStyle cT_CellStyle = new CT_CellStyle();
         cT_CellStyle.Name_Attr = item.Key;
         cT_CellStyle.XfId_Attr = item.Value;
         _stylesheet.CellStyles.CellStyle.Add(cT_CellStyle);
     }
     foreach (KeyValuePair <uint, string> pair2 in _numberFormats.GetPairs())
     {
         CT_NumFmt cT_NumFmt = new CT_NumFmt();
         cT_NumFmt.NumFmtId_Attr   = pair2.Key;
         cT_NumFmt.FormatCode_Attr = pair2.Value;
         _stylesheet.NumFmts.NumFmt.Add(cT_NumFmt);
     }
     foreach (KeyValuePair <uint, XMLFontModel> pair3 in _fonts.GetPairs())
     {
         _stylesheet.Fonts.Font.Add(pair3.Value.Data);
     }
     foreach (KeyValuePair <uint, XMLFillModel> pair4 in _fills.GetPairs())
     {
         pair4.Value.Cleanup();
         _stylesheet.Fills.Fill.Add(pair4.Value.Data);
     }
     foreach (KeyValuePair <uint, XMLBorderModel> pair5 in _borders.GetPairs())
     {
         _stylesheet.Borders.Border.Add(pair5.Value.Data);
     }
     if (_palette.LegacyPaletteModified)
     {
         _palette.WriteIndexedColors(_stylesheet);
     }
     _stylesheet.NumFmts.Count_Attr    = _numberFormats.Count;
     _stylesheet.Fonts.Count_Attr      = _fonts.Count;
     _stylesheet.Fills.Count_Attr      = _fills.Count;
     _stylesheet.Borders.Count_Attr    = _borders.Count;
     _stylesheet.CellXfs.Count_Attr    = _styles.Count;
     _stylesheet.CellStyles.Count_Attr = (uint)_namedlookup.Count;
 }
Exemple #3
0
        /**
         * Write this table out as XML.
         *
         * @param out The stream to write to.
         * @throws IOException if an error occurs while writing.
         */
        public void WriteTo(Stream out1)
        {
            // Work on the current one
            // Need to do this, as we don't handle
            //  all the possible entries yet
            CT_Stylesheet styleSheet = doc.GetStyleSheet();

            // Formats
            CT_NumFmts ctFormats = new CT_NumFmts();

            ctFormats.count = (uint)numberFormats.Count;
            if (ctFormats.count > 0)
            {
                ctFormats.countSpecified = true;
            }
            foreach (KeyValuePair <int, String> fmt in numberFormats)
            {
                CT_NumFmt ctFmt = ctFormats.AddNewNumFmt();
                ctFmt.numFmtId   = (uint)fmt.Key;
                ctFmt.formatCode = fmt.Value;
            }
            if (ctFormats.count > 0)
            {
                styleSheet.numFmts = ctFormats;
            }

            // Fonts
            CT_Fonts ctFonts = new CT_Fonts();

            ctFonts.count = (uint)fonts.Count;
            if (ctFonts.count > 0)
            {
                ctFonts.countSpecified = true;
            }
            List <CT_Font> ctfnt = new List <CT_Font>(fonts.Count);

            foreach (XSSFFont f in fonts)
            {
                ctfnt.Add(f.GetCTFont());
            }
            ctFonts.SetFontArray(ctfnt);
            styleSheet.fonts = (ctFonts);

            // Fills
            List <CT_Fill> ctf = new List <CT_Fill>(fills.Count);

            foreach (XSSFCellFill f in fills)
            {
                ctf.Add(f.GetCTFill());
            }
            CT_Fills ctFills = new CT_Fills();

            ctFills.SetFillArray(ctf);
            ctFills.count = (uint)fills.Count;
            if (ctFills.count > 0)
            {
                ctFills.countSpecified = true;
            }
            styleSheet.fills = ctFills;

            // Borders
            List <CT_Border> ctb = new List <CT_Border>(borders.Count);

            foreach (XSSFCellBorder b in borders)
            {
                ctb.Add(b.GetCTBorder());
            }
            CT_Borders ctBorders = new CT_Borders();

            ctBorders.SetBorderArray(ctb);
            ctBorders.count    = (uint)ctb.Count;
            styleSheet.borders = ctBorders;

            // Xfs
            if (xfs.Count > 0)
            {
                CT_CellXfs ctXfs = new CT_CellXfs();
                ctXfs.count = (uint)xfs.Count;
                if (ctXfs.count > 0)
                {
                    ctXfs.countSpecified = true;
                }
                ctXfs.xf = xfs;

                styleSheet.cellXfs = (ctXfs);
            }

            // Style xfs
            if (styleXfs.Count > 0)
            {
                CT_CellStyleXfs ctSXfs = new CT_CellStyleXfs();
                ctSXfs.count = (uint)(styleXfs.Count);
                if (ctSXfs.count > 0)
                {
                    ctSXfs.countSpecified = true;
                }
                ctSXfs.xf = styleXfs;

                styleSheet.cellStyleXfs = (ctSXfs);
            }

            // Style dxfs
            if (dxfs.Count > 0)
            {
                CT_Dxfs ctDxfs = new CT_Dxfs();
                ctDxfs.count = (uint)dxfs.Count;
                if (ctDxfs.count > 0)
                {
                    ctDxfs.countSpecified = true;
                }
                ctDxfs.dxf = dxfs;

                styleSheet.dxfs = (ctDxfs);
            }

            // Save
            doc.Save(out1);
        }
Exemple #4
0
        public void WriteTo(Stream out1)
        {
            CT_Stylesheet styleSheet = this.doc.GetStyleSheet();
            CT_NumFmts    ctNumFmts  = new CT_NumFmts();

            ctNumFmts.count = (uint)this.numberFormats.Count;
            if (ctNumFmts.count > 0U)
            {
                ctNumFmts.countSpecified = true;
            }
            foreach (KeyValuePair <int, string> numberFormat in this.numberFormats)
            {
                CT_NumFmt ctNumFmt = ctNumFmts.AddNewNumFmt();
                ctNumFmt.numFmtId   = (uint)numberFormat.Key;
                ctNumFmt.formatCode = numberFormat.Value;
            }
            styleSheet.numFmts = ctNumFmts;
            CT_Fonts ctFonts = new CT_Fonts();

            ctFonts.count = (uint)this.fonts.Count;
            if (ctFonts.count > 0U)
            {
                ctFonts.countSpecified = true;
            }
            CT_Font[] array1 = new CT_Font[this.fonts.Count];
            int       num    = 0;

            foreach (XSSFFont font in this.fonts)
            {
                array1[num++] = font.GetCTFont();
            }
            ctFonts.SetFontArray(array1);
            styleSheet.fonts = ctFonts;
            List <CT_Fill> array2 = new List <CT_Fill>(this.fills.Count);

            foreach (XSSFCellFill fill in this.fills)
            {
                array2.Add(fill.GetCTFill());
            }
            CT_Fills ctFills = new CT_Fills();

            ctFills.SetFillArray(array2);
            ctFills.count = (uint)this.fills.Count;
            if (ctFills.count > 0U)
            {
                ctFills.countSpecified = true;
            }
            styleSheet.fills = ctFills;
            List <CT_Border> array3 = new List <CT_Border>(this.borders.Count);

            foreach (XSSFCellBorder border in this.borders)
            {
                array3.Add(border.GetCTBorder());
            }
            CT_Borders ctBorders = new CT_Borders();

            ctBorders.SetBorderArray(array3);
            ctBorders.count = (uint)array3.Count;
            if (ctBorders.count > 0U)
            {
                ctBorders.countSpecified = true;
            }
            styleSheet.borders = ctBorders;
            if (this.xfs.Count > 0)
            {
                CT_CellXfs ctCellXfs = new CT_CellXfs();
                ctCellXfs.count = (uint)this.xfs.Count;
                if (ctCellXfs.count > 0U)
                {
                    ctCellXfs.countSpecified = true;
                }
                ctCellXfs.xf       = this.xfs;
                styleSheet.cellXfs = ctCellXfs;
            }
            if (this.styleXfs.Count > 0)
            {
                CT_CellStyleXfs ctCellStyleXfs = new CT_CellStyleXfs();
                ctCellStyleXfs.count = (uint)this.styleXfs.Count;
                if (ctCellStyleXfs.count > 0U)
                {
                    ctCellStyleXfs.countSpecified = true;
                }
                ctCellStyleXfs.xf       = this.styleXfs;
                styleSheet.cellStyleXfs = ctCellStyleXfs;
            }
            if (this.dxfs.Count > 0)
            {
                CT_Dxfs ctDxfs = new CT_Dxfs();
                ctDxfs.count = (uint)this.dxfs.Count;
                if (ctDxfs.count > 0U)
                {
                    ctDxfs.countSpecified = true;
                }
                ctDxfs.dxf      = this.dxfs;
                styleSheet.dxfs = ctDxfs;
            }
            this.doc.Save(out1);
        }