Ejemplo n.º 1
0
        public void TestBug52348()
        {
            XSSFWorkbook workbook = XSSFTestDataSamples.OpenSampleWorkbook("52348.xlsx");
            StylesTable  st       = workbook.GetStylesSource();

            Assert.AreEqual(0, st.GetStyleXfsSize());


            XSSFCellStyle style = workbook.CreateCellStyle() as XSSFCellStyle; // no exception at this point

            Assert.IsNull(style.GetStyleXf());
        }
Ejemplo n.º 2
0
        public void TestBug55650()
        {
            XSSFWorkbook workbook = XSSFTestDataSamples.OpenSampleWorkbook("52348.xlsx");
            StylesTable st = workbook.GetStylesSource();
            Assert.AreEqual(0, st.StyleXfsSize);

            // no exception at this point
            XSSFCellStyle style = workbook.GetSheetAt(0).GetRow(0).GetCell(0).CellStyle as XSSFCellStyle;
            Assert.IsNull(style.GetStyleXf());

            Assert.IsNotNull(XSSFTestDataSamples.WriteOutAndReadBack(workbook));
        }
Ejemplo n.º 3
0
        public void CloneStyleFrom(ICellStyle source)
        {
            if (!(source is XSSFCellStyle))
            {
                throw new ArgumentException("Can only clone from one XSSFCellStyle to another, not between HSSFCellStyle and XSSFCellStyle");
            }
            XSSFCellStyle xssfCellStyle = (XSSFCellStyle)source;

            if (xssfCellStyle._stylesSource == this._stylesSource)
            {
                this._cellXf      = xssfCellStyle.GetCoreXf();
                this._cellStyleXf = xssfCellStyle.GetStyleXf();
            }
            else
            {
                try
                {
                    if (this._cellXf.IsSetAlignment())
                    {
                        this._cellXf.UnsetAlignment();
                    }
                    if (this._cellXf.IsSetExtLst())
                    {
                        this._cellXf.UnsetExtLst();
                    }
                    this._cellXf = CT_Xf.Parse(xssfCellStyle.GetCoreXf().ToString());
                    this._stylesSource.ReplaceCellXfAt(this._cellXfId, this._cellXf);
                }
                catch (XmlException ex)
                {
                    throw new POIXMLException((Exception)ex);
                }
                this.DataFormat = new XSSFDataFormat(this._stylesSource).GetFormat(xssfCellStyle.GetDataFormatString());
                try
                {
                    XSSFFont xssfFont = new XSSFFont(CT_Font.Parse(xssfCellStyle.GetFont().GetCTFont().ToString()));
                    xssfFont.RegisterTo(this._stylesSource);
                    this.SetFont((IFont)xssfFont);
                }
                catch (XmlException ex)
                {
                    throw new POIXMLException((Exception)ex);
                }
            }
            this._font          = (XSSFFont)null;
            this._cellAlignment = (XSSFCellAlignment)null;
        }
Ejemplo n.º 4
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 = CT_Xf.Parse(
                            src.GetCoreXf().ToString()
                            );
                        // 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 = CT_Font.Parse(
                            src.GetFont().GetCTFont().ToString()
                            );
                        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.º 5
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();
                        if (_cellXf.applyBorder)
                        {
                            //CellXF is copied with existing Ids, but those are different if you're copying between two documents
                            _cellXf.borderId = FindAddBorder(src._stylesSource.GetBorderAt((int)_cellXf.borderId).GetCTBorder());
                        }

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

                        if (src._cellStyleXf.applyBorder)
                        {
                            _cellStyleXf.borderId = FindAddBorder(src.GetCTBorder());
                        }

                        // 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");
            }
        }