问题描述
使用 Excel Interop,您可以像这样获取工作表正在使用的行数:
Using Excel Interop, you can get the count of rows in use by a sheet like so:
_xlSheet.UsedRange.Rows
(其中_xlSheet"是 Excel.Worksheet).
(where "_xlSheet" is an Excel.Worksheet).
Spreadsheet Light 中的等价物是什么?
What is the equivalent in Spreadsheet Light?
您可以像这样添加工作表:
You can add a worksheet like so:
var sl = new SLDocument();
. . .
sl.AddWorksheet("SheetsToTheWind");
...但是您如何访问该工作表以查询其使用的行数?
...but how can you then access that worksheet to interrogate it for its used row count?
推荐答案
添加工作表后,它也处于活动状态.这意味着您可以从方法 GetWorksheetStatistics
中获取 WorksheetStatistics
.该统计实例有一个 NumberOfRows
属性:
After adding the worksheet it is active as well. That means that you can get the WorksheetStatistics
from the method GetWorksheetStatistics
. That statistics instance has a NumberOfRows
property:
// NOTE: The information is only current at point of retrieval.
var stats = sl.GetWorksheetStatistics();
var rowcount = stats.NumberOfRows;
如果你想知道所有工作表的行数,你可以这样做:
If you want to to know the rowcount of all sheets you can do:
foreach(var name in sl.GetSheetNames())
{
sl.SelectWorksheet(name);
var stats = sl.GetWorksheetStatistics();
var rowcount = stats.NumberOfRows;
Trace.WriteLine(String.Format("sheet '{0}' has {1} rows", name, rowcount));
}
这篇关于电子表格 Light 中 Excel Interop 的 Worksheet.UsedRange.Rows 的模拟是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!