...
Writing the code for the cover sheet comes in two parts. the first part uses ExcelApplication
to create a template coversheet; and the second part uses ExcelTemplate
to bind the appropriate data to the data markers on the cover sheet.
...
We want to create a cover sheet that looks like the following Excel worksheet:
Ultimately, the cells below the Table of Contents will be populated with hyperlinks to country sheets in the workbook. The user is provided with several logo options, one of which will be inserted into the sheet. The "Report For :" field will correspond with the supplied name, and finally, the "Date Executed :" will correspond with today's date.
Info | ||
---|---|---|
| ||
The code for this part of the tutorial can be found in Part2.aspx.cs |
...
Code Block |
---|
protected void GenerateTemplate() { xla = new ExcelApplication(); wb = xla.Open(Page.MapPath(@"templates\template.xlsx")); for (int i = 0; i < selectedCountries.Count; i++) { wb.Worksheets.CopySheet(wb.Worksheets[0], wb.Worksheets.Count, selectedCountries[i]); } wb.Worksheets["SimpleTemplate"].Visibility = Worksheet.SheetVisibility.Hidden; wb.Worksheets[1].Select(); /*********Part 2*************/ AddCoverSheet(); /**************************/ } |
Adding the cover sheet
1. Create In AddCoverSheet
, create a new worksheet called "Summary" at the beginning of the workbook with Worksheets.CreateWorksheet
:
...