gpt4 book ai didi

c# - 使用 linq to excel 从多个 excel 表中读取数据 (http ://code. google.com/p/linqtoexcel/)

转载 作者:太空宇宙 更新时间:2023-11-03 13:55:45 30 4
gpt4 key购买 nike

我正在尝试从多页 Excel 文件中读取数据。第一张表有列标题。第二张没有。第三个没有。我可以成功阅读第一张纸。

当我尝试从没有标题的工作表中读取时,程序出现异常。

var sheet1_data = from c in excel.Worksheet<Species>("Sheet1") select c; // This works and the question is how do i retreive data from sheet2?

我目前正在使用这个:

var Sheet2_data = from b in excel.WorksheetNoHeader("sheet2") select b; 

当我尝试读取 sheet2_data 时,出现以下异常:

'sheet2' is not a valid worksheet name. Valid worksheet names are: 'sheet2,sheet3',

我们将不胜感激任何帮助。

B.

最佳答案

可以使用 GetWorksheetNames() 方法抽象工作表名称。

    var sheets = excel.GetWorksheetNames();
foreach(var sheet in sheets)
{
var sheetData = from x in excel.Worksheet(sheet) select x;
}

关于c# - 使用 linq to excel 从多个 excel 表中读取数据 (http ://code. google.com/p/linqtoexcel/),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12251579/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com