如何在提取excel单元格时获取行号
Hello Paul,
我尝试使用你的优秀代码C#如何阅读.xlsx带有3行代码的Excel文件来提取内容单元格一个简单的工作表。
我的问题是我可以用cell.ColumnIndex检索列号和cell.Text的单元格内容,但我不知道如何得到单元格的行号,所以我无法成功提取数据。
你能借我一把吗?
提前致意并感谢
David Luque
什么我试过了:
Hello Paul,
I've try to use your great code "C# How To Read .xlsx Excel File With 3 Lines of Code" to extract content cells of a simple sheet.
My problem is I can retrieve the column number with cell.ColumnIndex and cell content with cell.Text, but I don't know how to get the row number of the cell, So I can't extract the data successfully.
Can you lend me a hand?
Regards and thanks in advance
David Luque
What I have tried:
long MaxCol = 0;
long MaxRow = 0;
foreach (var worksheet in Workbook.Worksheets(@"T:\Libro1.xlsx"))
{
MaxCol = worksheet.MaxColumnIndex;
foreach (var row in worksheet.Rows)
{
foreach (var cell in row.Cells)
if (cell != null)
{
MessageBox.Show("Column: " + cell.ColumnIndex + "\nContent: " + cell.Text);
}
我的问题是我可以使用cell.ColumnIndex和cell.Text的单元格内容检索列号,但我不知道如何获取单元格的行号,所以我无法成功提取数据。
My problem is I can retrieve the column number with cell.ColumnIndex and cell content with cell.Text, but I don't know how to get the row number of the cell, So I can't extract the data successfully.
你试过 Cell.RowIndex 吗?
[更新]
Did you tried Cell.RowIndex ?
[Update]
Cell中没有RowIndex,只有ColumnIndex。
There is no RowIndex in Cell, there is only ColumnIndex.
然后尝试 cell.Row 和 cell.Column 。
然后尝试使用cell.Row和cell.Column。
没有cell.Column,但非常感谢您的尝试。我终于使用了NPOI,它已经有效了
问候
Then try with cell.Row and cell.Column.
There is no cell.Column, but many thanks for the try. I've finally use NPOI and it already works
Regards