Esempio n. 1
0
        public void TestApplyFont()
        {

            XSSFRichTextString rt = new XSSFRichTextString();
            rt.Append("123");
            rt.Append("4567");
            rt.Append("89");

            Assert.AreEqual("123456789", rt.String);

            XSSFFont font1 = new XSSFFont();
            font1.IsBold = (true);

            rt.ApplyFont(2, 5, font1);

            Assert.AreEqual(4, rt.NumFormattingRuns);
            Assert.AreEqual(0, rt.GetIndexOfFormattingRun(0));
            Assert.AreEqual("12", rt.GetCTRst().GetRArray(0).t);

            Assert.AreEqual(2, rt.GetIndexOfFormattingRun(1));
            Assert.AreEqual("345", rt.GetCTRst().GetRArray(1).t);

            Assert.AreEqual(5, rt.GetIndexOfFormattingRun(2));
            Assert.AreEqual(2, rt.GetLengthOfFormattingRun(2));
            Assert.AreEqual("67", rt.GetCTRst().GetRArray(2).t);

            Assert.AreEqual(7, rt.GetIndexOfFormattingRun(3));
            Assert.AreEqual(2, rt.GetLengthOfFormattingRun(3));
            Assert.AreEqual("89", rt.GetCTRst().GetRArray(3).t);
        }
Esempio n. 2
0
        public void TestBoldweight()
        {
            CT_Font ctFont = new CT_Font();
            CT_BooleanProperty bool1 = ctFont.AddNewB();
            bool1.val = (false);
            ctFont.SetBArray(0, bool1);
            XSSFFont xssfFont = new XSSFFont(ctFont);
            Assert.AreEqual(false, xssfFont.IsBold);

            xssfFont.IsBold = (true);
            Assert.AreEqual(ctFont.b.Count, 1);
            Assert.AreEqual(true, ctFont.GetBArray(0).val);
        }
Esempio n. 3
0
        public void TestCharSet()
        {
            CT_Font ctFont = new CT_Font();
            CT_IntProperty prop = ctFont.AddNewCharset();
            prop.val = (FontCharset.ANSI.Value);

            ctFont.SetCharsetArray(0, prop);
            XSSFFont xssfFont = new XSSFFont(ctFont);
            Assert.AreEqual(FontCharset.ANSI.Value, xssfFont.Charset);

            xssfFont.SetCharSet(FontCharset.DEFAULT);
            Assert.AreEqual(FontCharset.DEFAULT.Value, ctFont.GetCharsetArray(0).val);

            // Try with a few less usual ones:
            // Set with the Charset itself
            xssfFont.SetCharSet(FontCharset.RUSSIAN);
            Assert.AreEqual(FontCharset.RUSSIAN.Value, xssfFont.Charset);
            // And Set with the Charset index
            xssfFont.SetCharSet(FontCharset.ARABIC.Value);
            Assert.AreEqual(FontCharset.ARABIC.Value, xssfFont.Charset);

            // This one isn't allowed
            Assert.AreEqual(null, FontCharset.ValueOf(9999));
            try
            {
                xssfFont.SetCharSet(9999);
                Assert.Fail("Shouldn't be able to Set an invalid charset");
            }
            catch (POIXMLException) { }


            // Now try with a few sample files

            // Normal charset
            XSSFWorkbook workbook = XSSFTestDataSamples.OpenSampleWorkbook("Formatting.xlsx");
            Assert.AreEqual(0,
                  ((XSSFCellStyle)workbook.GetSheetAt(0).GetRow(0).GetCell(0).CellStyle).GetFont().Charset
            );

            // GB2312 charact Set
            workbook = XSSFTestDataSamples.OpenSampleWorkbook("49273.xlsx");
            Assert.AreEqual(134,
                  ((XSSFCellStyle)workbook.GetSheetAt(0).GetRow(0).GetCell(0).CellStyle).GetFont().Charset
            );
        }
Esempio 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);
        }
Esempio n. 5
0
 public void SetStylesTableReference(StylesTable stylestable)
 {
     this.styles = stylestable;
     if (st.sizeOfRArray() > 0)
     {
         foreach (CT_RElt r in st.r)
         {
             CT_RPrElt pr = r.rPr;
             if (pr != null && pr.sizeOfRFontArray() > 0)
             {
                 String fontName = pr.GetRFontArray(0).val;
                 if (fontName.StartsWith("#"))
                 {
                     int      idx  = int.Parse(fontName.Substring(1));
                     XSSFFont font = styles.GetFontAt(idx);
                     //pr.removeRFont(0);
                     pr.rFont = null;
                     SetRunAttributes(font.GetCTFont(), pr);
                 }
             }
         }
     }
 }
Esempio n. 6
0
        /**
         * Return a copy of the font in use at a particular index.
         *
         * @param index         The index.
         * @return              A copy of the  font that's currently being applied at that
         *                      index or null if no font is being applied or the
         *                      index is out of range.
         */
        public short GetFontAtIndex(int index)
        {
            if (st.sizeOfRArray() == 0)
            {
                return(-1);
            }

            int pos = 0;

            for (int i = 0; i < st.sizeOfRArray(); i++)
            {
                CT_RElt r = st.GetRArray(i);
                if (index >= pos && index < pos + r.t.Length)
                {
                    XSSFFont fnt = new XSSFFont(ToCTFont(r.rPr));
                    fnt.SetThemesTable(GetThemesTable());
                    return(fnt.Index);
                }

                pos += r.t.Length;
            }
            return(-1);
        }
Esempio n. 7
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]);
        }
Esempio n. 8
0
        /**
         * Return a copy of the font in use at a particular index.
         *
         * @param index         The index.
         * @return              A copy of the  font that's currently being applied at that
         *                      index or null if no font is being applied or the
         *                      index is out of range.
         */
        public XSSFFont GetFontAtIndex(int index)
        {
            ThemesTable themes = GetThemesTable();
            int         pos    = 0;

            if (st.r == null)
            {
                return(null);
            }
            foreach (CT_RElt r in st.r)
            {
                int length = r.t.Length;
                if (index >= pos && index < pos + length)
                {
                    XSSFFont fnt = new XSSFFont(ToCTFont(r.rPr));
                    fnt.SetThemesTable(themes);
                    return(fnt);
                }

                pos += length;
            }
            return(null);
        }
