Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
1725
How to modify cell contents on Excel Export
posted

I'm using an excel exporter on a grid where one of the columns has one value for display purposes that I want to expand with more content detail on export.

First, is there a way to do this?

I've tried hooking the various events (InitializeRow, RowExporting, CellExporting) but can't seem to find a way to set the cell value. I don't get an error when I assign the value to something  like

            e.GridRow.Cells[0].Value = "NEW VALUE";

but the exported value does not change. 

I don't really want to change the base cell value before export, do the export and then change it back if that can be avoided so I must be missing something simple here. 

Thanks

  • 1725
    posted

     I tried changing the text in the CellExported event. The code just does

    e.GridRow.Cells[e.CurrentColumnIndex].Value = "my new text";

    on the cells that I want to modify. In debug is shows that the value property is changed but there is no difference in the resulting xls file.

     

    So, I thought that this might be to late so I moved the code to the CellExporting  event and was able to modify the text in the cell.

    I'm still not able to get what I really am trying to do which is to insert a new line (0x0a) in the text so that the cell shows multiline text. For some reason I'm unable to make that work as they seem to be removed when the xls file is actually written (I'm guessing).

     

  • 44743
    posted

    Try updating the value in the CellExported event. This event is fired after the exporter has written the data to the cell, so any changes you make shouldn't be overwritten again.