0

我想读取使用 EPPlus 和 LinqToExcel 生成的 excel 文件的列名。这是我到目前为止所做的

var excelFile = new ExcelQueryFactory(excelPath);
IQueryable<Row> excelSheetValues = from workingSheet in excelFile.Worksheet(sheetName) select workingSheet;
string[] headerRow = excelFile.GetColumnNames(sheetName).ToArray(); 
4

2 回答 2

0

下面的 foreach 对你有用吗?您可以遍历开始行,开始列并获取单元格文本(或设置)

var excelFile = new ExcelQueryFactory(excelPath);
IQueryable<Row> excelSheetValues = from workingSheet in excelFile.Worksheet(sheetName) select workingSheet;
string[] headerRow = excelFile.GetColumnNames(sheetName).ToArray(); 
var ws = excelFile.Worksheet(sheetName);
foreach (var cell in ws.Cells[ws.Dimension.Start.Row, ws.Dimension.Start.Column, 1, ws.Dimension.End.Column]) 
    Console.WriteLine(cell.Text);
于 2015-07-13T06:58:55.763 回答
0

如果在第一行中指定了列名,请尝试以下操作:

var excel = new ExcelQueryFactory(excelPath);
var columnNames = excel.GetColumnNames(excel.GetWorksheetNames().FirstOrDefault()).ToList();
于 2022-01-04T13:24:58.623 回答