Esempio n. 9
0
        public void TestApplyFont()
        {
            XSSFRichTextString rt = new XSSFRichTextString();

            rt.Append("123");
            rt.Append("4567");
            rt.Append("89");

            Assert.AreEqual("123456789", rt.String);
            Assert.AreEqual(false, rt.HasFormatting());

            XSSFFont font1 = new XSSFFont();

            font1.IsBold = (true);

            rt.ApplyFont(2, 5, font1);
            Assert.AreEqual(true, rt.HasFormatting());

            Assert.AreEqual(4, rt.NumFormattingRuns);
            Assert.AreEqual(0, rt.GetIndexOfFormattingRun(0));
            Assert.AreEqual("12", rt.GetCTRst().GetRArray(0).t);

            Assert.AreEqual(2, rt.GetIndexOfFormattingRun(1));
            Assert.AreEqual("345", rt.GetCTRst().GetRArray(1).t);

            Assert.AreEqual(5, rt.GetIndexOfFormattingRun(2));
            Assert.AreEqual(2, rt.GetLengthOfFormattingRun(2));
            Assert.AreEqual("67", rt.GetCTRst().GetRArray(2).t);

            Assert.AreEqual(7, rt.GetIndexOfFormattingRun(3));
            Assert.AreEqual(2, rt.GetLengthOfFormattingRun(3));
            Assert.AreEqual("89", rt.GetCTRst().GetRArray(3).t);

            Assert.AreEqual(-1, rt.GetIndexOfFormattingRun(9999));
            Assert.AreEqual(-1, rt.GetLengthOfFormattingRun(9999));
            Assert.IsNull(rt.GetFontAtIndex(9999));
        }
Esempio n. 10
0
        public void TestCloneStyleSameWB()
        {
            XSSFWorkbook wb = new XSSFWorkbook();
            Assert.AreEqual(1, wb.NumberOfFonts);

            XSSFFont fnt = (XSSFFont)wb.CreateFont();
            fnt.FontName = ("TestingFont");
            Assert.AreEqual(2, wb.NumberOfFonts);

            XSSFCellStyle orig = (XSSFCellStyle)wb.CreateCellStyle();
            orig.Alignment = (HorizontalAlignment.Right);
            orig.SetFont(fnt);
            orig.DataFormat = (short)18;

            Assert.AreEqual(HorizontalAlignment.Right, orig.Alignment);
            Assert.AreEqual(fnt, orig.GetFont());
            Assert.AreEqual(18, orig.DataFormat);

            XSSFCellStyle clone = (XSSFCellStyle)wb.CreateCellStyle();
            Assert.AreNotEqual(HorizontalAlignment.Right, clone.Alignment);
            Assert.AreNotEqual(fnt, clone.GetFont());
            Assert.AreNotEqual(18, clone.DataFormat);

            clone.CloneStyleFrom(orig);
            Assert.AreEqual(HorizontalAlignment.Right, clone.Alignment);
            Assert.AreEqual(fnt, clone.GetFont());
            Assert.AreEqual(18, clone.DataFormat);
            Assert.AreEqual(2, wb.NumberOfFonts);

            clone.Alignment = HorizontalAlignment.Left;
            clone.DataFormat = 17;
            Assert.AreEqual(HorizontalAlignment.Right, orig.Alignment);
            Assert.AreEqual(18, orig.DataFormat);

            Assert.IsNotNull(XSSFTestDataSamples.WriteOutAndReadBack(wb));
        }
Esempio n. 11
0
        public void GetFontAt()
        {
            XSSFWorkbook workbook = new XSSFWorkbook();

            try
            {
                StylesTable styleSource = workbook.GetStylesSource();
                short       i           = 0;
                //get default font
                IFont fontAt = workbook.GetFontAt(i);
                Assert.IsNotNull(fontAt);

                //get customized font
                XSSFFont customFont = new XSSFFont();
                customFont.IsItalic = (true);
                int x = styleSource.PutFont(customFont);
                fontAt = workbook.GetFontAt((short)x);
                Assert.IsNotNull(fontAt);
            }
            finally
            {
                workbook.Close();
            }
        }
Esempio n. 12
0
        public void TestClearFormatting()
        {
            XSSFRichTextString rt = new XSSFRichTextString("Apache POI");

            Assert.AreEqual("Apache POI", rt.String);

            rt.ClearFormatting();

            CT_Rst st = rt.GetCTRst();

            Assert.IsTrue(st.IsSetT());
            Assert.AreEqual("Apache POI", rt.String);
            Assert.AreEqual(0, rt.NumFormattingRuns);

            XSSFFont font = new XSSFFont();

            font.IsBold = true;

            rt.ApplyFont(7, 10, font);
            Assert.AreEqual(2, rt.NumFormattingRuns);
            rt.ClearFormatting();
            Assert.AreEqual("Apache POI", rt.String);
            Assert.AreEqual(0, rt.NumFormattingRuns);
        }
Esempio n. 13
0
        public void TestSetTextSingleParagraph()
        {
            XSSFWorkbook wb      = new XSSFWorkbook();
            XSSFSheet    sheet   = wb.CreateSheet() as XSSFSheet;
            XSSFDrawing  Drawing = sheet.CreateDrawingPatriarch() as XSSFDrawing;

            XSSFTextBox        shape = Drawing.CreateTextbox(new XSSFClientAnchor(0, 0, 0, 0, 2, 2, 3, 4));
            XSSFRichTextString rt    = new XSSFRichTextString("Test String");

            XSSFFont font = wb.CreateFont() as XSSFFont;

            font.SetColor(new XSSFColor(Color.FromArgb(0, 255, 255)));
            font.FontName = ("Arial");
            rt.ApplyFont(font);

            shape.SetText(rt);

            List <XSSFTextParagraph> paras = shape.TextParagraphs;

            Assert.AreEqual(1, paras.Count);
            Assert.AreEqual("Test String", paras[0].Text);

            List <XSSFTextRun> runs = paras[0].TextRuns;

            Assert.AreEqual(1, runs.Count);
            Assert.AreEqual("Arial", runs[0].FontFamily);

            Color clr = runs[0].FontColor;

            Assert.IsTrue(Arrays.Equals(
                              new int[] { 0, 255, 255 },
                              new int[] { clr.R, clr.G, clr.B }));

            checkRewrite(wb);
            wb.Close();
        }
