Ejemplo n.º 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);
        }
Ejemplo n.º 2
0
        public void TestGetBorderStyle()
        {
            CT_Stylesheet stylesheet = new CT_Stylesheet();
            CT_Border     border     = stylesheet.AddNewBorders().AddNewBorder();
            CT_BorderPr   top        = border.AddNewTop();
            CT_BorderPr   right      = border.AddNewRight();
            CT_BorderPr   bottom     = border.AddNewBottom();

            top.style    = (ST_BorderStyle.dashDot);
            right.style  = (ST_BorderStyle.none);
            bottom.style = (ST_BorderStyle.thin);

            XSSFCellBorder cellBorderStyle = new XSSFCellBorder(border);

            Assert.AreEqual("DashDot", cellBorderStyle.GetBorderStyle(BorderSide.TOP).ToString());

            Assert.AreEqual("None", cellBorderStyle.GetBorderStyle(BorderSide.RIGHT).ToString());
            Assert.AreEqual(BorderStyle.None, cellBorderStyle.GetBorderStyle(BorderSide.RIGHT));

            Assert.AreEqual("Thin", cellBorderStyle.GetBorderStyle(BorderSide.BOTTOM).ToString());

            Assert.AreEqual(BorderStyle.Thin, cellBorderStyle.GetBorderStyle(BorderSide.BOTTOM));
        }
Ejemplo n.º 3
0
        private void WriteStyles(string path)
        {
            CT_Stylesheet stylesheet = new CT_Stylesheet
            {
                cellXfs = new CT_CellXfs {
                    xf = styles.ToArray()
                },
                cellStyles = new CT_CellStyles {
                    cellStyle = new[] { new CT_CellStyle {
                                            name = "Normal", xfId = 0, builtinId = 0, builtinIdSpecified = true
                                        } }
                },
                cellStyleXfs = new CT_CellStyleXfs {
                    xf = new[] { new CT_Xf() }
                },
                borders = new CT_Borders {
                    border = borders.ToArray()
                },
                fonts = new CT_Fonts {
                    font = fonts.ToArray()
                },
                dxfs = new CT_Dxfs {
                    dxf = dxfStyles.ToArray()
                },
                colors = new CT_Colors(),
                fills  = new CT_Fills {
                    fill = fills.ToArray()
                },
                numFmts = new CT_NumFmts {
                    numFmt = numFormats.ToArray()
                },
                tableStyles = new CT_TableStyles()
            };

            WriteFile(path, stylesheet, SpreadsheetNs(false));
        }
Ejemplo n.º 4
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);
        }
Ejemplo n.º 5
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);
            }
        }
