Пример #1
0
        private void SaveAndReloadReport(IWorkbook wb, FileInfo outFile)
        {
            // run some method on the font to verify if it is "disconnected" already
            //for(short i = 0;i < 256;i++)
            {
                IFont font = wb.GetFontAt((short)0);
                if (font is XSSFFont)
                {
                    XSSFFont xfont  = (XSSFFont)wb.GetFontAt((short)0);
                    CT_Font  ctFont = (CT_Font)xfont.GetCTFont();
                    Assert.AreEqual(0, ctFont.sizeOfBArray());
                }
            }

            FileStream fileOutStream = new FileStream(outFile.FullName, FileMode.Truncate, FileAccess.ReadWrite);

            wb.Write(fileOutStream);
            fileOutStream.Close();
            //Console.WriteLine("File \""+outFile.GetName()+"\" has been saved successfully");

            Stream is1 = new FileStream(outFile.FullName, FileMode.Truncate, FileAccess.ReadWrite);

            try
            {
                IWorkbook newWB;
                if (wb is XSSFWorkbook)
                {
                    newWB = new XSSFWorkbook(is1);
                }
                else if (wb is HSSFWorkbook)
                {
                    newWB = new HSSFWorkbook(is1);
                    //} else if(wb is SXSSFWorkbook) {
                    //    newWB = new SXSSFWorkbook(new XSSFWorkbook(is1));
                }
                else
                {
                    throw new InvalidOperationException("Unknown workbook: " + wb);
                }
                Assert.IsNotNull(newWB.GetSheet("test"));
            }
            finally
            {
                is1.Close();
            }
        }
Пример #2
0
        public void TestItalic()
        {
            CT_Font            ctFont = new CT_Font();
            CT_BooleanProperty bool1  = ctFont.AddNewI();

            bool1.val = (false);
            ctFont.SetIArray(0, bool1);

            XSSFFont xssfFont = new XSSFFont(ctFont);

            Assert.AreEqual(false, xssfFont.IsItalic);

            xssfFont.IsItalic = (true);
            Assert.AreEqual(1, ctFont.i.Count);
            Assert.AreEqual(true, ctFont.GetIArray(0).val);
            Assert.AreEqual(true, ctFont.GetIArray(0).val);
        }
Пример #3
0
        public void TestStrikeout()
        {
            CT_Font            ctFont = new CT_Font();
            CT_BooleanProperty bool1  = ctFont.AddNewStrike();

            bool1.val = (false);
            ctFont.SetStrikeArray(0, bool1);

            XSSFFont xssfFont = new XSSFFont(ctFont);

            Assert.AreEqual(false, xssfFont.IsStrikeout);

            xssfFont.IsStrikeout = (true);
            Assert.AreEqual(1, ctFont.strike.Count);
            Assert.AreEqual(true, ctFont.GetStrikeArray(0).val);
            Assert.AreEqual(true, ctFont.GetStrikeArray(0).val);
        }
Пример #4
0
        public void copy(XMLFontModel srcFont)
        {
            CT_Font font = srcFont._font;

            this._hasBeenModified = srcFont.HasBeenModified;
            if (font.B != null)
            {
                this.Bold = srcFont.Bold;
            }
            if (font.I != null)
            {
                this.Italic = srcFont.Italic;
            }
            if (font.Strike != null)
            {
                this.Strikethrough = srcFont.Strikethrough;
            }
            if (font.Name != null)
            {
                this.Name = srcFont.Name;
            }
            if (font.Sz != null)
            {
                this.Size = srcFont.Size;
            }
            if (font.U != null)
            {
                this.Underline = srcFont.Underline;
            }
            if (font.VertAlign != null)
            {
                this.ScriptStyle = srcFont.ScriptStyle;
            }
            if (font.Family != null)
            {
                this._font.Family = font.Family;
            }
            if (font.Scheme != null)
            {
                this._font.Scheme = font.Scheme;
            }
            if (font.Color != null)
            {
                this.Color = ((XMLColorModel)srcFont.Color).Clone();
            }
        }
Пример #5
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);
        }
