Hello World with ExcelTemplate
ExcelWriter's ExcelTemplate approach allows you to write data to a template file that contains data markers. The data markers tell ExcelWriter where to bind specific sets of data. This tutorial will show you the basics on how to dynamically insert data into a worksheet using ExcelTemplate by taking custom text from a web form textbox and inserting it into a template file.
Setting up the template file
The template file for Hello World can be found under \templates\Hello World.xlsx.
...
Now the template file is done. Next is writing the code to bind the string value to the data marker.
Writing the code
// ExcelTemplate
Code Block | ||
---|---|---|
| ||
using SoftArtisans.OfficeWriter.ExcelWriter;
ExcelTemplate oXLT = new ExcelTemplate();
oXLT.Open(Page.MapPath("Hello World.xlsx"));
DataBindingProperties oDataProps = oXLT.CreateDataBindingProperties();
string value = DataValueBox.Text.Trim();
oXLT.BindCellData(value, "DataValue", oDataProps);
oXLT.Process();
oXLT.Save(Page.Response, "Output.xlsx", false);
|
This section refers to the code-behind for the ExcelTemplate Hello World sample: ExcelTemplate_HelloWorld.aspx.[cs/vb]. The corresponding web form is ExcelTemplate_HelloWorld.aspx.
...