Ejemplo n.º 6
0
        public PartManager(XMLWorkbookModel workbookModel)
        {
            _workbookmodel    = workbookModel;
            _relationshipTree = new OPCRelationshipTree("http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument", ((IStreambookModel)_workbookmodel).ZipPackage);
            WorkbookPart workbookPart = new WorkbookPart();
            CT_Workbook  obj          = (CT_Workbook)workbookPart.Root;

            obj.FileVersion = new CT_FileVersion();
            obj.FileVersion.AppName_Attr      = "xl";
            obj.FileVersion.LastEdited_Attr   = "4";
            obj.FileVersion.LowestEdited_Attr = "4";
            obj.FileVersion.RupBuild_Attr     = "4506";
            obj.WorkbookPr = new CT_WorkbookPr();
            obj.WorkbookPr.DefaultThemeVersion_Attr = 124226u;
            obj.BookViews = new CT_BookViews();
            CT_BookView item = new CT_BookView
            {
                XWindow_Attr      = 240,
                YWindow_Attr      = 120,
                WindowWidth_Attr  = 18060u,
                WindowHeight_Attr = 7050u
            };

            obj.BookViews.WorkbookView.Add(item);
            obj.CalcPr             = new CT_CalcPr();
            obj.CalcPr.CalcId_Attr = 125725u;
            Relationship relationship = _relationshipTree.AddRootPartToTree(workbookPart, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml", "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument", "xl/workbook.xml");

            _workbook = workbookPart;
            StyleSheetPart styleSheetPart = new StyleSheetPart();
            CT_Stylesheet  obj2           = (CT_Stylesheet)styleSheetPart.Root;
            CT_Font        cT_Font        = new CT_Font();

            cT_Font.Sz              = new CT_FontSize();
            cT_Font.Sz.Val_Attr     = 11.0;
            cT_Font.Color           = new CT_Color();
            cT_Font.Color.Rgb_Attr  = "FF000000";
            cT_Font.Name            = new CT_FontName();
            cT_Font.Name.Val_Attr   = "Calibri";
            cT_Font.Family          = new CT_IntProperty();
            cT_Font.Family.Val_Attr = 2;
            cT_Font.Scheme          = new CT_FontScheme();
            cT_Font.Scheme.Val_Attr = ST_FontScheme.minor;
            obj2.Fonts              = new CT_Fonts();
            obj2.Fonts.Font.Add(cT_Font);
            obj2.Fonts.Count_Attr = 1u;
            CT_Fill cT_Fill = new CT_Fill();

            cT_Fill.PatternFill = new CT_PatternFill();
            cT_Fill.PatternFill.PatternType_Attr = ST_PatternType.none;
            CT_Fill cT_Fill2 = new CT_Fill();

            cT_Fill2.PatternFill = new CT_PatternFill();
            cT_Fill2.PatternFill.PatternType_Attr = ST_PatternType.gray125;
            obj2.Fills = new CT_Fills();
            obj2.Fills.Fill.Add(cT_Fill);
            obj2.Fills.Fill.Add(cT_Fill2);
            obj2.Fills.Count_Attr = 2u;
            CT_Border item2 = new CT_Border
            {
                Left     = new CT_BorderPr(),
                Right    = new CT_BorderPr(),
                Top      = new CT_BorderPr(),
                Bottom   = new CT_BorderPr(),
                Diagonal = new CT_BorderPr()
            };

            obj2.Borders = new CT_Borders();
            obj2.Borders.Border.Add(item2);
            obj2.Borders.Count_Attr = 1u;
            CT_Xf item3 = new CT_Xf
            {
                NumFmtId_Attr = 0u,
                FontId_Attr   = 0u,
                FillId_Attr   = 0u,
                BorderId_Attr = 0u
            };

            obj2.CellStyleXfs = new CT_CellStyleXfs();
            obj2.CellStyleXfs.Xf.Add(item3);
            obj2.CellXfs = new CT_CellXfs();
            obj2.CellXfs.Xf.Add(StyleManager.CreateDefaultXf());
            CT_CellStyle item4 = new CT_CellStyle
            {
                Name_Attr      = "Normal",
                XfId_Attr      = 0u,
                BuiltinId_Attr = 0u
            };

            obj2.CellStyles = new CT_CellStyles();
            obj2.CellStyles.CellStyle.Add(item4);
            obj2.Dxfs                               = new CT_Dxfs();
            obj2.Dxfs.Count_Attr                    = 0u;
            obj2.TableStyles                        = new CT_TableStyles();
            obj2.TableStyles.Count_Attr             = 0u;
            obj2.TableStyles.DefaultTableStyle_Attr = "TableStyleMedium9";
            obj2.TableStyles.DefaultPivotStyle_Attr = "PivotStyleLight16";
            _relationshipTree.AddPartToTree(styleSheetPart, "application/vnd.openxmlformats-officedocument.spreadsheetml.styles+xml", "http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles", "xl/styles.xml", (XmlPart)_relationshipTree.GetPartByLocation(relationship.RelatedPart));
            _stylesheet = new StyleManager(styleSheetPart);
            OpcCorePropertiesPart part = new OpcCorePropertiesPart();

            _relationshipTree.AddRootPartToTree(part, "application/vnd.openxmlformats-package.core-properties+xml", "http://schemas.openxmlformats.org/package/2006/relationships/meatadata/core-properties", "docProps/core.xml");
            PropertiesPart propertiesPart = new PropertiesPart();
            CT_Properties  obj3           = (CT_Properties)propertiesPart.Root;

            obj3.Application                       = "Microsoft Excel";
            obj3.DocSecurity                       = 0;
            obj3.ScaleCrop                         = false;
            obj3.HeadingPairs                      = new CT_VectorVariant();
            obj3.HeadingPairs.Vector               = new CT_Vector();
            obj3.HeadingPairs.Vector.Size_Attr     = 2u;
            obj3.HeadingPairs.Vector.BaseType_Attr = ST_VectorBaseType.variant;
            CT_Variant item5 = new CT_Variant
            {
                Choice_0 = CT_Variant.ChoiceBucket_0.lpstr,
                Lpstr    = "Worksheets"
            };
            CT_Variant item6 = new CT_Variant
            {
                Choice_0 = CT_Variant.ChoiceBucket_0.i4,
                I4       = 1
            };

            obj3.HeadingPairs.Vector.Variant.Add(item5);
            obj3.HeadingPairs.Vector.Variant.Add(item6);
            obj3.TitlesOfParts                      = new CT_VectorLpstr();
            obj3.TitlesOfParts.Vector               = new CT_Vector();
            obj3.TitlesOfParts.Vector.Size_Attr     = 0u;
            obj3.TitlesOfParts.Vector.BaseType_Attr = ST_VectorBaseType.lpstr;
            obj3.LinksUpToDate                      = false;
            obj3.SharedDoc         = false;
            obj3.HyperlinksChanged = false;
            obj3.AppVersion        = "12.0000";
            _relationshipTree.AddRootPartToTree(propertiesPart, "application/vnd.openxmlformats-officedocument.extended-properties+xml", "http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties", "docProps/app.xml");
        }
Ejemplo n.º 7
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);
     }
 }
Ejemplo n.º 8
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);
        }
Ejemplo n.º 9
0
 public StyleManager(StyleSheetPart part)
 {
     _part       = part;
     _stylesheet = (CT_Stylesheet)_part.Root;
     Hydrate();
 }
Ejemplo n.º 10
0
 public StyleManager(StyleSheetPart part)
 {
     this._part       = part;
     this._stylesheet = (CT_Stylesheet)this._part.Root;
     this.Hydrate();
 }