本文整理汇总了C#中NPOI.HSSF.UserModel.HSSFWorkbook.GetNameIndex方法的典型用法代码示例。如果您正苦于以下问题:C# HSSFWorkbook.GetNameIndex方法的具体用法?C# HSSFWorkbook.GetNameIndex怎么用?C# HSSFWorkbook.GetNameIndex使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NPOI.HSSF.UserModel.HSSFWorkbook
的用法示例。
在下文中一共展示了HSSFWorkbook.GetNameIndex方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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);
}
示例2: 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);
}
}
示例3: TestDiscontinousReference
public void TestDiscontinousReference()
{
Stream is1 = HSSFTestDataSamples.OpenSampleFileStream("44167.xls");
HSSFWorkbook wb = new HSSFWorkbook(is1);
InternalWorkbook workbook = wb.Workbook;
HSSFEvaluationWorkbook eb = HSSFEvaluationWorkbook.Create(wb);
Assert.AreEqual(1, wb.NumberOfNames);
String sheetName = "Tabelle1";
String rawRefA = "$C$10:$C$14";
String rawRefB = "$C$16:$C$18";
String refA = sheetName + "!" + rawRefA;
String refB = sheetName + "!" + rawRefB;
String ref1 = refA + "," + refB;
// Check the low level record
NameRecord nr = workbook.GetNameRecord(0);
Assert.IsNotNull(nr);
Assert.AreEqual("test", nr.NameText);
Ptg[] def = nr.NameDefinition;
Assert.AreEqual(4, def.Length);
MemFuncPtg ptgA = (MemFuncPtg)def[0];
Area3DPtg ptgB = (Area3DPtg)def[1];
Area3DPtg ptgC = (Area3DPtg)def[2];
UnionPtg ptgD = (UnionPtg)def[3];
Assert.AreEqual("", ptgA.ToFormulaString());
Assert.AreEqual(refA, ptgB.ToFormulaString(eb));
Assert.AreEqual(refB, ptgC.ToFormulaString(eb));
Assert.AreEqual(",", ptgD.ToFormulaString());
Assert.AreEqual(ref1, NPOI.HSSF.Model.HSSFFormulaParser.ToFormulaString(wb, nr.NameDefinition));
// Check the high level definition
int idx = wb.GetNameIndex("test");
Assert.AreEqual(0, idx);
NPOI.SS.UserModel.IName aNamedCell = wb.GetNameAt(idx);
// Should have 2 references
Assert.AreEqual(ref1, aNamedCell.RefersToFormula);
// Check the parsing of the reference into cells
Assert.IsFalse(AreaReference.IsContiguous(aNamedCell.RefersToFormula));
AreaReference[] arefs = AreaReference.GenerateContiguous(aNamedCell.RefersToFormula);
Assert.AreEqual(2, arefs.Length);
Assert.AreEqual(refA, arefs[0].FormatAsString());
Assert.AreEqual(refB, arefs[1].FormatAsString());
for (int i = 0; i < arefs.Length; i++)
{
AreaReference ar = arefs[i];
ConfirmResolveCellRef(wb, ar.FirstCell);
ConfirmResolveCellRef(wb, ar.LastCell);
}
}