Ejemplo n.º 1
0
 public static CT_Xf Parse(XmlNode node, XmlNamespaceManager namespaceManager)
 {
     if (node == null)
         return null;
     CT_Xf ctObj = new CT_Xf();
     ctObj.numFmtId = XmlHelper.ReadUInt(node.Attributes["numFmtId"]);
     ctObj.fontId = XmlHelper.ReadUInt(node.Attributes["fontId"]);
     ctObj.fillId = XmlHelper.ReadUInt(node.Attributes["fillId"]);
     ctObj.borderId = XmlHelper.ReadUInt(node.Attributes["borderId"]);
     ctObj.xfId = XmlHelper.ReadUInt(node.Attributes["xfId"]);
     ctObj.quotePrefix = XmlHelper.ReadBool(node.Attributes["quotePrefix"]);
     ctObj.pivotButton = XmlHelper.ReadBool(node.Attributes["pivotButton"]);
     ctObj.applyNumberFormat = XmlHelper.ReadBool(node.Attributes["applyNumberFormat"]);
     ctObj.applyFont = XmlHelper.ReadBool(node.Attributes["applyFont"]);
     ctObj.applyFill = XmlHelper.ReadBool(node.Attributes["applyFill"]);
     ctObj.applyBorder = XmlHelper.ReadBool(node.Attributes["applyBorder"]);
     ctObj.applyAlignment = XmlHelper.ReadBool(node.Attributes["applyAlignment"]);
     ctObj.applyProtection = XmlHelper.ReadBool(node.Attributes["applyProtection"]);
     foreach (XmlNode childNode in node.ChildNodes)
     {
         if (childNode.LocalName == "alignment")
             ctObj.alignment = CT_CellAlignment.Parse(childNode, namespaceManager);
         else if (childNode.LocalName == "protection")
             ctObj.protection = CT_CellProtection.Parse(childNode, namespaceManager);
         else if (childNode.LocalName == "extLst")
             ctObj.extLst = CT_ExtensionList.Parse(childNode, namespaceManager);
     }
     return ctObj;
 }
Ejemplo n.º 2
0
 /**
  * Creates a Cell Style from the supplied parts
  * @param cellXfId The main XF for the cell. Must be a valid 0-based index into the XF table
  * @param cellStyleXfId Optional, style xf. A value of <code>-1</code> means no xf.
  * @param stylesSource Styles Source to work off
  */
 public XSSFCellStyle(int cellXfId, int cellStyleXfId, StylesTable stylesSource, ThemesTable theme)
 {
     _cellXfId = cellXfId;
     _stylesSource = stylesSource;
     _cellXf = stylesSource.GetCellXfAt(this._cellXfId);
     _cellStyleXf = cellStyleXfId == -1 ? null : stylesSource.GetCellStyleXfAt(cellStyleXfId);
     _theme = theme;
 }
Ejemplo n.º 3
0
 public CT_Xf AddNewXf()
 {
     if (this.xfField == null)
         this.xfField = new List<CT_Xf>();
     CT_Xf xf = new CT_Xf();
     this.xfField.Add(xf);
     return xf;
 }
Ejemplo 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);
        }
Ejemplo n.º 5
0
        public CT_Xf Copy()
        {
            CT_Xf obj = new CT_Xf();
            obj.alignmentField = this.alignmentField;
            obj.protectionField = this.protectionField;
            obj.extLstField = null == extLstField ? null : this.extLstField.Copy();

            obj.applyAlignmentField = this.applyAlignmentField;
            obj.applyBorderField = this.applyBorderField;
            obj.applyFillField = this.applyFillField;
            obj.applyFontField = this.applyFontField;
            obj.applyNumberFormatField = this.applyNumberFormatField;
            obj.applyProtectionField = this.applyProtectionField;
            obj.borderIdField = this.borderIdField;
            obj.fillIdField = this.fillIdField;
            obj.fontIdField = this.fontIdField;
            obj.numFmtIdField = this.numFmtIdField;
            obj.pivotButtonField = this.pivotButtonField;
            obj.quotePrefixField = this.quotePrefixField;
            obj.xfIdField = this.xfIdField;
            return obj;
        }
Ejemplo n.º 6
0
        public static CT_Xf Parse(XmlNode node, XmlNamespaceManager namespaceManager)
        {
            if (node == null)
            {
                return(null);
            }
            CT_Xf ctObj = new CT_Xf();

            ctObj.numFmtId          = XmlHelper.ReadUInt(node.Attributes["numFmtId"]);
            ctObj.fontId            = XmlHelper.ReadUInt(node.Attributes["fontId"]);
            ctObj.fillId            = XmlHelper.ReadUInt(node.Attributes["fillId"]);
            ctObj.borderId          = XmlHelper.ReadUInt(node.Attributes["borderId"]);
            ctObj.xfId              = XmlHelper.ReadUInt(node.Attributes["xfId"]);
            ctObj.quotePrefix       = XmlHelper.ReadBool(node.Attributes["quotePrefix"]);
            ctObj.pivotButton       = XmlHelper.ReadBool(node.Attributes["pivotButton"]);
            ctObj.applyNumberFormat = XmlHelper.ReadBool(node.Attributes["applyNumberFormat"]);
            ctObj.applyFont         = XmlHelper.ReadBool(node.Attributes["applyFont"]);
            ctObj.applyFill         = XmlHelper.ReadBool(node.Attributes["applyFill"]);
            ctObj.applyBorder       = XmlHelper.ReadBool(node.Attributes["applyBorder"]);
            ctObj.applyAlignment    = XmlHelper.ReadBool(node.Attributes["applyAlignment"]);
            ctObj.applyProtection   = XmlHelper.ReadBool(node.Attributes["applyProtection"]);
            foreach (XmlNode childNode in node.ChildNodes)
            {
                if (childNode.LocalName == "alignment")
                {
                    ctObj.alignment = CT_CellAlignment.Parse(childNode, namespaceManager);
                }
                else if (childNode.LocalName == "protection")
                {
                    ctObj.protection = CT_CellProtection.Parse(childNode, namespaceManager);
                }
                else if (childNode.LocalName == "extLst")
                {
                    ctObj.extLst = CT_ExtensionList.Parse(childNode, namespaceManager);
                }
            }
            return(ctObj);
        }
