Esempio n. 1
0
        public static CT_Stylesheet Parse(XmlNode node, XmlNamespaceManager namespaceManager)
        {
            if (node == null)
            {
                return(null);
            }
            CT_Stylesheet ctObj = new CT_Stylesheet();

            foreach (XmlNode childNode in node.ChildNodes)
            {
                if (childNode.LocalName == "numFmts")
                {
                    ctObj.numFmts = CT_NumFmts.Parse(childNode, namespaceManager);
                }
                else if (childNode.LocalName == "fonts")
                {
                    ctObj.fonts = CT_Fonts.Parse(childNode, namespaceManager);
                }
                else if (childNode.LocalName == "fills")
                {
                    ctObj.fills = CT_Fills.Parse(childNode, namespaceManager);
                }
                else if (childNode.LocalName == "borders")
                {
                    ctObj.borders = CT_Borders.Parse(childNode, namespaceManager);
                }
                else if (childNode.LocalName == "cellStyleXfs")
                {
                    ctObj.cellStyleXfs = CT_CellStyleXfs.Parse(childNode, namespaceManager);
                }
                else if (childNode.LocalName == "cellXfs")
                {
                    ctObj.cellXfs = CT_CellXfs.Parse(childNode, namespaceManager);
                }
                else if (childNode.LocalName == "cellStyles")
                {
                    ctObj.cellStyles = CT_CellStyles.Parse(childNode, namespaceManager);
                }
                else if (childNode.LocalName == "dxfs")
                {
                    ctObj.dxfs = CT_Dxfs.Parse(childNode, namespaceManager);
                }
                else if (childNode.LocalName == "tableStyles")
                {
                    ctObj.tableStyles = CT_TableStyles.Parse(childNode, namespaceManager);
                }
                else if (childNode.LocalName == "colors")
                {
                    ctObj.colors = CT_Colors.Parse(childNode, namespaceManager);
                }
                else if (childNode.LocalName == "extLst")
                {
                    ctObj.extLst = CT_ExtensionList.Parse(childNode, namespaceManager);
                }
            }
            return(ctObj);
        }
Esempio n. 2
0
 public static CT_CellXfs Parse(XmlNode node, XmlNamespaceManager namespaceManager)
 {
     if (node == null)
         return null;
     CT_CellXfs ctObj = new CT_CellXfs();
     ctObj.count = XmlHelper.ReadUInt(node.Attributes["count"]);
     ctObj.xf = new List<CT_Xf>();
     foreach (XmlNode childNode in node.ChildNodes)
     {
         if (childNode.LocalName == "xf")
             ctObj.xf.Add(CT_Xf.Parse(childNode, namespaceManager));
     }
     return ctObj;
 }
Esempio n. 3
0
        public static CT_CellXfs Parse(XmlNode node, XmlNamespaceManager namespaceManager)
        {
            if (node == null)
            {
                return(null);
            }
            CT_CellXfs ctObj = new CT_CellXfs();

            ctObj.count = XmlHelper.ReadUInt(node.Attributes["count"]);
            ctObj.xf    = new List <CT_Xf>();
            foreach (XmlNode childNode in node.ChildNodes)
            {
                if (childNode.LocalName == "xf")
                {
                    ctObj.xf.Add(CT_Xf.Parse(childNode, namespaceManager));
                }
            }
            return(ctObj);
        }
Esempio n. 4
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);
        }
Esempio n. 5
0
 public CT_CellXfs AddNewCellXfs()
 {
     this.cellXfsField = new CT_CellXfs();
     return(this.cellXfsField);
 }
Esempio n. 6
0
 public CT_CellXfs AddNewCellXfs()
 {
     this.cellXfsField = new CT_CellXfs();
     return this.cellXfsField;
 }
Esempio n. 7
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 = styleSheet.fonts;
            if (ctFonts == null)
                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
            CT_Fills ctFills = styleSheet.fills;
            if (ctFills == null)
            {
                ctFills = new CT_Fills();
            }
            ctFills.count = (uint)fills.Count;
            List<CT_Fill> ctf = new List<CT_Fill>(fills.Count);
            
            foreach (XSSFCellFill f in fills)
                ctf.Add( f.GetCTFill());
            ctFills.SetFillArray(ctf);
            if (ctFills.count > 0)
                ctFills.countSpecified = true;
            styleSheet.fills = ctFills;

            // Borders
            CT_Borders ctBorders = styleSheet.borders;
            if (ctBorders == null)
            {
                ctBorders = new CT_Borders();
            }
            ctBorders.count = (uint)borders.Count;
            List<CT_Border> ctb = new List<CT_Border>(borders.Count);
            foreach (XSSFCellBorder b in borders) 
                ctb.Add(b.GetCTBorder());
            
            ctBorders.SetBorderArray(ctb);
            styleSheet.borders = ctBorders;

            // Xfs
            if (xfs.Count > 0)
            {
                CT_CellXfs ctXfs = styleSheet.cellXfs;
                if (ctXfs == null)
                {
                    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 = styleSheet.cellStyleXfs;
                if (ctSXfs == null)
                {
                    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 = styleSheet.dxfs;
                if (ctDxfs == null)
                {
                    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);
        }