Esempio n. 14
0
        public void XSSFTextParagraphTest()
        {
            XSSFWorkbook wb = new XSSFWorkbook();

            try
            {
                XSSFSheet   sheet   = wb.CreateSheet() as XSSFSheet;
                XSSFDrawing Drawing = sheet.CreateDrawingPatriarch() as XSSFDrawing;

                XSSFTextBox        shape = Drawing.CreateTextbox(new XSSFClientAnchor(0, 0, 0, 0, 2, 2, 3, 4)) as XSSFTextBox;
                XSSFRichTextString rt    = new XSSFRichTextString("Test String");

                XSSFFont font  = wb.CreateFont() as XSSFFont;
                Color    color = Color.FromArgb(0, 255, 255);
                font.SetColor(new XSSFColor(color));
                font.FontName = (/*setter*/ "Arial");
                rt.ApplyFont(font);

                shape.SetText(rt);

                List <XSSFTextParagraph> paras = shape.TextParagraphs;
                Assert.AreEqual(1, paras.Count);

                XSSFTextParagraph text = paras[(0)];
                Assert.AreEqual("Test String", text.Text);

                Assert.IsFalse(text.IsBullet());
                Assert.IsNotNull(text.GetXmlObject());
                Assert.AreEqual(shape.GetCTShape(), text.ParentShape);
                Assert.IsNotNull(text.GetEnumerator());
                Assert.IsNotNull(text.AddLineBreak());

                Assert.IsNotNull(text.TextRuns);
                Assert.AreEqual(2, text.TextRuns.Count);
                text.AddNewTextRun();
                Assert.AreEqual(3, text.TextRuns.Count);

                Assert.AreEqual(TextAlign.LEFT, text.TextAlign);
                text.TextAlign = TextAlign.None;
                Assert.AreEqual(TextAlign.LEFT, text.TextAlign);
                text.TextAlign = (/*setter*/ TextAlign.CENTER);
                Assert.AreEqual(TextAlign.CENTER, text.TextAlign);
                text.TextAlign = (/*setter*/ TextAlign.RIGHT);
                Assert.AreEqual(TextAlign.RIGHT, text.TextAlign);
                text.TextAlign = TextAlign.None;
                Assert.AreEqual(TextAlign.LEFT, text.TextAlign);

                text.TextFontAlign = (/*setter*/ TextFontAlign.BASELINE);
                Assert.AreEqual(TextFontAlign.BASELINE, text.TextFontAlign);
                text.TextFontAlign = (/*setter*/ TextFontAlign.BOTTOM);
                Assert.AreEqual(TextFontAlign.BOTTOM, text.TextFontAlign);
                text.TextFontAlign = TextFontAlign.None;
                Assert.AreEqual(TextFontAlign.BASELINE, text.TextFontAlign);
                text.TextFontAlign = TextFontAlign.None;
                Assert.AreEqual(TextFontAlign.BASELINE, text.TextFontAlign);

                Assert.IsNull(text.BulletFont);
                text.BulletFont = (/*setter*/ "Arial");
                Assert.AreEqual("Arial", text.BulletFont);

                Assert.IsNull(text.BulletCharacter);
                text.BulletCharacter = (/*setter*/ ".");
                Assert.AreEqual(".", text.BulletCharacter);

                Assert.IsNull(text.BulletFontColor);
                text.BulletFontColor = (/*setter*/ color);
                Assert.AreEqual(color, text.BulletFontColor);

                Assert.AreEqual(100.0, text.BulletFontSize, 0.01);
                text.BulletFontSize = (/*setter*/ 1.0);
                Assert.AreEqual(1.0, text.BulletFontSize, 0.01);
                text.BulletFontSize = (/*setter*/ 1.0);
                Assert.AreEqual(1.0, text.BulletFontSize, 0.01);
                text.BulletFontSize = (/*setter*/ -9.0);
                Assert.AreEqual(-9.0, text.BulletFontSize, 0.01);
                text.BulletFontSize = (/*setter*/ -9.0);
                Assert.AreEqual(-9.0, text.BulletFontSize, 0.01);
                text.BulletFontSize = (/*setter*/ 1.0);
                Assert.AreEqual(1.0, text.BulletFontSize, 0.01);
                text.BulletFontSize = (/*setter*/ -9.0);
                Assert.AreEqual(-9.0, text.BulletFontSize, 0.01);

                Assert.AreEqual(0.0, text.Indent, 0.01);
                text.Indent = (/*setter*/ 2.0);
                Assert.AreEqual(2.0, text.Indent, 0.01);
                text.Indent = (/*setter*/ -1.0);
                Assert.AreEqual(0.0, text.Indent, 0.01);
                text.Indent = (/*setter*/ -1.0);
                Assert.AreEqual(0.0, text.Indent, 0.01);

                Assert.AreEqual(0.0, text.LeftMargin, 0.01);
                text.LeftMargin = (/*setter*/ 3.0);
                Assert.AreEqual(3.0, text.LeftMargin, 0.01);
                text.LeftMargin = (/*setter*/ -1.0);
                Assert.AreEqual(0.0, text.LeftMargin, 0.01);
                text.LeftMargin = (/*setter*/ -1.0);
                Assert.AreEqual(0.0, text.LeftMargin, 0.01);

                Assert.AreEqual(0.0, text.RightMargin, 0.01);
                text.RightMargin = (/*setter*/ 4.5);
                Assert.AreEqual(4.5, text.RightMargin, 0.01);
                text.RightMargin = (/*setter*/ -1.0);
                Assert.AreEqual(0.0, text.RightMargin, 0.01);
                text.RightMargin = (/*setter*/ -1.0);
                Assert.AreEqual(0.0, text.RightMargin, 0.01);

                Assert.AreEqual(0.0, text.DefaultTabSize, 0.01);

                Assert.AreEqual(0.0, text.GetTabStop(0), 0.01);
                text.AddTabStop(3.14);
                Assert.AreEqual(3.14, text.GetTabStop(0), 0.01);

                Assert.AreEqual(100.0, text.LineSpacing, 0.01);
                text.LineSpacing = (/*setter*/ 3.15);
                Assert.AreEqual(3.15, text.LineSpacing, 0.01);
                text.LineSpacing = (/*setter*/ -2.13);
                Assert.AreEqual(-2.13, text.LineSpacing, 0.01);

                Assert.AreEqual(0.0, text.SpaceBefore, 0.01);
                text.SpaceBefore = (/*setter*/ 3.17);
                Assert.AreEqual(3.17, text.SpaceBefore, 0.01);
                text.SpaceBefore = (/*setter*/ -4.7);
                Assert.AreEqual(-4.7, text.SpaceBefore, 0.01);

                Assert.AreEqual(0.0, text.SpaceAfter, 0.01);
                text.SpaceAfter = (/*setter*/ 6.17);
                Assert.AreEqual(6.17, text.SpaceAfter, 0.01);
                text.SpaceAfter = (/*setter*/ -8.17);
                Assert.AreEqual(-8.17, text.SpaceAfter, 0.01);

                Assert.AreEqual(0, text.Level);
                text.Level = (/*setter*/ 1);
                Assert.AreEqual(1, text.Level);
                text.Level = (/*setter*/ 4);
                Assert.AreEqual(4, text.Level);

                Assert.IsTrue(text.IsBullet());
                Assert.IsFalse(text.IsBulletAutoNumber);
                text.SetBullet(false);
                text.SetBullet(false);
                Assert.IsFalse(text.IsBullet());
                Assert.IsFalse(text.IsBulletAutoNumber);
                text.SetBullet(true);
                Assert.IsTrue(text.IsBullet());
                Assert.IsFalse(text.IsBulletAutoNumber);
                Assert.AreEqual(0, text.BulletAutoNumberStart);
                Assert.AreEqual(ListAutoNumber.ARABIC_PLAIN, text.BulletAutoNumberScheme);

                text.SetBullet(false);
                Assert.IsFalse(text.IsBullet());
                text.SetBullet(ListAutoNumber.CIRCLE_NUM_DB_PLAIN);
                Assert.IsTrue(text.IsBullet());
                Assert.IsTrue(text.IsBulletAutoNumber);
                Assert.AreEqual(0, text.BulletAutoNumberStart);
                Assert.AreEqual(ListAutoNumber.CIRCLE_NUM_DB_PLAIN, text.BulletAutoNumberScheme);
                text.SetBullet(false);
                Assert.IsFalse(text.IsBullet());
                Assert.IsFalse(text.IsBulletAutoNumber);
                text.SetBullet(ListAutoNumber.CIRCLE_NUM_WD_BLACK_PLAIN, 10);
                Assert.IsTrue(text.IsBullet());
                Assert.IsTrue(text.IsBulletAutoNumber);
                Assert.AreEqual(10, text.BulletAutoNumberStart);
                Assert.AreEqual(ListAutoNumber.CIRCLE_NUM_WD_BLACK_PLAIN, text.BulletAutoNumberScheme);


                Assert.IsNotNull(text.ToString());

                new XSSFTextParagraph(text.GetXmlObject(), shape.GetCTShape());
            }
            finally
            {
                wb.Close();
            }
        }
