Page tree

Versions Compared

Key

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

...

We're done creating the template. Now it's time to write the code.

Writing the Code

SOMETHING ABOUT BINDROWDATA and BINDCOLUMN DATA

Info

In the sample code, the a sample web application page Part1.aspx and code behind Part1.aspx.cs are available in the SimpleExpenseSummary directory.

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

Csharp
1
1

using SoftArtisans.OfficeWriter.ExcelWriter;

2. In the method that is going to actually run the report, instantiate the ExcelTemplate object.

Csharp
2
2

ExcelTemplate XLT = new ExcelTemplate();

3. Open the template file from earlier with the ExcelTemplate.Open() method.

Csharp
3
3

XLT.Open(Page.MapPath("//templates//part1_template.xlsx"));

4. Create a DataBindingProperties object. Although we won't be changing any of the binding properties, a DataBindingProperties is a required parameter in all ExcelTemplate data binding methods.

Csharp
4
4

DataBindingProperties dataProps = XLT.CreateDataBindingProperties();

5.

Info

If you want to import a row of data as a vertical column in Excel, you need to use ExcelTemplate.BindColumnData and the data marker syntax %%=$DataSourceName.ColumnName, with a $ to denote that the data should be imported as a column instead of a row.

Run your code

Final Code

Csharp
10
10
Add code here
Vbnet
1010

Add code here

Downloads