Export unigrid data to Excel with customization

Deanna Martens asked on January 29, 2016 20:40

Good afternoon,

I have a uni-grid that I need to export to Excel with a few customization. The datetime field needs to be date only as is displayed by the uni-grid (not how it is in the data source), and ideally the header columns in the Excel file would be bold and autofitted as well. In addition, I have a custom file name for it to be saved with.

So far I can either export the data source data with the incorrect datetime format but the custom file name or use the action menu to export the correct data but with a generic file name. I have not been able to format the header column at all.

Any ideas or suggestions would be appreciated.

Thank you for your time,

Recent Answers

Brenden Kehren answered on February 1, 2016 05:22


You can use the API for exporting any tabular/table data. Check this out:

DataSet ds = getYourDataSetHere();
// formatting the column name to remove some unnecessary characters
foreach (DataColumn dc in ds.Tables[0].Columns)
    dc.ColumnName = dc.ColumnName.Replace("RS_", "").Replace("#", "");

foreach (DataRow dr in ds.Tables[0].Rows)
    // format your date as needed
DataExportHelper eh = new DataExportHelper(ds);
eh.ExportData((DataExportFormatEnum.XLSX, Page.Response);

They key is the DataSet you're sending to the ExportHelper class needs to be formatted in the way you want the output to be. This doesn't happen when you use the out of the box controls.


3 votesVote for this answer Mark as a Correct answer

Deanna Martens answered on February 5, 2016 17:46

Wonderful thank you!

So now that I've got my DataSet formatted correctly, is there a way to make the Excel file that gets created have columns that are autofitted and headers that are bold?


0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.