EPPlus,查找并设置命名范围的值 [英] EPPlus, Find and set the value for a Named Range
问题描述
我一直在努力尝试使用ExcelPackage(3.0.1)库设置命名范围(在本例中为单个命名单元格)的值,它应该很简单:
I've been pulling my hair out trying to set the value of a named range (in this case, a single named cell) using the ExcelPackage (3.0.1) library, it should be a simple as this:
ExcelNamedRange er = xlPackage.Workbook.Names["Customer"];
er.Value = "Foo Bar";
我显然做错了-有谁能效法我的榜样
I'm obviously doing it wrong - has anyone got an example I can follow
谢谢
推荐答案
我在寻找ExcelPackage文档,以查看Names []集合返回的类型并发现文档很快就会到来,或者至少是他们在2007年所说的。
I looked for ExcelPackage documentation to see what type Names[] collection returns and found that documentatios will come soon, or at least that is what they said back in 2007.
我建议您使用EPPlus,因为它是一个excel库(仅xlsx),
I suggest you use EPPlus wich is a excel library (xlsx only) that have worked great to me.
现在,为命名范围内的每个单元格设置一个值:
Now, to set a value for each cell in a named range:
ExcelWorksheet sheet = _openXmlPackage.Workbook.Worksheets["SheetName"];
using (ExcelNamedRange namedRange = sheet.Names["RangeName"])
{
for (int rowIndex = Start.Row; rowIndex <= namedRange.End.Row; rowIndex++)
{
for (int columnIndex = namedRange.Start.Column; columnIndex <= namedRange.End.Column; columnIndex++)
{
sheet.Cells[rowIndex, columnIndex].Value = "no more hair pulling";
}
}
}
这篇关于EPPlus,查找并设置命名范围的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!