This is a migrated thread and some comments may be shown as answers.

RadGrid CSV Export trimming trailing spaces

2 Answers 87 Views
Grid
This is a migrated thread and some comments may be shown as answers.
John Cruz
Top achievements
Rank 1
John Cruz asked on 15 Jun 2011, 12:07 AM
Does anyone know why radgrid export to CSV is trimming the trailing spaces from the CSV output and how to work around this issue?


grdExport.ExportSettings.ExportOnlyData = true;
grdExport.ExportSettings.IgnorePaging = true;
grdExport.ExportSettings.OpenInNewWindow = true;
grdExport.ExportSettings.FileName = DateTime.Now.ToString("yyyyMMdd") + filename;
grdExport.MasterTableView.ExportToCSV();

2 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 15 Jun 2011, 09:44 AM
Hello John,

One suggestion is to set the ColumnDelimiter.
aspx:
<ExportSettings FileName="Customers" Csv-ColumnDelimiter="Tab">
</ExportSettings>

Thanks,
Princy.
0
John Cruz
Top achievements
Rank 1
answered on 15 Jun 2011, 10:52 PM
Thanks. I found a solution.

What i did was convert the space to '{space}' before calling grid.MasterTableView.ExportToCsv() then wire a grid exporting event that would replace all the '{space}' symbols back to space. 

  private void ConvertTrailingSpacesOnItemsColumn()
    {
        foreach (DataRow row in ((DataSet)grdExport.DataSource).Tables[0].Rows)
        {
            var invItem = row[@"INVITEM"].ToString();
            row[@"INVITEM"] = invItem.Replace(" ", "{SP}");
        }
    }
 
protected void grdTransaction_GridExporting(object sender, GridExportingArgs e)
    {
        e.ExportOutput = e.ExportOutput.Replace("{SP}", " ");
    }


Thanks,

John
Tags
Grid
Asked by
John Cruz
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
John Cruz
Top achievements
Rank 1
Share this question
or