Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Excellibrary documentation

Tags:

c#

I found many recommendations here to use ExcelLibrary for editing excell files, but I can't find any documentation anywhere.

http://code.google.com/p/excellibrary/

like image 565
el ninho Avatar asked Jan 19 '12 15:01

el ninho


People also ask

What is Excellibrary?

This is a small C# library made to simplify reading from and writing to Excel workbooks in the Open XML file format (. xlsx). Here's an example to get you started: Workbook workbook = new Workbook(); workbook.

Which library is used for working with Excel in robot framework?

The Excel. Files library can be used to read and write Excel files without the need to start the actual Excel application.


1 Answers

Try this:

var workbook = Workbook.Load("spreadsheet.xls");
var worksheet = workbook.Worksheets[0]; // assuming only 1 worksheet
var cells = worksheet.Cells;
var dataTable = new DataTable("datatable");

// add columns
dataTable.Columns.Add("column1");
dataTable.Columns.Add("column2");
...

// add rows
for (int rowIndex = cells.FirstRowIndex + 1; rowIndex <= cells.LastRowIndex; rowIndex++)
{
    var values = new List<string>();
    foreach(var cell in cells.GetRow(rowIndex))
    {
        values.Add(cell.Value.StringValue);
    }

    dataTable.LoadDataRow(values.ToArray(), true);
}

It's not exactly the prettiest code but it returns a DataTable. I recommend that you just use the values directly if possible ie. instead of converting to a DataTable read the values directly and skip this conversion step.

like image 179
Lester Avatar answered Oct 01 '22 19:10

Lester