コード例 #1
0
ファイル: StylesTable.cs プロジェクト: judypol/Npoi.netcore
        public XSSFCellStyle CreateCellStyle()
        {
            int xfSize = styleXfs.Count;

            if (xfSize > MAXIMUM_STYLE_ID)
            {
                throw new InvalidOperationException("The maximum number of Cell Styles was exceeded. " +
                                                    "You can define up to " + MAXIMUM_STYLE_ID + " style in a .xlsx Workbook");
            }

            CT_Xf ctXf = new CT_Xf();

            ctXf.numFmtId = 0;
            ctXf.fontId   = 0;
            ctXf.fillId   = 0;
            ctXf.borderId = 0;
            ctXf.xfId     = 0;

            int indexXf = PutCellXf(ctXf);

            return(new XSSFCellStyle(indexXf - 1, xfSize - 1, this, theme));
        }
コード例 #2
0
ファイル: StylesTable.cs プロジェクト: zbl960/npoi
        private void Initialize()
        {
            //CT_Font ctFont = CreateDefaultFont();
            XSSFFont xssfFont = CreateDefaultFont();

            fonts.Add(xssfFont);

            CT_Fill[] ctFill = CreateDefaultFills();
            fills.Add(new XSSFCellFill(ctFill[0]));
            fills.Add(new XSSFCellFill(ctFill[1]));

            CT_Border ctBorder = CreateDefaultBorder();

            borders.Add(new XSSFCellBorder(ctBorder));

            CT_Xf styleXf = CreateDefaultXf();

            styleXfs.Add(styleXf);
            CT_Xf xf = CreateDefaultXf();

            xf.xfId = 0;
            xfs.Add(xf);
        }
コード例 #3
0
ファイル: TestColumnHelper.cs プロジェクト: zuiwanting/npoi
        public void TestGetSetColDefaultStyle()
        {
            XSSFWorkbook workbook     = new XSSFWorkbook();
            XSSFSheet    sheet        = (XSSFSheet)workbook.CreateSheet();
            CT_Worksheet ctWorksheet  = sheet.GetCTWorksheet();
            ColumnHelper columnHelper = sheet.GetColumnHelper();

            // POI column 3, OOXML column 4
            CT_Col col = columnHelper.GetOrCreateColumn1Based(4, false);

            Assert.IsNotNull(col);
            Assert.IsNotNull(columnHelper.GetColumn(3, false));
            columnHelper.SetColDefaultStyle(3, 2);
            Assert.AreEqual(2, columnHelper.GetColDefaultStyle(3));
            Assert.AreEqual(-1, columnHelper.GetColDefaultStyle(4));
            StylesTable stylesTable = workbook.GetStylesSource();
            CT_Xf       cellXf      = new CT_Xf();

            cellXf.fontId   = (0);
            cellXf.fillId   = (0);
            cellXf.borderId = (0);
            cellXf.numFmtId = (0);
            cellXf.xfId     = (0);
            stylesTable.PutCellXf(cellXf);
            CT_Col col_2 = ctWorksheet.GetColsArray(0).AddNewCol();

            col_2.min            = (10);
            col_2.max            = (12);
            col_2.style          = (1);
            col_2.styleSpecified = true;
            Assert.AreEqual(1, columnHelper.GetColDefaultStyle(11));
            XSSFCellStyle cellStyle = new XSSFCellStyle(0, 0, stylesTable, null);

            columnHelper.SetColDefaultStyle(11, cellStyle);
            Assert.AreEqual(0u, col_2.style);
            Assert.AreEqual(1, columnHelper.GetColDefaultStyle(10));
        }
コード例 #4
0
ファイル: StylesTable.cs プロジェクト: zbl960/npoi
 internal int PutCellStyleXf(CT_Xf cellStyleXf)
 {
     styleXfs.Add(cellStyleXf);
     return(styleXfs.Count);
 }
コード例 #5
0
ファイル: StylesTable.cs プロジェクト: zbl960/npoi
 internal void ReplaceCellXfAt(int idx, CT_Xf cellXf)
 {
     xfs[idx] = cellXf;
 }
コード例 #6
0
ファイル: StylesTable.cs プロジェクト: zbl960/npoi
 internal int PutCellXf(CT_Xf cellXf)
 {
     xfs.Add(cellXf);
     return(xfs.Count);
 }
コード例 #7
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");
            }
        }
コード例 #8
0
 public void ReplaceCellXfAt(int idx, CT_Xf cellXf)
 {
     xfs[idx] = cellXf;
 }
コード例 #9
0
 public int PutCellStyleXf(CT_Xf cellStyleXf)
 {
     this.styleXfs.Add(cellStyleXf);
     return(this.styleXfs.Count);
 }
コード例 #10
0
 public XMLStyleModel(CT_Xf xf, StyleManager manager)
     : this(xf, manager, setVerticalAlignment : true)
 {
 }
コード例 #11
0
 /// <summary>
 /// Adds a cell style to the styles table.Does not check for duplicates.
 /// </summary>
 /// <param name="cellStyleXf">the cell style to add to the styles table</param>
 /// <returns>return the cell style ID in the style table</returns>
 internal int PutCellStyleXf(CT_Xf cellStyleXf)
 {
     styleXfs.Add(cellStyleXf);
     // TODO: check for duplicate
     return(styleXfs.Count);
 }
コード例 #12
0
 public XSSFCellStyle(StylesTable stylesSource)
 {
     this._stylesSource = stylesSource;
     this._cellXf       = new CT_Xf();
     this._cellStyleXf  = (CT_Xf)null;
 }
コード例 #13
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");
        }
コード例 #14
0
 public XMLStyleModel(CT_Xf xf, StyleManager manager)
     : this(xf, manager, true)
 {
 }
コード例 #15
0
 public void ReplaceCellStyleXfAt(int idx, CT_Xf cellStyleXf)
 {
     this.styleXfs[idx] = cellStyleXf;
 }
コード例 #16
0
ファイル: StylesTable.cs プロジェクト: zbl960/npoi
 internal void ReplaceCellStyleXfAt(int idx, CT_Xf cellStyleXf)
 {
     styleXfs[idx] = cellStyleXf;
 }
コード例 #17
0
 public int PutCellXf(CT_Xf cellXf)
 {
     xfs.Add(cellXf);
     return(xfs.Count);
 }
コード例 #18
0
 public int PutCellXf(CT_Xf cellXf)
 {
     this.xfs.Add(cellXf);
     return(this.xfs.Count);
 }