Page tree

Versions Compared

Key

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

...

Code Block
public class GroupingAndNesting
    {
          /// <summary>
        /// Build the report with ExcelTemplate
        /// </summary>
        public void GenerateReport()
        {
            //--- Create a new ExcelTemplate object and open a template file

            ExcelTemplate xlt = new ExcelTemplate();
            //Open the template
            xlt.Open(@"..\..\ExcelTemplateFiles\GroupingAndNestingTemplate.xlsx");

            //--- Fill the dataset with the data from the CSV file
            DataSet ds = GetCSVData(@"..\..\ExcelData\GroupingandNestingData.CSV");


            //--- Bind the data to the template file and save it.

            xlt.BindData(ds, "Data", xlt.CreateDataBindingProperties());
            xlt.Process();
            xlt.Save(@"..\..\ExcelOutputFiles\GroupingandNesting_output.xlsx");
        }

        //Parse the data from the CSV file
        System.Data.DataSet GetCSVData(string csvFileName)
        {
            DataSet ds;
            using (GenericParserAdapter parser = new GenericParserAdapter(csvFileName))
            {
                parser.ColumnDelimiter = ',';
                parser.FirstRowHasHeader = true;

                ds = parser.GetDataSet();
            }
            return ds;
        }
    }


...