I would like to customize the export
a) I would like exclude one of the columns from the original XamDataGrid
b) I would like to have specific numeric columns formatted "Scientific" like if I select cell/column in Excel and set number formatting to Scientific.
I am trying to handle exporter's CellExporting event, but not exactly knowing what to change currently without success
Thanks in advance.
Hello Justin,
To get Excel to format cells as a string as well as apply your custom formatting, I would first recommend handling the CellExported event of the DataPresenterExcelExporter. This event fires just after the cell has exported, but before it begins exporting another one.
In the event handler, you can check the field by calling if(e.Field.Name.Contains(“FieldName”)) and if it is a match, you can call e.CurrentWorksheet.Rows[e.CurrentRowIndex].Cells[e.CurrentColumnIndex].Value and set that as a string. You can nest the if-statements to check the value to determine whether you want to put it in km or m as well, through a nested if-else statement.
I have attached a sample application demonstrating the above.
Please let me know if you have any other questions or concerns on this matter.
Sincerely,AndrewDeveloper Support Engineer IInfragistics Inc.www.infragistics.com/support
Hi Andrew,
Thanks for you sample, it works correctly.
I can format numbers now. However I have a special column (originally number) what I want to format in a complete custom way, say with metrics like
- number: 100 -> 100.0 m
- number: 2500 -> 2.5 km
I found my solution, but I think it is not perfect. I convert my number to the required displayable string, then insert \'s into this string to escape format meaining chars to prevent Excel to interpret them, then set the FormatString to this string. The visual effect is great, however the column in Excel is still numeric with a custom baked constant formatting what is exactly what I set.
It would be better if this column have the 'Text' datatype in Excel. How can achieve this? (The e.Field.DataType seems to be writable, but I think it's write is ignored.
Thanks in advance
Just checking in, did you have any other questions or concerns on this matter?
To exclude one of your columns from the original XamDataGrid, I would recommend setting the column’s visibility to Collapsed in the event handler that you are exporting the cell in. There are other ways of doing this, but most will create a blank column where that one would have been. To make it visible in the XamDataGrid again, just set the visibility of the column to Visible after the export is done.
For the numeric columns being formatted to scientific, I would recommend setting the e.FormatSettings.FormatString if e.Field.DataType == double or int. You can set the format string to be in scientific notation. Below is a link to an MSDN article about format strings.
FormatString Article: http://msdn.microsoft.com/en-us/library/0c899ak8(v=vs.110).aspx
I have attached a sample application to demonstrate the above.