Пример #6
0
        public void TestUnderline()
        {
            CT_Font ctFont = new CT_Font();
            CT_UnderlineProperty underlinePropr = ctFont.AddNewU();

            underlinePropr.val = (ST_UnderlineValues.single);
            ctFont.SetUArray(0, underlinePropr);

            XSSFFont xssfFont = new XSSFFont(ctFont);

            Assert.AreEqual(FontUnderlineType.Single, xssfFont.Underline);

            xssfFont.SetUnderline(FontUnderlineType.Double);
            Assert.AreEqual(1, ctFont.u.Count);
            Assert.AreEqual(ST_UnderlineValues.@double, ctFont.GetUArray(0).val);

            xssfFont.SetUnderline(FontUnderlineType.DoubleAccounting);
            Assert.AreEqual(1, ctFont.u.Count);
            Assert.AreEqual(ST_UnderlineValues.doubleAccounting, ctFont.GetUArray(0).val);
        }
Пример #7
0
 public void CloneStyleFrom(IFont src)
 {
     if (src is XSSFFont)
     {
         _ctFont = ((XSSFFont)src)._ctFont;
     }
     else
     {
         FontName    = src.FontName;
         FontHeight  = src.FontHeight;
         IsBold      = src.IsBold;
         Boldweight  = src.Boldweight;
         IsItalic    = src.IsItalic;
         IsStrikeout = src.IsStrikeout;
         Color       = src.Color;
         Underline   = src.Underline;
         Charset     = src.Charset;
         TypeOffset  = src.TypeOffset;
     }
 }
Пример #8
0
        public void TestRgbColor()
        {
            CT_Font  ctFont = new CT_Font();
            CT_Color color  = ctFont.AddNewColor();

            //Integer.toHexString(0xFFFFFF).getBytes() = [102, 102, 102, 102, 102, 102]
            color.SetRgb(Encoding.ASCII.GetBytes("ffffff"));
            ctFont.SetColorArray(0, color);

            XSSFFont xssfFont = new XSSFFont(ctFont);

            Assert.AreEqual(ctFont.GetColorArray(0).GetRgb()[0], xssfFont.GetXSSFColor().GetRgb()[0]);
            Assert.AreEqual(ctFont.GetColorArray(0).GetRgb()[1], xssfFont.GetXSSFColor().GetRgb()[1]);
            Assert.AreEqual(ctFont.GetColorArray(0).GetRgb()[2], xssfFont.GetXSSFColor().GetRgb()[2]);
            Assert.AreEqual(ctFont.GetColorArray(0).GetRgb()[3], xssfFont.GetXSSFColor().GetRgb()[3]);

            //Integer.toHexString(0xF1F1F1).getBytes() = [102, 49, 102, 49, 102, 49]
            color.SetRgb(Encoding.ASCII.GetBytes("f1f1f1"));
            XSSFColor newColor = new XSSFColor(color);

            xssfFont.SetColor(newColor);
            Assert.AreEqual(ctFont.GetColorArray(0).GetRgb()[2], newColor.GetRgb()[2]);
        }
Пример #9
0
 /*package*/
 internal XSSFFontFormatting(CT_Font font)
 {
     _font = font;
 }
Пример #10
0
 public XMLFontModel(CT_Font font, XMLPaletteModel palette)
 {
     _font      = font;
     _interface = new Font(this);
     _palette   = palette;
 }
Пример #11
0
 public XSSFFont(CT_Font font, int index)
 {
     _ctFont = font;
     _index  = (short)index;
 }
