Page tree

Versions Compared

Key

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

...

2. Instantiate the ExcelApplication object

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

Dim oXLAPP XLAPP As New ExcelApplication()

...

3. Create a new workbook with ExcelApplication.Create()

Csharp
3
3
Workbook oWBWB = oXLAPPXLAPP.Create(ExcelApplication.FileFormat.Excel2007);
Vbnet
3
3

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

...

4. Access the first worksheet through the Workbook.Worksheets collection

Csharp
4
4
Worksheet oWKSTWKST = oWBWB.Worksheets[0];
Vbnet
4
4

Dim oWKST WKST As Worksheet = oWBWB.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();
oWKSTWKST.Cells[0,0].Value = value;
Vbnet
5
5

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

...

6. Save the workbook

Csharp
6
6
oXLAPPXLAPP.Save(oWBWB, Page.Response, "Output.xlsx", false);
Vbnet
6
6

oXLAPPXLAPP.Save(oWBWB, Page.Response, "Output.xlsx", False)

...

Csharp
7
7

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

Vbnet
8
8

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