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


C# XSSFWorkbook.GetCellStyleAt方法代码示例

本文整理汇总了C#中NPOI.XSSF.UserModel.XSSFWorkbook.GetCellStyleAt方法的典型用法代码示例。如果您正苦于以下问题:C# XSSFWorkbook.GetCellStyleAt方法的具体用法?C# XSSFWorkbook.GetCellStyleAt怎么用?C# XSSFWorkbook.GetCellStyleAt使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在NPOI.XSSF.UserModel.XSSFWorkbook的用法示例。


在下文中一共展示了XSSFWorkbook.GetCellStyleAt方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TestGetFillForegroundColor

        public void TestGetFillForegroundColor()
        {

            XSSFWorkbook wb = new XSSFWorkbook();
            StylesTable styles = wb.GetStylesSource();
            Assert.AreEqual(1, wb.NumCellStyles);
            Assert.AreEqual(2, styles.GetFills().Count);

            XSSFCellStyle defaultStyle = (XSSFCellStyle)wb.GetCellStyleAt((short)0);
            Assert.AreEqual(IndexedColors.Automatic.Index, defaultStyle.FillForegroundColor);
            Assert.AreEqual(null, defaultStyle.FillForegroundColorColor);
            Assert.AreEqual(FillPattern.NoFill, defaultStyle.FillPattern);

            XSSFCellStyle customStyle = (XSSFCellStyle)wb.CreateCellStyle();

            customStyle.FillPattern = (FillPattern.SolidForeground);
            Assert.AreEqual(FillPattern.SolidForeground, customStyle.FillPattern);
            Assert.AreEqual(3, styles.GetFills().Count);

            customStyle.FillForegroundColor = (IndexedColors.BrightGreen.Index);
            Assert.AreEqual(IndexedColors.BrightGreen.Index, customStyle.FillForegroundColor);
            Assert.AreEqual(4, styles.GetFills().Count);

            for (int i = 0; i < 3; i++)
            {
                XSSFCellStyle style = (XSSFCellStyle)wb.CreateCellStyle();

                style.FillPattern = (FillPattern.SolidForeground);
                Assert.AreEqual(FillPattern.SolidForeground, style.FillPattern);
                Assert.AreEqual(4, styles.GetFills().Count);

                style.FillForegroundColor = (IndexedColors.BrightGreen.Index);
                Assert.AreEqual(IndexedColors.BrightGreen.Index, style.FillForegroundColor);
                Assert.AreEqual(4, styles.GetFills().Count);
            }

            Assert.IsNotNull(XSSFTestDataSamples.WriteOutAndReadBack(wb));
        }
开发者ID:eatage,项目名称:npoi,代码行数:38,代码来源:TestXSSFCellStyle.cs

示例2: TestBug49702

        public void TestBug49702()
        {
            // First try with a new file
            XSSFWorkbook wb = new XSSFWorkbook();

            // Should have one style
            Assert.AreEqual(1, wb.NumCellStyles);
            wb.GetCellStyleAt((short)0);
            try
            {
                wb.GetCellStyleAt((short)1);
                Assert.Fail("Shouldn't be able to get style at 1 that doesn't exist");
            }
            catch (ArgumentOutOfRangeException) { }

            // Add another one
            ICellStyle cs = wb.CreateCellStyle();
            cs.DataFormat = ((short)11);

            // Re-check
            Assert.AreEqual(2, wb.NumCellStyles);
            wb.GetCellStyleAt((short)0);
            wb.GetCellStyleAt((short)1);
            try
            {
                wb.GetCellStyleAt((short)2);
                Assert.Fail("Shouldn't be able to get style at 2 that doesn't exist");
            }
            catch (ArgumentOutOfRangeException) { }

            // Save and reload
            XSSFWorkbook nwb = (XSSFWorkbook)XSSFTestDataSamples.WriteOutAndReadBack(wb);
            Assert.AreEqual(2, nwb.NumCellStyles);
            nwb.GetCellStyleAt((short)0);
            nwb.GetCellStyleAt((short)1);
            try
            {
                nwb.GetCellStyleAt((short)2);
                Assert.Fail("Shouldn't be able to Get style at 2 that doesn't exist");
            }
            catch (ArgumentOutOfRangeException) { }

            // Now with an existing file
            wb = XSSFTestDataSamples.OpenSampleWorkbook("sample.xlsx");
            Assert.AreEqual(3, wb.NumCellStyles);
            wb.GetCellStyleAt((short)0);
            wb.GetCellStyleAt((short)1);
            wb.GetCellStyleAt((short)2);
            try
            {
                wb.GetCellStyleAt((short)3);
                Assert.Fail("Shouldn't be able to Get style at 3 that doesn't exist");
            }
            catch (ArgumentOutOfRangeException) { }
        }
