gembox-spreadsheet - Gembox 获取特定列的所有行(包括空白)的计数

标签 gembox-spreadsheet

我试图获取特定列的最后使用行的计数,但只能获取占用的最大行数。测试数据显示在附件快照中。请帮忙。 Snap Attached Here

        SpreadsheetInfo.SetLicense("FREE-LIMITED-KEY");
        ExcelFile ef = ExcelFile.Load("test.xlsx");

        CellRange rcount = ef.Worksheets[0].Columns[1].Cells;
        Console.WriteLine(ef.Worksheets[0].Rows.Count);


        ef.Save("test.xlsx");
        Console.ReadKey();  

最佳答案

单元格在内部按行分配,而不是按列分配。换句话说,您可以使用 ExcelRow.AlownedCells.Count 获取每行最后使用的列。

要获取特定列中最后使用的行,您可以使用如下所示的内容:

ExcelFile ef = ExcelFile.Load("test.xlsx");
ExcelWorksheet ws = ef.Worksheets[0];

ExcelColumn column = ws.Columns[1];
int rowIndex = ws.Rows.Count - 1;

while (rowIndex >= 0 && column.Cells[rowIndex].ValueType == CellValueType.Null)
    --rowIndex;

Console.WriteLine(rowIndex);

我希望这会有所帮助。

关于gembox-spreadsheet - Gembox 获取特定列的所有行(包括空白)的计数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37897924/

相关文章:

c# - 如果是 .NET Framework 的 .NET 库,如何在 OSX 中使用 GemBox.Spreadsheet

c# - Gembox 电子表格 C# : It is a way to detect if a cell has border?

c# - 使用 Gembox.Spreadsheet 提取到数据表的无效数据值

.net - GemBox - 滚动到 View 功能缺失?

c# - 使用 C# 打印文件 Excel

c# - GemBox 从电子表格或 Flexcel 中检索计算值

c# - Gembox 电子表格 : Is it possible to apply "Convert To Number" for the cells with warning?

c# - 将特殊字符从 MS-Word 或 Open Office writer 转换为记事本