Пример #12
0
        /**
         *
         * CTRPrElt --> CTFont adapter
         */
        protected static CT_Font ToCTFont(CT_RPrElt pr)
        {
            CT_Font ctFont = new CT_Font();

            if (pr.SizeOfBArray() > 0)
            {
                ctFont.AddNewB().val = (pr.GetBArray(0).val);
            }
            if (pr.SizeOfUArray() > 0)
            {
                ctFont.AddNewU().val = (pr.GetUArray(0).val);
            }
            if (pr.SizeOfIArray() > 0)
            {
                ctFont.AddNewI().val = (pr.GetIArray(0).val);
            }
            if (pr.SizeOfColorArray() > 0)
            {
                CT_Color c1 = pr.GetColorArray(0);
                CT_Color c2 = ctFont.AddNewColor();
                if (c1.IsSetAuto())
                {
                    c2.auto          = (c1.auto);
                    c2.autoSpecified = true;
                }
                if (c1.IsSetIndexed())
                {
                    c2.indexed          = (c1.indexed);
                    c2.indexedSpecified = true;
                }
                if (c1.IsSetRgb())
                {
                    c2.SetRgb(c1.GetRgb());
                    c2.rgbSpecified = true;
                }
                if (c1.IsSetTheme())
                {
                    c2.theme          = (c1.theme);
                    c2.themeSpecified = true;
                }
                if (c1.IsSetTint())
                {
                    c2.tint          = (c1.tint);
                    c2.tintSpecified = true;
                }
            }

            if (pr.SizeOfSzArray() > 0)
            {
                ctFont.AddNewSz().val = (pr.GetSzArray(0).val);
            }
            if (pr.SizeOfRFontArray() > 0)
            {
                ctFont.AddNewName().val = (pr.GetRFontArray(0).val);
            }
            if (pr.SizeOfFamilyArray() > 0)
            {
                ctFont.AddNewFamily().val = (pr.GetFamilyArray(0).val);
            }
            if (pr.sizeOfSchemeArray() > 0)
            {
                ctFont.AddNewScheme().val = (pr.GetSchemeArray(0).val);
            }
            if (pr.sizeOfCharsetArray() > 0)
            {
                ctFont.AddNewCharset().val = (pr.GetCharsetArray(0).val);
            }
            if (pr.sizeOfCondenseArray() > 0)
            {
                ctFont.AddNewCondense().val = (pr.GetCondenseArray(0).val);
            }
            if (pr.sizeOfExtendArray() > 0)
            {
                ctFont.AddNewExtend().val = (pr.GetExtendArray(0).val);
            }
            if (pr.sizeOfVertAlignArray() > 0)
            {
                ctFont.AddNewVertAlign().val = (pr.GetVertAlignArray(0).val);
            }
            if (pr.sizeOfOutlineArray() > 0)
            {
                ctFont.AddNewOutline().val = (pr.GetOutlineArray(0).val);
            }
            if (pr.sizeOfShadowArray() > 0)
            {
                ctFont.AddNewShadow().val = (pr.GetShadowArray(0).val);
            }
            if (pr.sizeOfStrikeArray() > 0)
            {
                ctFont.AddNewStrike().val = (pr.GetStrikeArray(0).val);
            }

            return(ctFont);
        }
Пример #13
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);
        }
Пример #14
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;
            }
            styleSheet.numFmts = (ctFormats);

            int idx;
            // Fonts
            CT_Fonts ctFonts = new CT_Fonts();

            ctFonts.count = (uint)fonts.Count;
            if (ctFonts.count > 0)
            {
                ctFonts.countSpecified = true;
            }
            CT_Font[] ctfnt = new CT_Font[fonts.Count];
            idx = 0;
            foreach (XSSFFont f in fonts)
            {
                ctfnt[idx++] = 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);

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

            ctBorders.SetBorderArray(ctb);
            ctBorders.count = (uint)ctb.Count;
            if (ctBorders.count > 0)
            {
                ctBorders.countSpecified = true;
            }
            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);
        }