Esempio n. 15
0
 public int PutFont(XSSFFont font)
 {
     return PutFont(font, false);
 }
Esempio n. 16
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);
            }
        }
Esempio n. 17
0
        public void TestGetFontAt()
        {
            XSSFWorkbook workbook = new XSSFWorkbook();
            StylesTable styleSource = workbook.GetStylesSource();
            short i = 0;
            //get default font
            IFont fontAt = workbook.GetFontAt(i);
            Assert.IsNotNull(fontAt);

            //get customized font
            XSSFFont customFont = new XSSFFont();
            customFont.IsItalic = (true);
            int x = styleSource.PutFont(customFont);
            fontAt = workbook.GetFontAt((short)x);
            Assert.IsNotNull(fontAt);
        }
Esempio n. 18
0
        /**
         * Return a copy of the font in use at a particular index.
         *
         * @param index         The index.
         * @return              A copy of the  font that's currently being applied at that
         *                      index or null if no font is being applied or the
         *                      index is out of range.
         */
        public short GetFontAtIndex(int index)
        {
            if (st.sizeOfRArray() == 0) return -1;

            int pos = 0;
            for (int i = 0; i < st.sizeOfRArray(); i++)
            {
                CT_RElt r = st.GetRArray(i);
                if (index >= pos && index < pos + r.t.Length)
                {
                    XSSFFont fnt = new XSSFFont(ToCTFont(r.rPr));
                    fnt.SetThemesTable(GetThemesTable());
                    return fnt.Index;
                }

                pos += r.t.Length;
            }
            return -1;

        }
Esempio n. 19
0
 /**
  * Append new text to this text run and apply the specify font to it
  *
  * @param text  the text to append
  * @param font  the font to apply to the Appended text or <code>null</code> if no formatting is required
  */
 public void Append(String text, XSSFFont font)
 {
     if (st.sizeOfRArray() == 0 && st.IsSetT())
     {
         //convert <t>string</t> into a text Run: <r><t>string</t></r>
         CT_RElt lt = st.AddNewR();
         lt.t = st.t;
         PreserveSpaces(lt.t);
         st.unsetT();
     }
     CT_RElt lt2 = st.AddNewR();
     lt2.t= (text);
     PreserveSpaces(lt2.t);
     CT_RPrElt pr = lt2.AddNewRPr();
     if (font != null) SetRunAttributes(font.GetCTFont(), pr);
 }
Esempio n. 20
0
        public void TestScheme()
        {
            CT_Font ctFont = new CT_Font();
            CT_FontScheme scheme = ctFont.AddNewScheme();
            scheme.val = (ST_FontScheme.major);
            ctFont.SetSchemeArray(0, scheme);

            XSSFFont font = new XSSFFont(ctFont);
            Assert.AreEqual(FontScheme.MAJOR, font.GetScheme());

            font.SetScheme(FontScheme.NONE);
            Assert.AreEqual(ST_FontScheme.none, ctFont.GetSchemeArray(0).val);
        }
Esempio n. 21
0
        public void TestFamily()
        {
            CT_Font ctFont = new CT_Font();
            CT_IntProperty family = ctFont.AddNewFamily();
            family.val = (FontFamily.MODERN.Value);
            ctFont.SetFamilyArray(0, family);

            XSSFFont xssfFont = new XSSFFont(ctFont);
            Assert.AreEqual(FontFamily.MODERN.Value, xssfFont.Family);
        }
Esempio n. 22
0
        public void TestThemeColor()
        {
            CT_Font ctFont = new CT_Font();
            CT_Color color = ctFont.AddNewColor();
            color.theme = (1);
            color.themeSpecified = true;
            ctFont.SetColorArray(0, color);

            XSSFFont xssfFont = new XSSFFont(ctFont);
            Assert.AreEqual((short)ctFont.GetColorArray(0).theme, xssfFont.GetThemeColor());

            xssfFont.SetThemeColor(IndexedColors.Red.Index);
            Assert.AreEqual((uint)IndexedColors.Red.Index, ctFont.GetColorArray(0).theme);
        }
Esempio n. 23
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]);
        }
