Page tree

Versions Compared

Key

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

...

Note: At the top of the worksheet, we will display the fiscal year, the company division and group. Below will be 2 tables: one to show the top 5 expenses and another to show all the expenses.

Info
titleFollowing the Sample Code

In the sample code, the downloadable C# project, there is a completed template file is located in SimpleExpenseSummary/templates/part1_template.xlsx.

1. Start with a blank .xlsx file. Save the file as template.xlsx.

...

Adding an ExcelWriter Reference in Visual Studio

Info
titleFollowing the Sample Code

In the sample code, the reference to SoftArtisans.OfficeWriter.ExcelWriter.dll has already been added to the SimpleExpenseSummary project.

...

  1. Open Visual Studio and create a .NET project.
    • The sample code uses a web application.
  2. Add a reference to SoftArtisans.OfficeWriter.ExcelWriter.dll
    • SoftArtisans.OfficeWriter.ExcelWriter.dll is located under Program Files > SoftArtisans > OfficeWriter > dotnet > bin

Writing the Code

In the sample code, the
Info
titleFollowing the Sample Code

There is a sample web application page Part1.aspx and code behind Part1.aspx.cs are available in the SimpleExpenseSummary/ directory that shows the completed code.

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

...

7. Get the data for the Top 5 Expenses and All Expenses data sets.

Info
titleFollowing the Sample

In the sample

...

project, we

...

are parsing CSV files

...

with query results

...

, rather than querying a live database. The CSV files are available under the data directory. There is a copy of the CSV parser, GenericParsing.dll in the bin directory of the project GetCSVData is defined in Part1.aspx.cs in a region marked Utility Methods.

These calls are to a helper method GetCSVData that parses the CSV files and returns a DataTable with the values.

Code Block
DataTable dtTop5 = GetCSVData(Page.MapPath("//data//Part1_Top5Expenses.csv"));
DataTable dtAll = GetCSVData(Page.MapPath("//data//Part1_AllExpenses.csv"));

If you are following in your own project and would like to parse the CSV files as well,

8. Use ExcelTemplate.BindData to bind the data for the Top 5 Expenses and All Expenses data sets.

...