Пример #15
0
        private CellFont ConvertDxfFont(CT_Font font)
        {
            var                     cellFont = new CellFont();
            List <object>           items    = font.Items.ToList();
            List <ItemsChoiceType3> name     = new List <ItemsChoiceType3>();
            int                     counter  = 0;

            foreach (var item in items)
            {
                if (font.ItemsElementName[counter] == ItemsChoiceType3.name)
                {
                    var fontName = item as CT_FontName;
                    if (fontName != null)
                    {
                        cellFont.Name = fontName.val;
                    }
                }
                if (font.ItemsElementName[counter] == ItemsChoiceType3.sz)
                {
                    var fontSize = item as CT_FontSize;
                    if (fontSize != null)
                    {
                        cellFont.Size = fontSize.val;
                    }
                }
                if (font.ItemsElementName[counter] == ItemsChoiceType3.b)
                {
                    var boldItem = item as CT_BooleanProperty;
                    if (boldItem != null)
                    {
                        cellFont.Bold = boldItem.val;
                    }
                }
                if (font.ItemsElementName[counter] == ItemsChoiceType3.i)
                {
                    var italicItem = item as CT_BooleanProperty;
                    if (italicItem != null)
                    {
                        cellFont.Italic = italicItem.val;
                    }
                }
                if (font.ItemsElementName[counter] == ItemsChoiceType3.shadow)
                {
                    var shadowItem = item as CT_BooleanProperty;
                    if (shadowItem != null)
                    {
                        cellFont.Shadow = shadowItem.val;
                    }
                }
                if (font.ItemsElementName[counter] == ItemsChoiceType3.outline)
                {
                    var outlineItem = item as CT_BooleanProperty;
                    if (outlineItem != null)
                    {
                        cellFont.Outline = outlineItem.val;
                    }
                }
                if (font.ItemsElementName[counter] == ItemsChoiceType3.strike)
                {
                    var strikeItem = item as CT_BooleanProperty;
                    if (strikeItem != null)
                    {
                        cellFont.Strike = strikeItem.val;
                    }
                }
                if (font.ItemsElementName[counter] == ItemsChoiceType3.u)
                {
                    var underlineItem = item as CT_UnderlineProperty;
                    if (underlineItem != null)
                    {
                        cellFont.Underline = (FontUnderline)underlineItem.val;
                    }
                }
                if (font.ItemsElementName[counter] == ItemsChoiceType3.vertAlign)
                {
                    var vertAlignItem = item as CT_VerticalAlignFontProperty;
                    if (vertAlignItem != null)
                    {
                        cellFont.Script = (FontScript)vertAlignItem.val;
                    }
                }
                if (font.ItemsElementName[counter] == ItemsChoiceType3.color)
                {
                    var colorItem = item as CT_Color1;
                    if (colorItem != null)
                    {
                        cellFont.Color = ConvertColor(colorItem);
                    }
                }
                counter++;
            }

            return(cellFont);
        }
Пример #16
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");
        }
Пример #17
0
        /**
         * Copy font attributes from CTFont bean into CTRPrElt bean
         */
        private void SetRunAttributes(CT_Font ctFont, CT_RPrElt pr)
        {
            if (ctFont.SizeOfBArray() > 0)
            {
                pr.AddNewB().val = (ctFont.GetBArray(0).val);
            }
            if (ctFont.sizeOfUArray() > 0)
            {
                pr.AddNewU().val = (ctFont.GetUArray(0).val);
            }
            if (ctFont.sizeOfIArray() > 0)
            {
                pr.AddNewI().val = (ctFont.GetIArray(0).val);
            }
            if (ctFont.sizeOfColorArray() > 0)
            {
                CT_Color c1 = ctFont.GetColorArray(0);
                CT_Color c2 = pr.AddNewColor();
                if (c1.IsSetAuto())
                {
                    c2.auto          = (c1.auto);
                    c2.autoSpecified = true;
                }
                if (c1.IsSetIndexed())
                {
                    c2.indexed          = (c1.indexed);
                    c2.indexedSpecified = true;
                }
                if (c1.IsSetRgb())
                {
                    c2.SetRgb(c1.rgb);
                    c2.rgbSpecified = true;
                }
                if (c1.IsSetTheme())
                {
                    c2.theme          = (c1.theme);
                    c2.themeSpecified = true;
                }
                if (c1.IsSetTint())
                {
                    c2.tint          = (c1.tint);
                    c2.tintSpecified = true;
                }
            }

            if (ctFont.sizeOfSzArray() > 0)
            {
                pr.AddNewSz().val = (ctFont.GetSzArray(0).val);
            }
            if (ctFont.sizeOfNameArray() > 0)
            {
                pr.AddNewRFont().val = (ctFont.name.val);
            }
            if (ctFont.sizeOfFamilyArray() > 0)
            {
                pr.AddNewFamily().val = (ctFont.GetFamilyArray(0).val);
            }
            if (ctFont.sizeOfSchemeArray() > 0)
            {
                pr.AddNewScheme().val = (ctFont.GetSchemeArray(0).val);
            }
            if (ctFont.sizeOfCharsetArray() > 0)
            {
                pr.AddNewCharset().val = (ctFont.GetCharsetArray(0).val);
            }
            if (ctFont.sizeOfCondenseArray() > 0)
            {
                pr.AddNewCondense().val = (ctFont.GetCondenseArray(0).val);
            }
            if (ctFont.sizeOfExtendArray() > 0)
            {
                pr.AddNewExtend().val = (ctFont.GetExtendArray(0).val);
            }
            if (ctFont.sizeOfVertAlignArray() > 0)
            {
                pr.AddNewVertAlign().val = (ctFont.GetVertAlignArray(0).val);
            }
            if (ctFont.sizeOfOutlineArray() > 0)
            {
                pr.AddNewOutline().val = (ctFont.GetOutlineArray(0).val);
            }
            if (ctFont.sizeOfShadowArray() > 0)
            {
                pr.AddNewShadow().val = (ctFont.GetShadowArray(0).val);
            }
            if (ctFont.sizeOfStrikeArray() > 0)
            {
                pr.AddNewStrike().val = (ctFont.GetStrikeArray(0).val);
            }
        }
