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


C# HSSFWorkbook.GetName方法代码示例

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


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

示例1: TestNames

        public void TestNames()
        {
            HSSFWorkbook wb = new HSSFWorkbook();

            try
            {
                wb.GetNameAt(0);
                Assert.Fail("Fails without any defined names");
            }
            catch (ArgumentException e)
            {
                //Assert.IsTrue(e.Message.Contains("no defined names"), e.Message);
            }

            HSSFName name = (HSSFName)wb.CreateName();
            Assert.IsNotNull(name);

            Assert.IsNull(wb.GetName("somename"));

            name.NameName = ("myname");
            Assert.IsNotNull(wb.GetName("myname"));

            Assert.AreEqual(0, wb.GetNameIndex(name));
            Assert.AreEqual(0, wb.GetNameIndex("myname"));

            try
            {
                wb.GetNameAt(5);
                Assert.Fail("Fails without any defined names");
            }
            catch (ArgumentException e)
            {
                //Assert.IsTrue(e.Message.Contains("outside the allowable range"), e.Message);
            }

            try
            {
                wb.GetNameAt(-3);
                Assert.Fail("Fails without any defined names");
            }
            catch (ArgumentException e)
            {
                //Assert.IsTrue(e.Message.Contains("outside the allowable range"), e.Message);
            }
        }
开发者ID:mdjasim,项目名称:npoi,代码行数:45,代码来源:TestHSSFWorkbook.cs

示例2: Test46664

        public void Test46664()
        {
            HSSFWorkbook wb = new HSSFWorkbook();
            ISheet sheet = wb.CreateSheet("new_sheet");
            IRow row = sheet.CreateRow((short)0);
            row.CreateCell(0).SetCellValue(new HSSFRichTextString("Column A"));
            row.CreateCell(1).SetCellValue(new HSSFRichTextString("Column B"));
            row.CreateCell(2).SetCellValue(new HSSFRichTextString("Column C"));
            row.CreateCell(3).SetCellValue(new HSSFRichTextString("Column D"));
            row.CreateCell(4).SetCellValue(new HSSFRichTextString("Column E"));
            row.CreateCell(5).SetCellValue(new HSSFRichTextString("Column F"));

            //set print area from column a to column c (on first row)
            wb.SetPrintArea(
                    0, //sheet index
                    0, //start column
                    2, //end column
                    0, //start row
                    0  //end row
            );

            wb = WriteOutAndReadBack(wb);

            // Ensure the tab index
            TabIdRecord tr = null;
            foreach (Record r in wb.Workbook.Records)
            {
                if (r is TabIdRecord)
                {
                    tr = (TabIdRecord)r;
                }
            }
            Assert.IsNotNull(tr);
            Assert.AreEqual(1, tr._tabids.Length);
            Assert.AreEqual(0, tr._tabids[0]);

            // Ensure the print setup
            Assert.AreEqual("new_sheet!$A$1:$C$1", wb.GetPrintArea(0));
            Assert.AreEqual("new_sheet!$A$1:$C$1", wb.GetName("Print_Area").RefersToFormula);

            // Needs reference not value
            NameRecord nr = wb.Workbook.GetNameRecord(
                  wb.GetNameIndex("Print_Area")
            );
            Assert.AreEqual("Print_Area", nr.NameText);
            Assert.AreEqual(1, nr.NameDefinition.Length);
            Assert.AreEqual(
                  "new_sheet!$A$1:$C$1",
                  ((Area3DPtg)nr.NameDefinition[0]).ToFormulaString(HSSFEvaluationWorkbook.Create(wb))
            );
            // TODO - fix me to be Reference not Value!
            //Assert.AreEqual('R', nr.NameDefinition[0].RVAType);
        }
开发者ID:xoposhiy,项目名称:npoi,代码行数:53,代码来源:TestBugs.cs

示例3: TestSetSheetOrderHSSF

        public void TestSetSheetOrderHSSF()
        {
            IWorkbook wb = new HSSFWorkbook();
            ISheet s1 = wb.CreateSheet("first sheet");
            ISheet s2 = wb.CreateSheet("other sheet");

            IName name1 = wb.CreateName();
            name1.NameName = (/*setter*/"name1");
            name1.RefersToFormula = (/*setter*/"'first sheet'!D1");

            IName name2 = wb.CreateName();
            name2.NameName = (/*setter*/"name2");
            name2.RefersToFormula = (/*setter*/"'other sheet'!C1");


            IRow s1r1 = s1.CreateRow(2);
            ICell c1 = s1r1.CreateCell(3);
            c1.SetCellValue(30);
            ICell c2 = s1r1.CreateCell(2);
            c2.CellFormula = (/*setter*/"SUM('other sheet'!C1,'first sheet'!C1)");

            IRow s2r1 = s2.CreateRow(0);
            ICell c3 = s2r1.CreateCell(1);
            c3.CellFormula = (/*setter*/"'first sheet'!D3");
            ICell c4 = s2r1.CreateCell(2);
            c4.CellFormula = (/*setter*/"'other sheet'!D3");

            // conditional formatting
            ISheetConditionalFormatting sheetCF = s1.SheetConditionalFormatting;

            IConditionalFormattingRule rule1 = sheetCF.CreateConditionalFormattingRule(
                    ComparisonOperator.Between, "'first sheet'!D1", "'other sheet'!D1");

            IConditionalFormattingRule[] cfRules = { rule1 };

            CellRangeAddress[] regions = { new CellRangeAddress(2, 4, 0, 0), // A3:A5
        };
            sheetCF.AddConditionalFormatting(regions, cfRules);

            wb.SetSheetOrder("other sheet", 0);

            // names
            Assert.AreEqual("'first sheet'!D1", wb.GetName("name1").RefersToFormula);
            Assert.AreEqual("'other sheet'!C1", wb.GetName("name2").RefersToFormula);

            // cells
            Assert.AreEqual("SUM('other sheet'!C1,'first sheet'!C1)", c2.CellFormula);
            Assert.AreEqual("'first sheet'!D3", c3.CellFormula);
            Assert.AreEqual("'other sheet'!D3", c4.CellFormula);

            // conditional formatting
            IConditionalFormatting cf = sheetCF.GetConditionalFormattingAt(0);
            Assert.AreEqual("'first sheet'!D1", cf.GetRule(0).Formula1);
            Assert.AreEqual("'other sheet'!D1", cf.GetRule(0).Formula2);
        }
开发者ID:mdjasim,项目名称:npoi,代码行数:55,代码来源:TestHSSFWorkbook.cs

示例4: expectName

 private void expectName(HSSFWorkbook wb, String name, String expect)
 {
     Assert.AreEqual(expect, wb.GetName(name).RefersToFormula);
 }
开发者ID:asd1355215911,项目名称:npoi,代码行数:4,代码来源:TestHSSFWorkbook.cs


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