Page tree

Versions Compared

Key

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

...

Diving right into the code

...

Info

In the Hello World sample

...

web application, ExcelApplication_HelloWorld.aspx

...

has a text box for users to supply a value and ExcelApplication_HelloWorld.aspx.cs/vb contains the code shown below.

1. Include the SoftArtisans.OfficeWriter.ExcelWriter namespace in the code behind.

...

Vbnet
2
2

Dim XLAPP 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.

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

Csharp
3
3
Workbook WB = XLAPP.Create(ExcelApplication.FileFormat.Excel2007);

...

Vbnet
6
6

XLAPP.Save(WB, 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.

7. Go to the web form page, ExcelApplication_HelloWorld.aspx, to try out the sample. Run the code. In the output file, you will see that the custom text from the form has been inserted into cell "A1".

...

Vbnet
8
8

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

You can download the Hello World sample code (C# or VB) to see the finished product.

Downloads

You can download the code for the hello world tutorial as a visual studio solution.