Пример #18
0
 private void SetRunAttributes(CT_Font ctFont, CT_RPrElt pr)
 {
     if (ctFont.sizeOfBArray() > 0)
     {
         pr.AddNewB().val = ctFont.GetBArray(0).val;
     }
     if (ctFont.sizeOfUArray() > 0)
     {
         pr.AddNewU().val = ctFont.GetUArray(0).val;
     }
     if (ctFont.sizeOfIArray() > 0)
     {
         pr.AddNewI().val = ctFont.GetIArray(0).val;
     }
     if (ctFont.sizeOfColorArray() > 0)
     {
         CT_Color colorArray = ctFont.GetColorArray(0);
         CT_Color ctColor    = pr.AddNewColor();
         if (colorArray.IsSetAuto())
         {
             ctColor.auto          = colorArray.auto;
             ctColor.autoSpecified = true;
         }
         if (colorArray.IsSetIndexed())
         {
             ctColor.indexed          = colorArray.indexed;
             ctColor.indexedSpecified = true;
         }
         if (colorArray.IsSetRgb())
         {
             ctColor.SetRgb(colorArray.rgb);
             ctColor.rgbSpecified = true;
         }
         if (colorArray.IsSetTheme())
         {
             ctColor.theme          = colorArray.theme;
             ctColor.themeSpecified = true;
         }
         if (colorArray.IsSetTint())
         {
             ctColor.tint          = colorArray.tint;
             ctColor.tintSpecified = true;
         }
     }
     if (ctFont.sizeOfSzArray() > 0)
     {
         pr.AddNewSz().val = ctFont.GetSzArray(0).val;
     }
     if (ctFont.sizeOfNameArray() > 0)
     {
         pr.AddNewRFont().val = ctFont.GetNameArray(0).val;
     }
     if (ctFont.sizeOfFamilyArray() > 0)
     {
         pr.AddNewFamily().val = ctFont.GetFamilyArray(0).val;
     }
     if (ctFont.sizeOfSchemeArray() > 0)
     {
         pr.AddNewScheme().val = ctFont.GetSchemeArray(0).val;
     }
     if (ctFont.sizeOfCharsetArray() > 0)
     {
         pr.AddNewCharset().val = ctFont.GetCharsetArray(0).val;
     }
     if (ctFont.sizeOfCondenseArray() > 0)
     {
         pr.AddNewCondense().val = ctFont.GetCondenseArray(0).val;
     }
     if (ctFont.sizeOfExtendArray() > 0)
     {
         pr.AddNewExtend().val = ctFont.GetExtendArray(0).val;
     }
     if (ctFont.sizeOfVertAlignArray() > 0)
     {
         pr.AddNewVertAlign().val = ctFont.GetVertAlignArray(0).val;
     }
     if (ctFont.sizeOfOutlineArray() > 0)
     {
         pr.AddNewOutline().val = ctFont.GetOutlineArray(0).val;
     }
     if (ctFont.sizeOfShadowArray() > 0)
     {
         pr.AddNewShadow().val = ctFont.GetShadowArray(0).val;
     }
     if (ctFont.sizeOfStrikeArray() <= 0)
     {
         return;
     }
     pr.AddNewStrike().val = ctFont.GetStrikeArray(0).val;
 }
