https://github.com/xavierjefferson/excellibrary
https://github.com/xavierjefferson/excellibrary
Last synced: about 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/xavierjefferson/excellibrary
- Owner: xavierjefferson
- License: gpl-3.0
- Created: 2022-09-15T20:36:46.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2022-09-16T12:07:42.000Z (over 2 years ago)
- Last Synced: 2025-02-13T07:39:53.400Z (3 months ago)
- Language: C#
- Size: 200 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ExcelLibrary
This code is adapted from this: https://code.google.com/archive/p/excellibrary/
The aim of this project is provide a native .NET solution to create, read and modify Excel files without using COM interop or OLEDB connection.
Currently .xls (BIFF8) format is implemented. In future .xlsx (Excel 2007) may also be supported.
## Create file
//create new xls file
string file = "C:\newdoc.xls";
Workbook workbook = new Workbook();
Worksheet worksheet = new Worksheet("First Sheet");
worksheet.Cells[0, 1] = new Cell((short)1);
worksheet.Cells[2, 0] = new Cell(9999999);
worksheet.Cells[3, 3] = new Cell((decimal)3.45);
worksheet.Cells[2, 2] = new Cell("Text string");
worksheet.Cells[2, 4] = new Cell("Second string");
worksheet.Cells[4, 0] = new Cell(32764.5, "#,##0.00");
worksheet.Cells[5, 1] = new Cell(DateTime.Now, @"YYYY-MM-DD");
worksheet.Cells.ColumnWidth[0, 1] = 3000;
workbook.Worksheets.Add(worksheet);
workbook.Save(file);## Open XLS file
Workbook book = Workbook.Load(file);
Worksheet sheet = book.Worksheets[0];## Traverse cells
```foreach (Pair, Cell> cell in sheet.Cells) { dgvCells[cell.Left.Right, cell.Left.Left].Value = cell.Right.Value; }```
## Traverse rows by index
for (int rowIndex = sheet.Cells.FirstRowIndex; rowIndex <= sheet.Cells.LastRowIndex; rowIndex++)
{
Row row = sheet.Cells.GetRow(rowIndex);
for (int colIndex = row.FirstColIndex; colIndex <= row.LastColIndex; colIndex++)
{
Cell cell = row.GetCell(colIndex);
}
}