Пример #1
0
        public void SetUp()
        {
            stylesTable = new StylesTable();

            ctStylesheet = stylesTable.GetCTStylesheet();

            ctBorderA = new CT_Border();
            XSSFCellBorder borderA  = new XSSFCellBorder(ctBorderA);
            long           borderId = stylesTable.PutBorder(borderA);

            Assert.AreEqual(1, borderId);

            XSSFCellBorder borderB = new XSSFCellBorder();

            Assert.AreEqual(1, stylesTable.PutBorder(borderB));

            ctFill = new CT_Fill();
            XSSFCellFill fill   = new XSSFCellFill(ctFill);
            long         fillId = stylesTable.PutFill(fill);

            Assert.AreEqual(2, fillId);

            ctFont = new CT_Font();
            XSSFFont font   = new XSSFFont(ctFont);
            long     fontId = stylesTable.PutFont(font);

            Assert.AreEqual(1, fontId);

            cellStyleXf          = ctStylesheet.AddNewCellStyleXfs().AddNewXf();
            cellStyleXf.borderId = 1;
            cellStyleXf.fillId   = 1;
            cellStyleXf.fontId   = 1;

            cellXfs         = ctStylesheet.AddNewCellXfs();
            cellXf          = cellXfs.AddNewXf();
            cellXf.xfId     = (1);
            cellXf.borderId = (1);
            cellXf.fillId   = (1);
            cellXf.fontId   = (1);
            stylesTable.PutCellStyleXf(cellStyleXf);
            stylesTable.PutCellXf(cellXf);
            cellStyle = new XSSFCellStyle(1, 1, stylesTable, null);

            Assert.IsNotNull(stylesTable.GetFillAt(1).GetCTFill().patternFill);
            Assert.AreEqual(ST_PatternType.darkGray, stylesTable.GetFillAt(1).GetCTFill().patternFill.patternType);
        }
Пример #2
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);
        }
Пример #3
0
        /**
         * Read this shared styles table from an XML file.
         *
         * @param is The input stream Containing the XML document.
         * @throws IOException if an error occurs while Reading.
         */

        protected void ReadFrom(XmlDocument xmldoc)
        {
            try
            {
                doc = StyleSheetDocument.Parse(xmldoc, NamespaceManager);

                CT_Stylesheet styleSheet = doc.GetStyleSheet();

                // Grab all the different bits we care about
                CT_NumFmts ctfmts = styleSheet.numFmts;
                if (ctfmts != null)
                {
                    foreach (CT_NumFmt nfmt in ctfmts.numFmt)
                    {
                        numberFormats.Add((int)nfmt.numFmtId, nfmt.formatCode);
                    }
                }

                CT_Fonts ctfonts = styleSheet.fonts;
                if (ctfonts != null)
                {
                    int idx = 0;
                    foreach (CT_Font font in ctfonts.font)
                    {
                        // Create the font and save it. Themes Table supplied later
                        XSSFFont f = new XSSFFont(font, idx);
                        fonts.Add(f);
                        idx++;
                    }
                }
                CT_Fills ctFills = styleSheet.fills;
                if (ctFills != null)
                {
                    foreach (CT_Fill fill in ctFills.fill)
                    {
                        fills.Add(new XSSFCellFill(fill));
                    }
                }

                CT_Borders ctborders = styleSheet.borders;
                if (ctborders != null)
                {
                    foreach (CT_Border border in ctborders.border)
                    {
                        borders.Add(new XSSFCellBorder(border));
                    }
                }

                CT_CellXfs cellXfs = styleSheet.cellXfs;
                if (cellXfs != null)
                {
                    xfs.AddRange(cellXfs.xf);
                }

                CT_CellStyleXfs cellStyleXfs = styleSheet.cellStyleXfs;
                if (cellStyleXfs != null)
                {
                    styleXfs.AddRange(cellStyleXfs.xf);
                }

                CT_Dxfs styleDxfs = styleSheet.dxfs;
                if (styleDxfs != null)
                {
                    dxfs.AddRange(styleDxfs.dxf);
                }
            }
            catch (XmlException e)
            {
                throw new IOException(e.Message);
            }
        }
Пример #4
0
 protected void ReadFrom(Stream is1)
 {
     try
     {
         this.doc = StyleSheetDocument.Parse(is1);
         CT_Stylesheet styleSheet = this.doc.GetStyleSheet();
         CT_NumFmts    numFmts    = styleSheet.numFmts;
         if (numFmts != null)
         {
             foreach (CT_NumFmt ctNumFmt in numFmts.numFmt)
             {
                 this.numberFormats.Add((int)ctNumFmt.numFmtId, ctNumFmt.formatCode);
             }
         }
         CT_Fonts fonts = styleSheet.fonts;
         if (fonts != null)
         {
             int index = 0;
             foreach (CT_Font font in fonts.font)
             {
                 this.fonts.Add(new XSSFFont(font, index));
                 ++index;
             }
         }
         CT_Fills fills = styleSheet.fills;
         if (fills != null)
         {
             foreach (CT_Fill Fill in fills.fill)
             {
                 this.fills.Add(new XSSFCellFill(Fill));
             }
         }
         CT_Borders borders = styleSheet.borders;
         if (borders != null)
         {
             foreach (CT_Border border in borders.border)
             {
                 this.borders.Add(new XSSFCellBorder(border));
             }
         }
         CT_CellXfs cellXfs = styleSheet.cellXfs;
         if (cellXfs != null)
         {
             this.xfs.AddRange((IEnumerable <CT_Xf>)cellXfs.xf);
         }
         CT_CellStyleXfs cellStyleXfs = styleSheet.cellStyleXfs;
         if (cellStyleXfs != null)
         {
             this.styleXfs.AddRange((IEnumerable <CT_Xf>)cellStyleXfs.xf);
         }
         CT_Dxfs dxfs = styleSheet.dxfs;
         if (dxfs == null)
         {
             return;
         }
         this.dxfs.AddRange((IEnumerable <CT_Dxf>)dxfs.dxf);
     }
     catch (XmlException ex)
     {
         throw new IOException(ex.Message);
     }
 }
Пример #5
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);
        }