Intro

Populate a template with ExcelTemplate and then programmatically manipulate or 'post process' the workbook with ExcelApplication.

This demo begins with an ExcelTemplate workbook with data markers.  First, the ExcelTemplate object binds data to the data markers while preserving all existing Excel formats that were in the original template.  Then, the populated workbook is opened as an ExcelApplication Workbook where it can be programmatically manipulated.  ExcelApplication adds a chart.

Code

private ExcelTemplate xlt;
private ExcelApplication xlw;
private Workbook wb;


	/// <summary>
        /// Build the report with ExcelApplication
        /// </summary>
        public void GenerateReport()
        {
            
            PopulateTemplate();
            AddChart();

            /* Save the report to specified folder */
            xlw.Save(wb, @"..\..\Output\TempToApp_output.xlsx");
        }

        /// <summary> Add a column chart to the second worksheet using ExcelApplication.
        /// The chart will show data imported with the ExcelTemplate
        /// object.</summary>
        private void AddChart()
        {
            /* Get the first two worksheets and give them names */
            Worksheet ws = wb.Worksheets[0];
            ws.Name = "Data";

            Worksheet ws2 = wb.Worksheets.CreateWorksheet("ChartSheet");

            /* Create a chart on the second worksheet */
            Anchor anch = ws2.CreateAnchor(0, 0, 50, 50);
            Chart chrt = ws2.Charts.CreateChart(ChartType.Column.Clustered, anch);

            /* Set series and category data */
            Series srs1 = chrt.SeriesCollection.CreateSeries("=Data!B2:B7");
            chrt.SeriesCollection.CategoryData = "=Data!A2:A7";
            srs1.NameFormula = "=Data!A1";

            /* Configure the chart's legend */
            Legend lgnd = chrt.Legend;
            lgnd.Visible = true;
            lgnd.Location = Legend.LegendLocation.Right;

            /* Set the chart's Title string and display properties. */
            chrt.Title.Text = "AdventureWorks Global Sales";
        }

Downloads

Sample Template File: TemplateToAppTemplate.xlsx

Sample Output File: TempToApp_output.xlsx