Skip to content

Getting started

Raphael Stoeckli edited this page Aug 24, 2018 · 1 revision

Creating a new workbook

Workbook workbook = new Workbook("test1.xlsx", "Sheet1");
This is the most common constructor. You can define the filename and the name of the first worksheet. This worksheet will also be the current worksheet after creating the workbook.

Creating an additional worksheet

workbook.AddWorksheet("Sheet2");
The new created worksheet will be the current worksheet. To set another worksheet as current sheet, use workbook.SetCurrentWorksheet("Sheet1");.

reading a worksbook

Workbook wb = Workbook.Load("basic.xlsx");
The workbokk contains all woeksheets and the enclosed cells. Resolved are values (e.g. stings or numbers) as well as formulas.

Adding cells

Shortener

The quickest way to create cells is usinng the shortener object 'WS' in the current workbook:

workbook.WS.Value("Some Text"); or in case of formulas: workbook.WS.Formula("=A2");

Additionally, a style can be added:

workbook.WS.Value(DateTime.Now, Style.BasicStyles.Bold);

Go to the next row with:

workbook.WS.Down(); or workbook.WS.Down(3); to move 3 cells down

Go to the next column with:

workbook.WS.Right(); or workbook.WS.Right(2); to move 2 cells towards right

Regular Syntax

workbook.CurrentWorksheet.AddNextCell("Test"); or workbook.CurrentWorksheet.AddNextCell(22.589);
AddNextCell() adds values to a cell and sets the "cursor" to the next column (default) or row.

workbook.CurrentWorksheet.AddCell("ABC", "A1"); or workbook.CurrentWorksheet.AddCell(true, 0, 4);
AddCell() adds values to the passed cell address. The address can be a string like "A1" or the column and row number (zero-based). In this case 0 is "A" and 4 is "5" → "A5".

workbook.CurrentWorksheet.AddCellRange(values, "A4:C4"); (values is a List<> of 3 values like strings etc.)
AddCellRange() adds a range of values to the passed cell range. The Range can be in the form "A4:C4" or as start address and end address.

If using AddNextCell() you can jump to the next row or column with workbook.CurrentWorksheet.GoToNextRow(); or workbook.CurrentWorksheet.GoToNextColumn();
The direction for AddNextCell() can be set by workbook.CurrentWorksheet.CurrentCellDirection = Worksheet.CellDirection.RowToRow; or workbook.CurrentWorksheet.CurrentCellDirection = Worksheet.CellDirection.ColumnToColumn;.

Using styles

[TBD]

Saving the workbook

workbook.Save(); or workbook.SaveAs(@"C:\temp\test2.xlsx");