Page tree

Versions Compared

Key

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

...

The final output should look something like this

Final Code

Code Block
            ExcelTemplate XLT = new ExcelTemplate();
            XLT.Open(Page.MapPath("//templates//Part1_Financial_Template.xlsx"));

            DataBindingProperties bindingProps = XLT.CreateDataBindingProperties();

            DataTable dtAssets = GetCSVData("//data//Assets.csv");
            DataTable dtLosses = GetCSVData("//data//Losses.csv");
            DataTable dtOther = GetCSVData("//data//Other.csv");

            string[] headerValues = { "2011" };
            string[] headerNames = { "FiscalYear" };

            XLT.BindData(dtAssets, "Assets", bindingProps);
            XLT.BindData(dtLosses, "Losses", bindingProps);
            XLT.BindData(dtOther, "Other", bindingProps);


            XLT.BindRowData(headerValues, headerNames, "Header", bindingProps);

            XLT.Process();

//Post-Processing
            ExcelApplication XLA = new ExcelApplication();

            Workbook wb = XLA.Open(XLT);

            Worksheet ws = wb.Worksheets[0];

            ws.PopulatedCells.AutoFitWidth();
            ws.PopulatedCells.AutoFitHeight();

            XLA.Save(wb, Page.Response, "temp.xlsx", false);

...