Пример #19
0
 /**
  * Create a new XSSFFont
  *
  * @param font the underlying CT_Font bean
  */
 public XSSFFont(CT_Font font)
 {
     _ctFont = font;
     _index  = 0;
 }
Пример #20
0
 public XSSFFont(CT_Font font)
 {
     this._ctFont = font;
     this._index  = (short)0;
 }
Пример #21
0
 /**
  * Create a new XSSFont. This method is protected to be used only by XSSFWorkbook
  */
 public XSSFFont()
 {
     this._ctFont       = new CT_Font();
     FontName           = DEFAULT_FONT_NAME;
     FontHeightInPoints = DEFAULT_FONT_SIZE;
 }
Пример #22
0
 public XSSFFont(CT_Font font, int index)
 {
     this._ctFont = font;
     this._index  = (short)index;
 }
Пример #23
0
 /**
  * Set font style options to default values (non-italic, non-bold)
  */
 public void ResetFontStyle()
 {
     _font = new CT_Font();
 }
Пример #24
0
 public XSSFFont()
 {
     this._ctFont    = new CT_Font();
     this.FontName   = XSSFFont.DEFAULT_FONT_NAME;
     this.FontHeight = XSSFFont.DEFAULT_FONT_SIZE;
 }
Пример #25
0
        /**
         * Clones all the style information from another
         *  XSSFCellStyle, onto this one. This
         *  XSSFCellStyle will then have all the same
         *  properties as the source, but the two may
         *  be edited independently.
         * Any stylings on this XSSFCellStyle will be lost!
         *
         * The source XSSFCellStyle could be from another
         *  XSSFWorkbook if you like. This allows you to
         *  copy styles from one XSSFWorkbook to another.
         */

        public void CloneStyleFrom(ICellStyle source)
        {
            if (source is XSSFCellStyle)
            {
                XSSFCellStyle src = (XSSFCellStyle)source;

                // Is it on our Workbook?
                if (src._stylesSource == _stylesSource)
                {
                    // Nice and easy
                    _cellXf      = src.GetCoreXf().Copy();
                    _cellStyleXf = src.GetStyleXf().Copy();
                }
                else
                {
                    // Copy the style
                    try
                    {
                        // Remove any children off the current style, to
                        //  avoid orphaned nodes
                        if (_cellXf.IsSetAlignment())
                        {
                            _cellXf.UnsetAlignment();
                        }
                        if (_cellXf.IsSetExtLst())
                        {
                            _cellXf.UnsetExtLst();
                        }

                        // Create a new Xf with the same contents
                        _cellXf =
                            src.GetCoreXf().Copy();

                        // bug 56295: ensure that the fills is available and set correctly
                        CT_Fill fill = CT_Fill.Parse(src.GetCTFill().ToString());
                        AddFill(fill);

                        // Swap it over
                        _stylesSource.ReplaceCellXfAt(_cellXfId, _cellXf);
                    }
                    catch (XmlException e)
                    {
                        throw new POIXMLException(e);
                    }

                    // Copy the format
                    String fmt = src.GetDataFormatString();
                    DataFormat = (
                        (new XSSFDataFormat(_stylesSource)).GetFormat(fmt)
                        );

                    // Copy the font
                    try
                    {
                        CT_Font ctFont =
                            src.GetFont().GetCTFont().Clone();
                        XSSFFont font = new XSSFFont(ctFont);
                        font.RegisterTo(_stylesSource);
                        SetFont(font);
                    }
                    catch (XmlException e)
                    {
                        throw new POIXMLException(e);
                    }
                }

                // Clear out cached details
                _font          = null;
                _cellAlignment = null;
            }
            else
            {
                throw new ArgumentException("Can only clone from one XSSFCellStyle to another, not between HSSFCellStyle and XSSFCellStyle");
            }
        }