开发者ID:kahinke,项目名称:npoi,代码行数:55,代码来源:TestXSSFWorkbook.cs

示例3: 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

示例4: TestGetFillForegroundColor

        public void TestGetFillForegroundColor()
        {

            XSSFWorkbook wb = new XSSFWorkbook();
            StylesTable styles = wb.GetStylesSource();
            Assert.AreEqual(1, wb.NumCellStyles);
            Assert.AreEqual(2, styles.GetFills().Count);

            XSSFCellStyle defaultStyle = (XSSFCellStyle)wb.GetCellStyleAt((short)0);
            Assert.AreEqual(IndexedColors.AUTOMATIC.Index, defaultStyle.FillForegroundColor);
            Assert.AreEqual(null, defaultStyle.FillForegroundColorColor);
            Assert.AreEqual(FillPatternType.NO_FILL, defaultStyle.FillPattern);

            XSSFCellStyle customStyle = (XSSFCellStyle)wb.CreateCellStyle();

            customStyle.FillPattern = (FillPatternType.SOLID_FOREGROUND);
            Assert.AreEqual(FillPatternType.SOLID_FOREGROUND, customStyle.FillPattern);
            Assert.AreEqual(3, styles.GetFills().Count);

            customStyle.FillForegroundColor = (IndexedColors.BRIGHT_GREEN.Index);
            Assert.AreEqual(IndexedColors.BRIGHT_GREEN.Index, customStyle.FillForegroundColor);
            Assert.AreEqual(4, styles.GetFills().Count);

            for (int i = 0; i < 3; i++)
            {
                XSSFCellStyle style = (XSSFCellStyle)wb.CreateCellStyle();

                style.FillPattern = (FillPatternType.SOLID_FOREGROUND);
                Assert.AreEqual(FillPatternType.SOLID_FOREGROUND, style.FillPattern);
                Assert.AreEqual(4, styles.GetFills().Count);

                style.FillForegroundColor = (IndexedColors.BRIGHT_GREEN.Index);
                Assert.AreEqual(IndexedColors.BRIGHT_GREEN.Index, style.FillForegroundColor);
                Assert.AreEqual(4, styles.GetFills().Count);
            }
        }
开发者ID:xoposhiy,项目名称:npoi,代码行数:36,代码来源:TestXSSFCellStyle.cs

