【发布时间】:2014-09-09 05:06:16
【问题描述】:
我的要求是从 excel 表中读取指定列的行。例如
如果我需要从上面的 excel 中获取列的行值(即)B 如何获取它。 我正在使用以下代码获取列标题名称。
Excel.Application xlApp = new Excel.Application();
Excel.Workbook xlWorkbook = xlApp.Workbooks.Open(FileNameTextBox.Text);
Excel.Worksheet xlWorksheet = xlWorkbook.Sheets[1]; // assume it is the first sheet
int columnCount = xlWorksheet.UsedRange.Columns.Count;
List<string> columnNames = new List<string>();
for (int c = 1; c < columnCount; c++)
{
if (xlWorksheet.Cells[1, c].Value2 != null)
{
string columnName = xlWorksheet.Columns[c].Address;
Regex reg = new Regex(@"(\$)(\w*):");
if (reg.IsMatch(columnName))
{
Match match = reg.Match(columnName);
columnNames.Add(match.Groups[2].Value);
}
}
}
它给了我一个包含 A、B、C、D、E、F 的列表的输出。如果我需要单独获取列 C 的值,那么如何获取它..?
【问题讨论】:
标签: c# excel interop excel-2010