使用tools SpreadSheetLight我无法找到如何阅读电子表格文件的行。特别是表1。
我遇到的两个问题是
我无法看到获得列索引 这是我的代码
public void ParseExcelFile(FileInfo file)
{
using (SLDocument sl = new SLDocument())
{
FileStream fs = new FileStream(file.FullName, FileMode.Open);
MemoryStream msFirstPass = new MemoryStream();
SLDocument sheet1 = new SLDocument(fs, "Sheet1");
// There is no way that I can see to get the Rows
foreach(var row in sheet1.Rows)
{
foreach(SLCell c in row)
{
// There is no way that I can see to get the Column Index
switch(c.Column )
{
case 1:
//Handle data if cell is Column 1
break;
case 2:
//Handle data if cell is Column 2
break;
case 3:
//Handle data if cell is Column 3
break;
}
}
}
}
}//func
答案 0 :(得分:1)
由于SpreadSheetLight似乎没有公开的代码文档,因此人们很难回答这个问题。基于几个假设,我有两个建议:
答案 1 :(得分:0)
下面的代码会读取每一行(假设文件是Excel文件的文件路径):
using (SLDocument sl = new SLDocument())
{
FileStream fs = new FileStream(file, FileMode.Open);
SLDocument sheet = new SLDocument(fs, "Table 1");
SLWorksheetStatistics stats = sheet.GetWorksheetStatistics();
for (int j = 1; j < stats.EndRowIndex; j++)
{
// Get the first column of the row (SLS is a 1-based index)
var value = sheet.GetCellValueAsString(j, 0);
}
}