...
Excerpt |
---|
Any chart that references a range with data markers will have its data source updated when ExcelTemplate imports rows of data. Make changes to a template without making any changes to code. |
Technical overview information.
Open the template, right click on the chart and choose the "Select Data..." option. This will open a window with details about the charts data range. Though the range for the chart is only one row (=ChartSheet!$A$26:$B$26), will update the data formula when the data is bound to the data markers in the cells.
Download the report to see how the chart would update once data were bound to the template.
Code
Code Block |
---|
Insertpublic codevoid here GenerateReport() { // Create an instance of ExcelTemplate ExcelTemplate xlt = new ExcelTemplate(); // Open the template workbook string templatePath = @"..\..\templates\ChartDemoTemplate.xlsx"; xlt.Open(templatePath); DataTable dt = GetCSVData(@"..\..\Data\ChartDemoData.csv"); // Pass the DataTable to ExcelTemplate xlt.BindData(dt, "SalesData", xlt.CreateDataBindingProperties()); // Call the process() method to populate the // template with the data source values and save the populated document xlt.Process(); xlt.Save(@"..\..\OutPut\ChartDemo_output.xlsx"); } /// <summary> /// Reads the CSV and returns datatable /// </summary> /// <returns>DataTable of top 5 products</returns> System.Data.DataTable GetCSVData(string csvFileName) { DataTable dt; using (GenericParserAdapter parser = new GenericParserAdapter(csvFileName)) { parser.ColumnDelimiter = ','; parser.FirstRowHasHeader = true; dt = parser.GetDataTable(); } return dt; } } |
Downloads
Template and populated output