How do you get GridViewSpreadStreamExport (ExportFormat = SpreadStreamExportFormat.Xlsx) to correctly export column formats?

1 Answer 25 Views
GridView
Curtis
Top achievements
Rank 1
Iron
Iron
Veteran
Curtis asked on 14 Aug 2024, 07:35 PM

Hi folks.  There seems to be a lot of questions about this and every answer I could find pointed me at some web solution.  This is Winforms and nothing I've seen so far has been in line with my current issue - so here goes!

WinForms .Net 4.7.2 VB

A simple grid (See gridPIC.png)

3 Columns:

  • Decimal DecimalPlaces = 0  FormatString = {0:N0}
  • Decimal DecimalPlaces = 2  FormatString = {0:N2}
  • Decimal DecimalPlaces = 4  FormatString = {0:N4}

Export property settings:

  • HiddenColumnOption = HiddenOption.DoNotExport
  • SummariesExportOption = SummariesOption.DoNotExport
  • ExportVisualSettings = False


When using ExportFormat = SpreadStreamExportFormat.Csv you can see the integer shows 111, the 2 decimal data shows 222.22 and the four decimal data shows 333.3333 as expected. (See csvPIC.png)

But when using ExportFormat = SpreadStreamExportFormat.Xlsx the results are incorrect (*See ExcelPic.png)

 

I was expecting that the export file would include the format information.  I thought perhaps because I'd set spreadStreamExport.ExportVisualSettings = False that this was the cause but I can flip that to True and the output is identical.

The DATA that gets into Excel IS CORRECT.  It's just not formatting the cells as expected.

Is there any way for spreadStreamExport to output the proper Decimal formatting? 

If yes, can you point me at a sample?  C# is just fine if you folks aren't vb.net users.

 

Thank you all!

Curtis

 

1 Answer, 1 is accepted

Sort by
0
Nadya | Tech Support Engineer
Telerik team
answered on 15 Aug 2024, 02:02 PM

Hello, Curtis,

Thank you for writing. 

Each column in RadGridView has ExcelExportType property which can be used for explicitly setting the data type of the cells in the exported document. In order to change the format of the exported data, you can set the ExcelExportType property of the specific column to Custom and specify the ExcelExportFormatString property with the desired format. 

Dim decimalColumn As GridViewDecimalColumn = TryCast(Me.radGridView1.Columns(2), GridViewDecimalColumn)
decimalColumn.ExcelExportType = DisplayFormatType.Custom
decimalColumn.ExcelExportFormatString = "#,##0"

Please refer to the following article from our online documentation. This property is marked in a yellow note in the Properties section:  Export to Excel with GridViewSpreadStreamExport - WinForms GridView Control - Telerik UI for WinForms

I hope this information helps. If you have any other questions do not hesitate to write back.

Regards,
Nadya | Tech Support Engineer
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Curtis
Top achievements
Rank 1
Iron
Iron
Veteran
commented on 15 Aug 2024, 05:07 PM

Nadya.  Once again, you come through.   This is exactly what I needed.

Plugged this in, made my specific edits and it works flawlessly.  I expected nothing less from Telerik :)

 

Thank you very much!

-C

 

Tags
GridView
Asked by
Curtis
Top achievements
Rank 1
Iron
Iron
Veteran
Answers by
Nadya | Tech Support Engineer
Telerik team
Share this question
or