Пример #26
0
        private void Hydrate()
        {
            if (_stylesheet.Borders == null)
            {
                _stylesheet.Borders = new CT_Borders();
            }
            if (_stylesheet.CellStyles == null)
            {
                _stylesheet.CellStyles = new CT_CellStyles();
            }
            if (_stylesheet.CellStyleXfs == null)
            {
                _stylesheet.CellStyleXfs = new CT_CellStyleXfs();
            }
            if (_stylesheet.CellXfs == null)
            {
                _stylesheet.CellXfs = new CT_CellXfs();
            }
            if (_stylesheet.Fills == null)
            {
                _stylesheet.Fills = new CT_Fills();
            }
            if (_stylesheet.Fonts == null)
            {
                _stylesheet.Fonts = new CT_Fonts();
            }
            if (_stylesheet.NumFmts == null)
            {
                _stylesheet.NumFmts = new CT_NumFmts();
            }
            if (_stylesheet.Borders.Border == null)
            {
                _stylesheet.Borders.Border = new List <CT_Border>();
            }
            if (_stylesheet.CellStyles.CellStyle == null)
            {
                _stylesheet.CellStyles.CellStyle = new List <CT_CellStyle>();
            }
            if (_stylesheet.CellStyleXfs.Xf == null)
            {
                _stylesheet.CellStyleXfs.Xf = new List <CT_Xf>();
            }
            if (_stylesheet.CellXfs.Xf == null)
            {
                _stylesheet.CellXfs.Xf = new List <CT_Xf>();
            }
            if (_stylesheet.Fills.Fill == null)
            {
                _stylesheet.Fills.Fill = new List <CT_Fill>();
            }
            if (_stylesheet.Fonts.Font == null)
            {
                _stylesheet.Fonts.Font = new List <CT_Font>();
            }
            if (_stylesheet.NumFmts.NumFmt == null)
            {
                _stylesheet.NumFmts.NumFmt = new List <CT_NumFmt>();
            }
            foreach (CT_NumFmt item in _stylesheet.NumFmts.NumFmt)
            {
                _numberFormats.Add(item.FormatCode_Attr, item.NumFmtId_Attr);
            }
            for (int i = 0; i < _stylesheet.Fonts.Font.Count; i++)
            {
                CT_Font font = _stylesheet.Fonts.Font[i];
                _fonts.Add(new XMLFontModel(font, Palette), (uint)i);
            }
            foreach (CT_Fill item2 in _stylesheet.Fills.Fill)
            {
                _fills.Add(new XMLFillModel(item2, Palette));
            }
            foreach (CT_Border item3 in _stylesheet.Borders.Border)
            {
                _borders.Add(new XMLBorderModel(item3, Palette));
            }
            foreach (CT_Xf item4 in _stylesheet.CellXfs.Xf)
            {
                _styles.ForceAdd(new XMLStyleModel(item4, this, setVerticalAlignment: false));
            }
            List <string> list = new List <string>();

            foreach (CT_CellStyle item5 in _stylesheet.CellStyles.CellStyle)
            {
                list.Add(item5.Name_Attr);
                _namedlookup.Add(item5.Name_Attr, item5.XfId_Attr);
            }
            _stylesheet.NumFmts.NumFmt.Clear();
            _stylesheet.Fonts.Font.Clear();
            _stylesheet.Fills.Fill.Clear();
            _stylesheet.Borders.Border.Clear();
            _stylesheet.CellXfs.Xf.Clear();
            _stylesheet.CellStyles.CellStyle.Clear();
        }