当前位置: 首页>>代码示例>>C#>>正文


C# UserModel.XSSFFont类代码示例

本文整理汇总了C#中NPOI.XSSF.UserModel.XSSFFont的典型用法代码示例。如果您正苦于以下问题:C# XSSFFont类的具体用法?C# XSSFFont怎么用?C# XSSFFont使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


XSSFFont类属于NPOI.XSSF.UserModel命名空间,在下文中一共展示了XSSFFont类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TestApplyFont

        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);
        }
开发者ID:twxstar,项目名称:npoi,代码行数:30,代码来源:TestXSSFRichTextString.cs

示例2: TestBoldweight

        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);
        }
开发者ID:89sos98,项目名称:npoi,代码行数:13,代码来源:TestXSSFFont.cs

示例3: TestCharSet

        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
            );
        }
开发者ID:89sos98,项目名称:npoi,代码行数:45,代码来源:TestXSSFFont.cs

示例4: SetUp

        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);
        }
开发者ID:age-soft,项目名称:npoi,代码行数:42,代码来源:TestXSSFCellStyle.cs

示例5: TestGetCellStyleAt

        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);
        }
开发者ID:kahinke,项目名称:npoi,代码行数:18,代码来源:TestXSSFWorkbook.cs

示例6: TestColor

        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);
        }
开发者ID:89sos98,项目名称:npoi,代码行数:13,代码来源:TestXSSFFont.cs

示例7: GetFontAtIndex

        /**
         * 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;

        }
开发者ID:twxstar,项目名称:npoi,代码行数:28,代码来源:XSSFRichTextString.cs

示例8: TestGetFonts

        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);
        }
开发者ID:twxstar,项目名称:npoi,代码行数:23,代码来源:TestXSSFRichTextString.cs

示例9: TestRgbColor

        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]);
        }
开发者ID:89sos98,项目名称:npoi,代码行数:21,代码来源:TestXSSFFont.cs

示例10: CreateDefaultFont

 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;
 }
开发者ID:eatage,项目名称:npoi,代码行数:11,代码来源:StylesTable.cs

示例11: CloneStyleFrom

        /**
         * 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");
            }
        }
开发者ID:qljiong,项目名称:npoi,代码行数:80,代码来源:XSSFCellStyle.cs

示例12: TestGetFontAt

        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);
        }
开发者ID:kahinke,项目名称:npoi,代码行数:16,代码来源:TestXSSFWorkbook.cs

示例13: PutFont

        /**
         * 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;
        }
开发者ID:eatage,项目名称:npoi,代码行数:27,代码来源:StylesTable.cs

示例14: TestThemeColor

        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);
        }
开发者ID:89sos98,项目名称:npoi,代码行数:14,代码来源:TestXSSFFont.cs

示例15: TestConstructor

 public void TestConstructor()
 {
     XSSFFont xssfFont = new XSSFFont();
     Assert.IsNotNull(xssfFont.GetCTFont());
 }
开发者ID:89sos98,项目名称:npoi,代码行数:5,代码来源:TestXSSFFont.cs


注:本文中的NPOI.XSSF.UserModel.XSSFFont类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。