Esempio n. 24
0
        public void TestColor()
        {
            CT_Font ctFont = new CT_Font();
            CT_Color color = ctFont.AddNewColor();
            color.indexed = (uint)(XSSFFont.DEFAULT_FONT_COLOR);
            ctFont.SetColorArray(0, color);

            XSSFFont xssfFont = new XSSFFont(ctFont);
            Assert.AreEqual(IndexedColors.Black.Index, xssfFont.Color);

            xssfFont.Color = IndexedColors.Red.Index;
            Assert.AreEqual((uint)IndexedColors.Red.Index, ctFont.GetColorArray(0).indexed);
        }
Esempio n. 25
0
        public void TestConstructor()
        {
            XSSFFont xssfFont = new XSSFFont();

            Assert.IsNotNull(xssfFont.GetCTFont());
        }
Esempio n. 26
0
 /**
  * Applies a font to the specified characters of a string.
  *
  * @param startIndex    The start index to apply the font to (inclusive)
  * @param endIndex      The end index to apply the font to (exclusive)
  * @param fontIndex     The font to use.
  */
 public void ApplyFont(int startIndex, int endIndex, short fontIndex)
 {
     XSSFFont font;
     if (styles == null)
     {
         //style table is not Set, remember fontIndex and Set the run properties later,
         //when SetStylesTableReference is called
         font = new XSSFFont();
         font.FontName = ("#" + fontIndex);
     }
     else
     {
         font = styles.GetFontAt(fontIndex);
     }
     ApplyFont(startIndex, endIndex, font);
 }
Esempio n. 27
0
 /**
  * Applies the specified font to the entire string.
  *
  * @param fontIndex  the font to Apply.
  */
 public void ApplyFont(short fontIndex)
 {
     XSSFFont font;
     if (styles == null)
     {
         font = new XSSFFont();
         font.FontName = ("#" + fontIndex);
     }
     else
     {
         font = styles.GetFontAt(fontIndex);
     }
     String text = this.String;
     ApplyFont(0, text.Length, font);
 }
Esempio n. 28
0
        public void TestTypeOffset()
        {
            CT_Font ctFont = new CT_Font();
            CT_VerticalAlignFontProperty valign = ctFont.AddNewVertAlign();
            valign.val = (ST_VerticalAlignRun.baseline);
            ctFont.SetVertAlignArray(0, valign);

            XSSFFont font = new XSSFFont(ctFont);
            Assert.AreEqual(FontSuperScript.None, font.TypeOffset);

            font.TypeOffset = FontSuperScript.Super;
            Assert.AreEqual(ST_VerticalAlignRun.superscript, ctFont.GetVertAlignArray(0).val);
        }
Esempio n. 29
0
        /**
         * Gets a copy of the font used in a particular formatting Run.
         *
         * @param index     the index of the formatting run
         * @return  A copy of the  font used or null if no formatting is applied to the specified text Run.
         */
        public IFont GetFontOfFormattingRun(int index)
        {
            if (st.sizeOfRArray() == 0 || index >= st.sizeOfRArray()) return null;

            CT_RElt r = st.GetRArray(index);
            if (r.rPr != null)
            {
                XSSFFont fnt = new XSSFFont(ToCTFont(r.rPr));
                fnt.SetThemesTable(GetThemesTable());
                return fnt;
            }
            return null;
        }
Esempio n. 30
0
 public void TestConstructor()
 {
     XSSFFont xssfFont = new XSSFFont();
     Assert.IsNotNull(xssfFont.GetCTFont());
 }
Esempio n. 31
0
        public void TestGetCellStyleAt()
        {
            XSSFWorkbook workbook = new XSSFWorkbook();
            short i = 0;
            //get default style
            ICellStyle cellStyleAt = workbook.GetCellStyleAt(i);
            Assert.IsNotNull(cellStyleAt);

            //get custom style
            StylesTable styleSource = workbook.GetStylesSource();
            XSSFCellStyle customStyle = new XSSFCellStyle(styleSource);
            XSSFFont font = new XSSFFont();
            font.FontName = ("Verdana");
            customStyle.SetFont(font);
            int x = styleSource.PutStyle(customStyle);
            cellStyleAt = workbook.GetCellStyleAt((short)x);
            Assert.IsNotNull(cellStyleAt);
        }
Esempio n. 32
0
        public void TestAddNewTextParagraphWithRTS()
        {
            XSSFWorkbook wb1     = new XSSFWorkbook();
            XSSFSheet    sheet   = wb1.CreateSheet() as XSSFSheet;
            XSSFDrawing  Drawing = sheet.CreateDrawingPatriarch() as XSSFDrawing;

            XSSFTextBox        shape = Drawing.CreateTextbox(new XSSFClientAnchor(0, 0, 0, 0, 2, 2, 3, 4));
            XSSFRichTextString rt    = new XSSFRichTextString("Test Rich Text String");

            XSSFFont font = wb1.CreateFont() as XSSFFont;

            font.SetColor(new XSSFColor(Color.FromArgb(0, 255, 255)));
            font.FontName = ("Arial");
            rt.ApplyFont(font);

            XSSFFont midfont = wb1.CreateFont() as XSSFFont;

            midfont.SetColor(new XSSFColor(Color.FromArgb(0, 255, 0)));
            rt.ApplyFont(5, 14, midfont);       // Set the text "Rich Text" to be green and the default font

            XSSFTextParagraph para = shape.AddNewTextParagraph(rt);

            // Save and re-load it
            XSSFWorkbook wb2 = XSSFTestDataSamples.WriteOutAndReadBack(wb1) as XSSFWorkbook;

            wb1.Close();
            sheet = wb2.GetSheetAt(0) as XSSFSheet;

            // Check
            Drawing = sheet.CreateDrawingPatriarch() as XSSFDrawing;

            List <XSSFShape> shapes = Drawing.GetShapes();

            Assert.AreEqual(1, shapes.Count);
            Assert.IsTrue(shapes[0] is XSSFSimpleShape);

            XSSFSimpleShape sshape = (XSSFSimpleShape)shapes[0];

            List <XSSFTextParagraph> paras = sshape.TextParagraphs;

            Assert.AreEqual(2, paras.Count);    // this should be 2 as XSSFSimpleShape Creates a default paragraph (no text), and then we add a string to that.

            List <XSSFTextRun> runs = para.TextRuns;

            Assert.AreEqual(3, runs.Count);

            // first run properties
            Assert.AreEqual("Test ", runs[0].Text);
            Assert.AreEqual("Arial", runs[0].FontFamily);

            Color clr = runs[0].FontColor;

            Assert.IsTrue(Arrays.Equals(
                              new int[] { 0, 255, 255 },
                              new int[] { clr.R, clr.G, clr.B }));

            // second run properties
            Assert.AreEqual("Rich Text", runs[1].Text);
            Assert.AreEqual(XSSFFont.DEFAULT_FONT_NAME, runs[1].FontFamily);

            clr = runs[1].FontColor;
            Assert.IsTrue(Arrays.Equals(
                              new int[] { 0, 255, 0 },
                              new int[] { clr.R, clr.G, clr.B }));

            // third run properties
            Assert.AreEqual(" String", runs[2].Text);
            Assert.AreEqual("Arial", runs[2].FontFamily);
            clr = runs[2].FontColor;
            Assert.IsTrue(Arrays.Equals(
                              new int[] { 0, 255, 255 },
                              new int[] { clr.R, clr.G, clr.B }));

            checkRewrite(wb2);
            wb2.Close();
        }
