如何在提取excel单元格时获取行号 [英] How to get row number when extracting excel cells

查看:886
本文介绍了如何在提取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);
                        }

推荐答案

Quote:

我的问题是我可以使用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]

Quote:

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


这篇关于如何在提取excel单元格时获取行号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