Reading data rows from a table

Using tools SpreadSheetLight I cannot find how to read the lines of a spreadsheet file. Specifically Sheet 1.

Two tasks Im have

  • Unable to see how to get rows
  • Unable to see how to get column index Here is my code

    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
    
+4
source share
2 answers

It will be difficult for his people to answer this, since SpreadSheetLight does not have publicly available code documentation. I have two suggestions based on several assumptions:

  • Does the SLDocument.Row.SLCell class have any index property? If so, you can get the necessary information from there.
  • foreach , .
+1

(, 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);

    }
}
0

Source: https://habr.com/ru/post/1539511/


All Articles