Esempio n. 33
0
        public void TestCloneStyleDiffWB()
        {
            XSSFWorkbook wbOrig = new XSSFWorkbook();

            Assert.AreEqual(1, wbOrig.NumberOfFonts);
            Assert.AreEqual(0, wbOrig.GetStylesSource().GetNumberFormats().Count);

            XSSFFont fnt = (XSSFFont)wbOrig.CreateFont();

            fnt.FontName = ("TestingFont");
            Assert.AreEqual(2, wbOrig.NumberOfFonts);
            Assert.AreEqual(0, wbOrig.GetStylesSource().GetNumberFormats().Count);

            XSSFDataFormat fmt = (XSSFDataFormat)wbOrig.CreateDataFormat();

            fmt.GetFormat("MadeUpOne");
            fmt.GetFormat("MadeUpTwo");

            XSSFCellStyle orig = (XSSFCellStyle)wbOrig.CreateCellStyle();

            orig.Alignment = (HorizontalAlignment.Right);
            orig.SetFont(fnt);
            orig.DataFormat = (fmt.GetFormat("Test##"));

            Assert.IsTrue(HorizontalAlignment.Right == orig.Alignment);
            Assert.IsTrue(fnt == orig.GetFont());
            Assert.IsTrue(fmt.GetFormat("Test##") == orig.DataFormat);

            Assert.AreEqual(2, wbOrig.NumberOfFonts);
            Assert.AreEqual(3, wbOrig.GetStylesSource().GetNumberFormats().Count);


            // Now a style on another workbook
            XSSFWorkbook wbClone = new XSSFWorkbook();

            Assert.AreEqual(1, wbClone.NumberOfFonts);
            Assert.AreEqual(0, wbClone.GetStylesSource().GetNumberFormats().Count);
            Assert.AreEqual(1, wbClone.NumCellStyles);

            XSSFDataFormat fmtClone = (XSSFDataFormat)wbClone.CreateDataFormat();
            XSSFCellStyle  clone    = (XSSFCellStyle)wbClone.CreateCellStyle();

            Assert.AreEqual(1, wbClone.NumberOfFonts);
            Assert.AreEqual(0, wbClone.GetStylesSource().GetNumberFormats().Count);

            Assert.IsFalse(HorizontalAlignment.Right == clone.Alignment);
            Assert.IsFalse("TestingFont" == clone.GetFont().FontName);

            clone.CloneStyleFrom(orig);

            Assert.AreEqual(2, wbClone.NumberOfFonts);
            Assert.AreEqual(2, wbClone.NumCellStyles);
            Assert.AreEqual(1, wbClone.GetStylesSource().GetNumberFormats().Count);

            Assert.AreEqual(HorizontalAlignment.Right, clone.Alignment);
            Assert.AreEqual("TestingFont", clone.GetFont().FontName);
            Assert.AreEqual(fmtClone.GetFormat("Test##"), clone.DataFormat);
            Assert.IsFalse(fmtClone.GetFormat("Test##") == fmt.GetFormat("Test##"));

            // Save it and re-check
            XSSFWorkbook wbReload = (XSSFWorkbook)XSSFTestDataSamples.WriteOutAndReadBack(wbClone);

            Assert.AreEqual(2, wbReload.NumberOfFonts);
            Assert.AreEqual(2, wbReload.NumCellStyles);
            Assert.AreEqual(1, wbReload.GetStylesSource().GetNumberFormats().Count);

            XSSFCellStyle reload = (XSSFCellStyle)wbReload.GetCellStyleAt((short)1);

            Assert.AreEqual(HorizontalAlignment.Right, reload.Alignment);
            Assert.AreEqual("TestingFont", reload.GetFont().FontName);
            Assert.AreEqual(fmtClone.GetFormat("Test##"), reload.DataFormat);
            Assert.IsFalse(fmtClone.GetFormat("Test##") == fmt.GetFormat("Test##"));

            Assert.IsNotNull(XSSFTestDataSamples.WriteOutAndReadBack(wbOrig));
            Assert.IsNotNull(XSSFTestDataSamples.WriteOutAndReadBack(wbClone));
        }
