Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: ixed File paths, added sample data

...

Code Block
public void GenerateReport()
        {
            // Create an instance of ExcelTemplate
            ExcelTemplate xlt = new ExcelTemplate();
 
            // Open the template workbook
            string templatePath = @"..\..\templatesExcelTemplateFiles\ChartDemoTemplate.xlsx";
            xlt.Open(templatePath);
 
            DataTable dt = GetCSVData(@"..\..\DataExcelData\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(@"..\..\OutPutExcelOutputFiles\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;
        }
    }
 
 

...