Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Csharp
2
2
ExcelApplication oXLAPP = new ExcelApplication();
Vbnet
2
2

Dim oXLAPP As New ExcelApplication()

Unlike the ExcelTemplate object, which represents a single file, the ExcelApplication works as a file generation engine. The ExcelApplication object can be used to create, open, and save multiple workbooks.

...

Csharp
3
3
Workbook oWB = oXLAPP.Create(ExcelApplication.FileFormat.Excel2007);
Vbnet
3
3

Dim oWB As Workbook = oXLAPP.Create(ExcelApplication.FileFormat.Excel2007)

ExcelWriter has the ability to create Excel 2003 (XLS) files and Excel 2007 (XLSX) files, but cannot convert between formats. The file format must be declared when the workbook is created and the file extension of the output file must match when the file is saved.

...

Csharp
4
4
Worksheet oWKST = oWB.Worksheets[0];
Vbnet
4
4

Dim oWKST As Worksheet = oWB.Worksheets(0)

You can access worksheets by name (e.g. "Sheet1") or by index (shown above), but ExcelWriter will throw an exception if you attempt to access a worksheet that does not exist.

...

Csharp
5
5
string value = DataValueBox.Text.Trim();
 oWKST.Cells[0,0].Value = value;
Vbnet
5
5

Dim value As String = DataValueBox.Text.Trim()
oWKST.Cells(0, 0).Value = value

It is important to note that ExcelWriter indices are all 0-indexed, unlike Excel indices, which are 1-indexed. This is importing when working with cells, rows, columns, and worksheet positions in ExcelWriter. You can also reference cells by name; in this case, it would be "A1".

...

Csharp
6
6
oXLAPP.Save(oWB, Page.Response, "Output.xlsx", false);
Vbnet
6
6

oXLAPP.Save(oWB, Page.Response, "Output.xlsx", False)

ExcelApplication.Save has the same output options as ExcelTemplate: save to disk, save to memory stream, stream back to the client inline, and stream back to the client as an attachment. In this case, we're streaming the workbook back to the client as an attachment.
Remember that the file extension must match the file format specified when the workbook was created.

...

Csharp
7
7

using SoftArtisans.OfficeWriter.ExcelWriter;
...
ExcelApplication oXLAPP = new ExcelApplication();
ExcelApplication oXLAPP = new ExcelApplication();
Worksheet oWKST = oWB.Worksheets[0];
string value = DataValueBox.Text.Trim();
oWKST.Cells[0,0].Value = value;
oXLAPP.Save(oWB, Page.Response, "Output.xlsx", false);

Vbnet
8
8

Include SoftArtisans.OfficeWriter.ExcelWriter
...
Dim oXLAPP As New ExcelApplication()
Dim oWB As Workbook = oXLAPP.Create(ExcelApplication.FileFormat.Excel2007)
Dim oWKST As Worksheet = oWB.Worksheets(0)
Dim value As String = DataValueBox.Text.Trim()
oWKST.Cells(0, 0).Value = value
oXLAPP.Save(oWB, Page.Response, "Output.xlsx", False)