Esempio n. 34
0
        public void TestXSSFTextParagraph()
        {
            XSSFWorkbook wb = new XSSFWorkbook();

            try
            {
                XSSFSheet   sheet   = wb.CreateSheet() as XSSFSheet;
                XSSFDrawing Drawing = sheet.CreateDrawingPatriarch() as XSSFDrawing;

                XSSFTextBox shape = Drawing.CreateTextbox(new XSSFClientAnchor(0, 0, 0, 0, 2, 2, 3, 4)) as XSSFTextBox;

                XSSFRichTextString rt = new XSSFRichTextString("Test String");

                XSSFFont font  = wb.CreateFont() as XSSFFont;
                Color    color = Color.FromArgb(0, 255, 255);
                font.SetColor(new XSSFColor(color));
                font.FontName = (/*setter*/ "Arial");
                rt.ApplyFont(font);

                shape.SetText(/*setter*/ rt);

                Assert.IsNotNull(shape.GetCTShape());
                Assert.IsNotNull(shape.GetEnumerator());
                Assert.IsNotNull(XSSFSimpleShape.GetPrototype());

                foreach (ListAutoNumber nr in Enum.GetValues(typeof(ListAutoNumber)))
                {
                    shape.TextParagraphs[(0)].SetBullet(nr);
                    Assert.IsNotNull(shape.Text);
                }

                shape.TextParagraphs[(0)].SetBullet(false);
                Assert.IsNotNull(shape.Text);

                shape.SetText("testtext");
                Assert.AreEqual("testtext", shape.Text);

                shape.SetText(new XSSFRichTextString());
                Assert.AreEqual("null", shape.Text);

                shape.AddNewTextParagraph();
                shape.AddNewTextParagraph("test-other-text");
                shape.AddNewTextParagraph(new XSSFRichTextString("rtstring"));
                shape.AddNewTextParagraph(new XSSFRichTextString());
                Assert.AreEqual("null\n\ntest-other-text\nrtstring\nnull", shape.Text);

                Assert.AreEqual(TextHorizontalOverflow.OVERFLOW, shape.TextHorizontalOverflow);
                shape.TextHorizontalOverflow = (/*setter*/ TextHorizontalOverflow.CLIP);
                Assert.AreEqual(TextHorizontalOverflow.CLIP, shape.TextHorizontalOverflow);
                shape.TextHorizontalOverflow = (/*setter*/ TextHorizontalOverflow.OVERFLOW);
                Assert.AreEqual(TextHorizontalOverflow.OVERFLOW, shape.TextHorizontalOverflow);
                shape.TextHorizontalOverflow = TextHorizontalOverflow.None;
                Assert.AreEqual(TextHorizontalOverflow.OVERFLOW, shape.TextHorizontalOverflow);
                shape.TextHorizontalOverflow = TextHorizontalOverflow.None;
                Assert.AreEqual(TextHorizontalOverflow.OVERFLOW, shape.TextHorizontalOverflow);

                Assert.AreEqual(TextVerticalOverflow.OVERFLOW, shape.TextVerticalOverflow);
                shape.TextVerticalOverflow = (/*setter*/ TextVerticalOverflow.CLIP);
                Assert.AreEqual(TextVerticalOverflow.CLIP, shape.TextVerticalOverflow);
                shape.TextVerticalOverflow = (/*setter*/ TextVerticalOverflow.OVERFLOW);
                Assert.AreEqual(TextVerticalOverflow.OVERFLOW, shape.TextVerticalOverflow);
                shape.TextVerticalOverflow = TextVerticalOverflow.None;
                Assert.AreEqual(TextVerticalOverflow.OVERFLOW, shape.TextVerticalOverflow);
                shape.TextVerticalOverflow = TextVerticalOverflow.None;
                Assert.AreEqual(TextVerticalOverflow.OVERFLOW, shape.TextVerticalOverflow);

                Assert.AreEqual((short)VerticalAlignment.Top, shape.VerticalAlignment);
                shape.VerticalAlignment = (short)VerticalAlignment.Bottom;
                Assert.AreEqual(VerticalAlignment.Bottom, shape.VerticalAlignment);
                shape.VerticalAlignment = (short)VerticalAlignment.Top;
                Assert.AreEqual(VerticalAlignment.Top, shape.VerticalAlignment);
                shape.VerticalAlignment = (short)VerticalAlignment.None;
                Assert.AreEqual(VerticalAlignment.Top, shape.VerticalAlignment);
                shape.VerticalAlignment = (short)VerticalAlignment.None;
                Assert.AreEqual(VerticalAlignment.Top, shape.VerticalAlignment);

                Assert.AreEqual(TextDirection.HORIZONTAL, shape.TextDirection);
                shape.TextDirection = (/*setter*/ TextDirection.STACKED);
                Assert.AreEqual(TextDirection.STACKED, shape.TextDirection);
                shape.TextDirection = (/*setter*/ TextDirection.HORIZONTAL);
                Assert.AreEqual(TextDirection.HORIZONTAL, shape.TextDirection);
                shape.TextDirection = (/*setter*/ TextDirection.None);
                Assert.AreEqual(TextDirection.HORIZONTAL, shape.TextDirection);
                shape.TextDirection = (/*setter*/ TextDirection.None);
                Assert.AreEqual(TextDirection.HORIZONTAL, shape.TextDirection);

                Assert.AreEqual(3.6, shape.BottomInset, 0.01);
                shape.BottomInset = (/*setter*/ 12.32);
                Assert.AreEqual(12.32, shape.BottomInset, 0.01);
                shape.BottomInset = (/*setter*/ -1);
                Assert.AreEqual(3.6, shape.BottomInset, 0.01);
                shape.BottomInset = (/*setter*/ -1);
                Assert.AreEqual(3.6, shape.BottomInset, 0.01);

                Assert.AreEqual(3.6, shape.LeftInset, 0.01);
                shape.LeftInset = (/*setter*/ 12.31);
                Assert.AreEqual(12.31, shape.LeftInset, 0.01);
                shape.LeftInset = (/*setter*/ -1);
                Assert.AreEqual(3.6, shape.LeftInset, 0.01);
                shape.LeftInset = (/*setter*/ -1);
                Assert.AreEqual(3.6, shape.LeftInset, 0.01);

                Assert.AreEqual(3.6, shape.RightInset, 0.01);
                shape.RightInset = (/*setter*/ 13.31);
                Assert.AreEqual(13.31, shape.RightInset, 0.01);
                shape.RightInset = (/*setter*/ -1);
                Assert.AreEqual(3.6, shape.RightInset, 0.01);
                shape.RightInset = (/*setter*/ -1);
                Assert.AreEqual(3.6, shape.RightInset, 0.01);

                Assert.AreEqual(3.6, shape.TopInset, 0.01);
                shape.TopInset = (/*setter*/ 23.31);
                Assert.AreEqual(23.31, shape.TopInset, 0.01);
                shape.TopInset = (/*setter*/ -1);
                Assert.AreEqual(3.6, shape.TopInset, 0.01);
                shape.TopInset = (/*setter*/ -1);
                Assert.AreEqual(3.6, shape.TopInset, 0.01);

                Assert.IsTrue(shape.WordWrap);
                shape.WordWrap = (/*setter*/ false);
                Assert.IsFalse(shape.WordWrap);
                shape.WordWrap = (/*setter*/ true);
                Assert.IsTrue(shape.WordWrap);

                Assert.AreEqual(TextAutofit.NORMAL, shape.TextAutofit);
                shape.TextAutofit = (/*setter*/ TextAutofit.NORMAL);
                Assert.AreEqual(TextAutofit.NORMAL, shape.TextAutofit);
                shape.TextAutofit = (/*setter*/ TextAutofit.SHAPE);
                Assert.AreEqual(TextAutofit.SHAPE, shape.TextAutofit);
                shape.TextAutofit = (/*setter*/ TextAutofit.NONE);
                Assert.AreEqual(TextAutofit.NONE, shape.TextAutofit);

                Assert.AreEqual(5, shape.ShapeType);
                shape.ShapeType = (/*setter*/ 23);
                Assert.AreEqual(23, shape.ShapeType);

                // TODO: should this be supported?
                //            shape.ShapeType=(/*setter*/-1);
                //            Assert.AreEqual(-1, shape.ShapeType);
                //            shape.ShapeType=(/*setter*/-1);
                //            Assert.AreEqual(-1, shape.ShapeType);

                Assert.IsNotNull(shape.GetShapeProperties());
            }
            finally
            {
                wb.Close();
            }
        }
