I have a predefined Excel template that has column widths already prefined.
In my code I am using the SfDataGrid.ExportToExcel to populate the template. The problem is that the function changes the widths of the columns.
Is there a way to prevent this?
private void ExcelOutput(string templateFile, string outputFilename)
{
using (ExcelEngine excelEngine = new ExcelEngine())
{
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Xlsx;
IWorkbook workbook = application.Workbooks.Open(templateFile, ExcelOpenType.Automatic);
ExcelExportingOptions exportingOptions = new ExcelExportingOptions
{
ExcelVersion = ExcelVersion.Excel2016,
StartRowIndex = 8,
StartColumnIndex = 2,
// ExportColumnWidth = true,
// ExportRowHeight = false,
// ExportStyle = false,
// ExportBorders = false,
// ExportGroupSummary = false,
// ExportStackedHeaders = false,
// ExportTableSummary = false
};
IWorksheet wsMisc = workbook.Worksheets["Misc"];
DgvSummary.ExportToExcel(DgvSummary.View, exportingOptions, wsMisc);
workbook.SaveAs(outputFilename);
workbook.Close();
}
}