Ejemplo n.º 7
0
        public CT_Xf Copy()
        {
            CT_Xf obj = new CT_Xf();

            obj.alignmentField  = this.alignmentField;
            obj.protectionField = this.protectionField;
            obj.extLstField     = null == extLstField ? null : this.extLstField.Copy();

            obj.applyAlignmentField    = this.applyAlignmentField;
            obj.applyBorderField       = this.applyBorderField;
            obj.applyFillField         = this.applyFillField;
            obj.applyFontField         = this.applyFontField;
            obj.applyNumberFormatField = this.applyNumberFormatField;
            obj.applyProtectionField   = this.applyProtectionField;
            obj.borderIdField          = this.borderIdField;
            obj.fillIdField            = this.fillIdField;
            obj.fontIdField            = this.fontIdField;
            obj.numFmtIdField          = this.numFmtIdField;
            obj.pivotButtonField       = this.pivotButtonField;
            obj.quotePrefixField       = this.quotePrefixField;
            obj.xfIdField = this.xfIdField;
            return(obj);
        }
Ejemplo n.º 8
0
 internal int PutCellStyleXf(CT_Xf cellStyleXf)
 {
     styleXfs.Add(cellStyleXf);
     return styleXfs.Count;
 }
Ejemplo n.º 9
0
 internal void ReplaceCellXfAt(int idx, CT_Xf cellXf)
 {
     xfs[idx] = cellXf;
 }
Ejemplo n.º 10
0
 internal int PutCellXf(CT_Xf cellXf)
 {
     xfs.Add(cellXf);
     return xfs.Count;
 }
Ejemplo n.º 11
0
 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);
 }
Ejemplo n.º 12
0
 public XSSFCellStyle CreateCellStyle()
 {
     CT_Xf ctXf = new CT_Xf();
     ctXf.numFmtId = 0;
     ctXf.fontId = 0;
     ctXf.fillId = 0;
     ctXf.borderId = 0;
     ctXf.xfId = 0;
     int xfSize = styleXfs.Count;
     int indexXf = PutCellXf(ctXf);
     return new XSSFCellStyle(indexXf - 1, xfSize - 1, this, theme);
 }
Ejemplo n.º 13
0
 public void ReplaceCellXfAt(int idx, CT_Xf cellXf)
 {
     xfs[idx] = cellXf;
 }
Ejemplo n.º 14
0
 public int PutCellXf(CT_Xf cellXf)
 {
     xfs.Add(cellXf);
     return xfs.Count;
 }
Ejemplo n.º 15
0
 public static void Save(Stream stream, CT_Xf font)
 {
     serializer.Serialize(stream, font, namespaces);
 }
Ejemplo n.º 16
0
 internal void ReplaceCellStyleXfAt(int idx, CT_Xf cellStyleXf)
 {
     styleXfs[idx] = cellStyleXf;
 }
Ejemplo n.º 17
0
 private static CT_Xf CreateDefaultXf()
 {
     CT_Xf ctXf = new CT_Xf();
     ctXf.numFmtId = 0;
     ctXf.fontId = 0;
     ctXf.fillId = 0;
     ctXf.borderId = 0;
     return ctXf;
 }
Ejemplo n.º 18
0
        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));
        }
Ejemplo n.º 19
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();
                    _cellStyleXf = src.GetStyleXf();
                }
                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();
                        // 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");
            }
        }
Ejemplo n.º 20
0
        public void TestSetDefaultColumnStyle()
        {
            XSSFWorkbook workbook = new XSSFWorkbook();
            XSSFSheet sheet = (XSSFSheet)workbook.CreateSheet();
            CT_Worksheet ctWorksheet = sheet.GetCTWorksheet();
            StylesTable stylesTable = workbook.GetStylesSource();
            XSSFFont font = new XSSFFont();
            font.FontName = ("Cambria");
            stylesTable.PutFont(font);
            CT_Xf cellStyleXf = new CT_Xf();
            cellStyleXf.fontId = (1);
            cellStyleXf.fillId= 0;
            cellStyleXf.borderId= 0;
            cellStyleXf.numFmtId= 0;
            stylesTable.PutCellStyleXf(cellStyleXf);
            CT_Xf cellXf = new CT_Xf();
            cellXf.xfId = (1);
            stylesTable.PutCellXf(cellXf);
            XSSFCellStyle cellStyle = new XSSFCellStyle(1, 1, stylesTable, null);
            Assert.AreEqual(1, cellStyle.FontIndex);

            sheet.SetDefaultColumnStyle(3, cellStyle);
            Assert.AreEqual(1u, ctWorksheet.GetColsArray(0).GetColArray(0).style);
        }
Ejemplo n.º 21
0
 /**
  * Creates an empty Cell Style
  */
 public XSSFCellStyle(StylesTable stylesSource)
 {
     _stylesSource = stylesSource;
     // We need a new CT_Xf for the main styles
     // TODO decide on a style ctxf
     _cellXf = new CT_Xf();
     _cellStyleXf = null;
 }
Ejemplo n.º 22
0
 public static void Save(Stream stream, CT_Xf font)
 {
     serializer.Serialize(stream, font, namespaces);
 }