Esempio n. 35
0
        /**
         * Records the given font in the font table.
         * Will re-use an existing font index if this
         *  font matches another, EXCEPT if forced
         *  registration is requested.
         * This allows people to create several fonts
         *  then customise them later.
         * Note - End Users probably want to call
         *  {@link XSSFFont#registerTo(StylesTable)}
         */
        public int PutFont(XSSFFont font, bool forceRegistration)
        {
            int idx = -1;
            if (!forceRegistration)
            {
                idx = fonts.IndexOf(font);
            }

            if (idx != -1)
            {
                return idx;
            }

            idx = fonts.Count;
            fonts.Add(font);
            return idx;
        }
Esempio n. 36
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");
            }
        }
Esempio n. 37
0
 private static XSSFFont CreateDefaultFont()
 {
     CT_Font ctFont = new CT_Font();
     XSSFFont xssfFont = new XSSFFont(ctFont, 0);
     xssfFont.FontHeightInPoints = (XSSFFont.DEFAULT_FONT_SIZE);
     xssfFont.Color = (XSSFFont.DEFAULT_FONT_COLOR);//SetTheme
     xssfFont.FontName = (XSSFFont.DEFAULT_FONT_NAME);
     xssfFont.SetFamily(FontFamily.SWISS);
     xssfFont.SetScheme(FontScheme.MINOR);
     return xssfFont;
 }
Esempio n. 38
0
        public void TestGetFonts()
        {

            XSSFRichTextString rt = new XSSFRichTextString();

            XSSFFont font1 = new XSSFFont();
            font1.FontName = ("Arial");
            font1.IsItalic = (true);
            rt.Append("The quick", font1);

            XSSFFont font1FR = (XSSFFont)rt.GetFontOfFormattingRun(0);
            Assert.AreEqual(font1.IsItalic, font1FR.IsItalic);
            Assert.AreEqual(font1.FontName, font1FR.FontName);

            XSSFFont font2 = new XSSFFont();
            font2.FontName = ("Courier");
            font2.IsBold = (true);
            rt.Append(" brown fox", font2);

            XSSFFont font2FR = (XSSFFont)rt.GetFontOfFormattingRun(1);
            Assert.AreEqual(font2.IsBold, font2FR.IsBold);
            Assert.AreEqual(font2.FontName, font2FR.FontName);
        }
Esempio n. 39
0
 /// <summary>
 /// Create a new Font and add it to the workbook's font table
 /// </summary>
 /// <returns></returns>
 public IFont CreateFont()
 {
     XSSFFont font = new XSSFFont();
     font.RegisterTo(stylesSource);
     return font;
 }
Esempio n. 40
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");
            }
        }
Esempio n. 41
0
 /**
 * Gets the font for this style
 * @return Font - font
 */
 public XSSFFont GetFont()
 {
     if (_font == null)
     {
         _font = _stylesSource.GetFontAt(GetFontId());
     }
     return _font;
 }
Esempio n. 42
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");
            }
        }
Esempio n. 43
0
        public void TestApplyFont_usermodel()
        {
            String text = "Apache Software Foundation";
            XSSFRichTextString str = new XSSFRichTextString(text);
            XSSFFont font1 = new XSSFFont();
            XSSFFont font2 = new XSSFFont();
            XSSFFont font3 = new XSSFFont();
            str.ApplyFont(font1);
            Assert.AreEqual(1, str.NumFormattingRuns);

            str.ApplyFont(0, 6, font1);
            str.ApplyFont(6, text.Length, font2);
            Assert.AreEqual(2, str.NumFormattingRuns);
            Assert.AreEqual("Apache", str.GetCTRst().GetRArray(0).t);
            Assert.AreEqual(" Software Foundation", str.GetCTRst().GetRArray(1).t);

            str.ApplyFont(15, 26, font3);
            Assert.AreEqual(3, str.NumFormattingRuns);
            Assert.AreEqual("Apache", str.GetCTRst().GetRArray(0).t);
            Assert.AreEqual(" Software", str.GetCTRst().GetRArray(1).t);
            Assert.AreEqual(" Foundation", str.GetCTRst().GetRArray(2).t);

            str.ApplyFont(6, text.Length, font2);
            Assert.AreEqual(2, str.NumFormattingRuns);
            Assert.AreEqual("Apache", str.GetCTRst().GetRArray(0).t);
            Assert.AreEqual(" Software Foundation", str.GetCTRst().GetRArray(1).t);
        }
Esempio n. 44
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);
        }
Esempio n. 45
0
        public void TestClearFormatting()
        {

            XSSFRichTextString rt = new XSSFRichTextString("Apache POI");
            Assert.AreEqual("Apache POI", rt.String);

            rt.ClearFormatting();

            CT_Rst st = rt.GetCTRst();
            Assert.IsTrue(st.IsSetT());
            Assert.AreEqual("Apache POI", rt.String);
            Assert.AreEqual(0, rt.NumFormattingRuns);

            XSSFFont font = new XSSFFont();
            font.IsBold = true;

            rt.ApplyFont(7, 10, font);
            Assert.AreEqual(2, rt.NumFormattingRuns);
            rt.ClearFormatting();
            Assert.AreEqual("Apache POI", rt.String);
            Assert.AreEqual(0, rt.NumFormattingRuns);
        }
Esempio n. 46
0
        /**
         * Gets a copy of the font used in a particular formatting Run.
         *
         * @param index     the index of the formatting run
         * @return  A copy of the  font used or null if no formatting is applied to the specified text Run.
         */
        public IFont GetFontOfFormattingRun(int index)
        {
            if (st.sizeOfRArray() == 0) return null;

            for (int i = 0; i < st.sizeOfRArray(); i++)
            {
                CT_RElt r = st.GetRArray(i);
                if (i == index)
                {
                    XSSFFont fnt = new XSSFFont(ToCTFont(r.rPr));
                    fnt.SetThemesTable(GetThemesTable());
                    return fnt;
                }
            }
            return null;
        }