BoldSignA modern eSignature application with affordable pricing. Sign up today for unlimited document usage!
Hi Chong,
Thanks for using Syncfusion products.
Query 1: I am trying to auto fit the rowheight and columnwidth when exporting the ggc data to excel?
We have analysed your given code snippet and we have found that you have been used AutofitRows for EntireColumn property, which is the cause of your reported issue. We suggest you to use AutofitRows property only for ExcelCell to resolve this performance issue. Please refer the below code snippets.
[CS]
private static void excel_FormatExcelCellHandler(object sender, ExcelExportEventArgs e)
{
if (e.RowElement.Kind == DisplayElementKind.ColumnHeader)
{
e.ExcelCell.AutofitColumns();
}
if (e.RowElement.Kind == DisplayElementKind.Record)
{
e.ExcelCell.WrapText = true;
if ((e.ExcelCell.LastRow == ((GridExcelExport)sender).GridGroupingControl.Table.DisplayElements.Count - 1) && (e.ExcelCell.LastColumn == ((GridExcelExport)sender).ColCount)) // this condition satisfies while this on the cell that is on last row and last column.
{
e.ExcelCell.AutofitRows();// this satisfies your requirement with better performance.
}
}
e.ExcelCell.CellStyle.ColorIndex = Syncfusion.XlsIO.ExcelKnownColors.White;
e.ExcelCell.CellStyle.IncludeBorder = true;
e.ExcelCell.BorderAround();
}
Also, we have created simple sample with modified code snippet and the same can be downloaded from the following link.
Sample: http://www.syncfusion.com/downloads/support/directtrac/118321/groupdroparea1-1982619337.zip
Query 2: Empty row added between column header and the data.
Before we start to analyse this query could you please provide more details about this issue. Did you enable Filtering or Add New property in your project? Could you please let us know that which scenario you have facing this issue and please share more code snippet with us regarding this issue.
Please let us know if you need further assistance.
Regards,
Shanmugaraja K
Hi Chong,
Thanks for your update.
We would like to let you know that your requirement has been achieved by using UsedRange property. Please refer the below code snippets.
[CS]
private static void excel_FormatExcelCellHandler(object sender, ExcelExportEventArgs e)
{
if (e.RowElement.Kind == DisplayElementKind.ColumnHeader)
{
e.ExcelCell.AutofitColumns();
}
if (e.RowElement.Kind == DisplayElementKind.Record)
{
e.ExcelCell.WrapText = true;
if ( (e.ExcelCell.LastColumn == ((GridExcelExport)sender).ColCount))
{
e.ExcelCell.Worksheet.UsedRange.AutofitRows();
}
}
e.ExcelCell.CellStyle.ColorIndex = Syncfusion.XlsIO.ExcelKnownColors.White;
e.ExcelCell.CellStyle.IncludeBorder = true;
e.ExcelCell.BorderAround();
}
Also, we have modified the sample with your suggestion and this code snippets and the same can be downloaded from the following link.
Sample: http://www.syncfusion.com/downloads/support/directtrac/118321/groupdroparea1_(2)-927697222.zip
Please let us know if you need further assistance.
Regards
Hello there,
I am trying to get the same result but using ASP. Net Core. Can you please give me a hint about it.
Thanks
Jair
public ActionResult ExportToExcel(string GridModel)
{
ExcelExport exp = new ExcelExport();
var DataSource = order;
GridProperties gridProp = ConvertGridObject(GridModel);
GridExcelExport excelExp = new GridExcelExport();
excelExp.IsAutoFit = false;
excelExp.FileName = "Export.xlsx";
excelExp.Excelversion = ExcelVersion.Excel2010;
excelExp.Theme = "flat-saffron";
return exp.Export(gridProp, DataSource, excelExp);
} |
public ActionResult ExportToExcel(string GridModel)
{
ExcelExport exp = new ExcelExport();
var DataSource = order;
GridProperties gridProp = ConvertGridObject(GridModel);
GridExcelExport excelExp = new GridExcelExport();
excelExp.IsAutoFit = true;
excelExp.FileName = "Export.xlsx";
excelExp.Excelversion = ExcelVersion.Excel2010;
excelExp.Theme = "flat-saffron";
return exp.Export(gridProp, DataSource, excelExp);
} |