Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.net 如何使用EPPlus生成的LinqToExcel读取Excel的列名?_.net_Excel_Linq_Epplus_Linq To Excel - Fatal编程技术网

.net 如何使用EPPlus生成的LinqToExcel读取Excel的列名?

.net 如何使用EPPlus生成的LinqToExcel读取Excel的列名?,.net,excel,linq,epplus,linq-to-excel,.net,Excel,Linq,Epplus,Linq To Excel,我想读取使用EPPlus和LinqToExcel生成的excel文件的列名。这就是我到目前为止所做的 var excelFile = new ExcelQueryFactory(excelPath); IQueryable<Row> excelSheetValues = from workingSheet in excelFile.Worksheet(sheetName) select workingSheet; string[] headerRow = excelFile.GetC

我想读取使用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(); 

下面的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);

当我在headerRow检索所有列名时,出现了一个错误。如果列值为空,我必须做一些事情。所以我不能在@krishna上循环所有内容。错误在哪里?excelFile.GetColumnNamessheetName.ToArray;在这一行?我无法使用Linq to Excel@Krishna检索值