I’m trying to figure out how to keep the leading 0’s when exporting data from a grid to Excel, either by manipulating the value of each cell or setting a format for the entire column.
I found several suggestion to add “t” in front of the value, but this doesn’t have any effect.
The only solution I’ve found so far is to add an apostrophe in front of the value, and that works, but I really don’t want the ‘ in the excel file.
Here is one of the code solutions I’ve tried:
protected void btnExport_Click(object sender, EventArgs e)
{
RGData.ExportSettings.FileName = "FileName" + DateTime.Now.ToShortDateString() + "";
RGData.ExportSettings.OpenInNewWindow = true;
RGData.ExportSettings.ExportOnlyData = true;
RGDataExport.ExportSettings.Excel.Format = GridExcelExportFormat.Xlsx;
foreach (GridDataItem item in RGData.MasterTableView.Items)
{
TableCell cell = item["Number"];
if (!string.IsNullOrEmpty(cell.Text))
{
cell.Text = "t" + cell.Text;
}
}
RGData.MasterTableView.ExportToExcel();
}