示例5: Test51037

        public void Test51037()
        {
            XSSFWorkbook wb = new XSSFWorkbook();
            XSSFSheet s = wb.CreateSheet() as XSSFSheet;

            ICellStyle defaultStyle = wb.GetCellStyleAt((short)0);
            Assert.AreEqual(0, defaultStyle.Index);

            ICellStyle blueStyle = wb.CreateCellStyle();
            blueStyle.FillForegroundColor=(IndexedColors.AQUA.Index);
            blueStyle.FillPattern=(FillPatternType.SOLID_FOREGROUND);
            Assert.AreEqual(1, blueStyle.Index);

            ICellStyle pinkStyle = wb.CreateCellStyle();
            pinkStyle.FillForegroundColor=(IndexedColors.PINK.Index);
            pinkStyle.FillPattern=(FillPatternType.SOLID_FOREGROUND);
            Assert.AreEqual(2, pinkStyle.Index);

            // Starts empty
            Assert.AreEqual(1, s.GetCTWorksheet().sizeOfColsArray());
            CT_Cols cols = s.GetCTWorksheet().GetColsArray(0);
            Assert.AreEqual(0, cols.sizeOfColArray());

            // Add some rows and columns
            XSSFRow r1 = s.CreateRow(0) as XSSFRow;
            XSSFRow r2 = s.CreateRow(1) as XSSFRow;
            r1.CreateCell(0);
            r1.CreateCell(2);
            r2.CreateCell(0);
            r2.CreateCell(3);

            // Check no style is there
            Assert.AreEqual(1, s.GetCTWorksheet().sizeOfColsArray());
            Assert.AreEqual(0, cols.sizeOfColArray());

            Assert.AreEqual(defaultStyle, s.GetColumnStyle(0));
            Assert.AreEqual(defaultStyle, s.GetColumnStyle(2));
            Assert.AreEqual(defaultStyle, s.GetColumnStyle(3));


            // Apply the styles
            s.SetDefaultColumnStyle(0, pinkStyle);
            s.SetDefaultColumnStyle(3, blueStyle);

            // Check
            Assert.AreEqual(pinkStyle, s.GetColumnStyle(0));
            Assert.AreEqual(defaultStyle, s.GetColumnStyle(2));
            Assert.AreEqual(blueStyle, s.GetColumnStyle(3));

            Assert.AreEqual(1, s.GetCTWorksheet().sizeOfColsArray());
            Assert.AreEqual(2, cols.sizeOfColArray());

            Assert.AreEqual(1, cols.GetColArray(0).min);
            Assert.AreEqual(1, cols.GetColArray(0).max);
            Assert.AreEqual(pinkStyle.Index, cols.GetColArray(0).style);

            Assert.AreEqual(4, cols.GetColArray(1).min);
            Assert.AreEqual(4, cols.GetColArray(1).max);
            Assert.AreEqual(blueStyle.Index, cols.GetColArray(1).style);


            // Save, re-load and re-check 
            wb = XSSFTestDataSamples.WriteOutAndReadBack(wb) as XSSFWorkbook;
            s = wb.GetSheetAt(0) as XSSFSheet;
            defaultStyle = wb.GetCellStyleAt(defaultStyle.Index);
            blueStyle = wb.GetCellStyleAt(blueStyle.Index);
            pinkStyle = wb.GetCellStyleAt(pinkStyle.Index);

            Assert.AreEqual(pinkStyle, s.GetColumnStyle(0));
            Assert.AreEqual(defaultStyle, s.GetColumnStyle(2));
            Assert.AreEqual(blueStyle, s.GetColumnStyle(3));
        }
开发者ID:WPG,项目名称:npoi,代码行数:72,代码来源:TestXSSFBugs.cs

示例6: Bug57880

        public void Bug57880()
        {
            Console.WriteLine("long time test, run over 1 minute.");
            int numStyles = 33000;
            XSSFWorkbook wb = new XSSFWorkbook();
            XSSFSheet s = wb.CreateSheet("TestSheet") as XSSFSheet;
            XSSFDataFormat fmt = wb.GetCreationHelper().CreateDataFormat() as XSSFDataFormat;
            for (int i = 1; i < numStyles; i++)
            {
                short df = fmt.GetFormat("test" + i);
                // Format indexes will be wrapped beyond 32,676
                Assert.AreEqual(164 + i, df & 0xffff);
                // Create a style and use it
                XSSFCellStyle style = wb.CreateCellStyle() as XSSFCellStyle;
                Assert.AreEqual(i, style.UIndex);
                style.DataFormat = (/*setter*/df);
                XSSFCell c = s.CreateRow(i).CreateCell(0, CellType.Numeric) as XSSFCell;
                c.CellStyle = (/*setter*/style);
                c.SetCellValue(i);
            }

            //wb = XSSFTestDataSamples.WriteOutAndReadBack(wb) as XSSFWorkbook;
            // using temp file instead of ByteArrayOutputStream because of OOM in gump run
            FileInfo tmp = TempFile.CreateTempFile("poi-test", ".bug57880");
            FileStream fos = new FileStream(tmp.FullName, FileMode.Create, FileAccess.ReadWrite);
            wb.Write(fos);
            fos.Close();

            wb.Close();
            fmt = null; s = null; wb = null;
            // System.gc();

            wb = new XSSFWorkbook(tmp.FullName);
            fmt = wb.GetCreationHelper().CreateDataFormat() as XSSFDataFormat;
            s = wb.GetSheetAt(0) as XSSFSheet;
            for (int i = 1; i < numStyles; i++)
            {
                XSSFCellStyle style = wb.GetCellStyleAt((short)i) as XSSFCellStyle;
                Assert.IsNotNull(style);
                Assert.AreEqual(i, style.UIndex);
                Assert.AreEqual(164 + i, style.DataFormat & 0xffff);
                Assert.AreEqual("test" + i, style.GetDataFormatString());
            }

            wb.Close();
            tmp.Delete();
        }
开发者ID:runningwater,项目名称:npoi,代码行数:47,代码来源:TestXSSFBugs.cs


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