Hi,
I'm having a problem with the formatting of currency during the export to excel. I'm using version 13.2 of the controls.
I want the column values to be formatted as "£#,##0.00" however it formats it as "$#,##0.00" when it gets to excel.
I created a simple class
Public Class Data Public Property Price As Double End Class
Public Class Data
Public Property Price As Double
End Class
Then create a list of about 10 numbers using this class, bound the list to the grid and then exported the grid to excel.
On the initializeColumn event I was setting the column format as below.
Private Sub UltraGridExcelExporter1_InitializeColumn(sender As Object, e As Infragistics.Win.UltraWinGrid.ExcelExport.InitializeColumnEventArgs) Handles UltraGridExcelExporter1.InitializeColumn e.ExcelFormatStr = "£#,##0.00" End Sub
Private Sub UltraGridExcelExporter1_InitializeColumn(sender As Object, e As Infragistics.Win.UltraWinGrid.ExcelExport.InitializeColumnEventArgs) Handles UltraGridExcelExporter1.InitializeColumn
e.ExcelFormatStr = "£#,##0.00"
End Sub
When I view the exported spreadsheet the numbers are formatted "$#,##0.00"
If I try it with "€#,##0.00" it will format it using the €. It seems to not like £ any more.
Your help will be greatly appreciated.
kind regards,
Nathan
I've attached an example project.
Nathan,
I ran your sample application and it worked fine for me. It looks like you are doing everything you need to do to get the currency symbol that you want. You are handling the InitializeColumn event of the ExcelExporter and then setting the ExcelFormatStr property of the Column. I have attached the output file that I generated with your application. Is there some setting on your machine that is causing the Excel file to default to United States currency?
Hi Nathan,
redox said:I only posted the two excel files to demonstrate the different results using different versions of the Infragistics controls.
Yes, I get that. :)
I looked at the files and I can see that in one there is no Format applied to the cells and in one there is. So clearly the format is not being written to the file (or not being written correctly). But without a sample, that doesn't tell us why it's happening.
redox said:I've tried your project and it still provides the incorrect format. :( I've also installed the latest Infragistics service pack and no change.
Okay, so that seems to indicate that it's some other factor, like something on the machine.
redox said:It's not a regional setting as our client machines would have to have changed at the same time, plus why would it work fine with an earlier version of the control set on the same machine? I did change my regional settings to the US as a test but it made no difference.
The version issue doesn't necessarily rule out a problem with regional settings. There could be an issue where the new version is comparing the format to the current machine settings and then not exporting the format if it's the same. Of course, since you are saying that the problem occurs with two different regional settings, that's probably not related.
redox said:Your project was with VS2010, have you ran the same in VS2013?
I don't have VS2013 to test with, but I seriously doubt that's the issue. The version of Visual Studio should not make a difference, only the framework matters. My samples is using CLR4, and it will use CLR4 no matter what version of VS you are running. But I will ask around and see if someone in Developer Support has a machine with VS2013 they can test on, just to be sure.
In the mean time, let's try another test. I am attaching another sample that just creates a Workbook and exports to Excel without using the WinGrid or the ExcelExporter. If this one works, then we know something in the Exporter is the problem if it does not, then we know for sure the problem is specific to the machine.
Hi Mike,
I hope you had a good weekend. Thanks for persevering with this.
I’ve tried your code but it still doesn’t format it correctly.
I tried again bypassing the Infragistics libraries using the following code and it formatted both cells with the £.
Dim ex As New Microsoft.Office.Interop.Excel.Application ex.Visible = True Dim ws As Excel.Worksheet ex.Workbooks.Add() ws = ex.ActiveSheet Dim r As Excel.Range r = ws.Range("A1") r.NumberFormat = "$#,##0.00" r.FormulaR1C1 = 100 r = ws.Range("A2") r.NumberFormat = "£#,##0.00" r.FormulaR1C1 = 200
Dim ex As New Microsoft.Office.Interop.Excel.Application
ex.Visible = True
Dim ws As Excel.Worksheet
ex.Workbooks.Add()
ws = ex.ActiveSheet
Dim r As Excel.Range
r = ws.Range("A1")
r.NumberFormat = "$#,##0.00"
r.FormulaR1C1 = 100
r = ws.Range("A2")
r.NumberFormat = "£#,##0.00"
r.FormulaR1C1 = 200
I ran a macro on Excel and set the cell to format style currency. It displayed as £. The macro code showed setting the number format to $#,##0.00 will set format it with £.
If I change the Example project and format the cell as “"\£#,##0.00"” then it will work.
Something is different between using the Infragistics libraries and communicating to Excel direct. Whatever it is seems to be getting wrapped up in a deployment as the client gets the same issue. I’ve tried installing the test app on a clean test machine and it had the same issue. I’ve added the installer files for you to try if you can. It adds a shortcut to the desktop.
Have you tried testing this with your settings set to UK?
Again, thanks for your assistance. It's much appreciated.
I am starting to wonder if maybe there is a misunderstanding here in terms of what the expected Excel file should look like.
redox said:I tried again bypassing the Infragistics libraries using the following code and it formatted both cells with the £.
I'm confused by this. You are saying that when you run this code, which uses Interop, the results you get are that both cells are formatted using the Pound ("£") and not the Dollar ("$") sign. Is that correct?
And it further implies that those are not the results you are getting when you use the Infragistics Excel engine. But that would be correct. If you explicitly set a format (as I have done in my sample), then the format should be honored. If Interop is not honoring it, then that seems like a problem with the Interop behavior.
Just to further clarify, when I run my sample (under American English settings), the resulting Excel file displays as follows:
£123.45$123.45
The first cell display with a Pound ("£") and the second with a Dollar ("$") sign. That's the behavior I have been getting all along, and it is what I expected. I had someone in Developer Support try it out while running under English (UK) settings and they get exactly the same results.
So are are you saying you are getting the same results, but you believe those results are wrong?
Or are you getting different results?
Mike Saltzman said:I'm confused by this. You are saying that when you run this code, which uses Interop, the results you get are that both cells are formatted using the Pound ("£") and not the Dollar ("$") sign. Is that correct?
Yes. The interop code will produce “£” for both values. However Excel only sees the first one as a Currency format, the second it sees as a custom format.
If I want to format it with a “$” the formatting would need to use "[$$-409]#,##0.00". Excel would see this as a currency format too. I mean that when you select a cell in Excel the ribbon shows the current format of that cell i.e.Currency.
When you record a macro in Excel these are the formatting values it uses to give the results. The interop results and the Excel macro results are identical.
Sub Macro1()'' Macro1 Macro' Macro recorded 27/01/2014 by VMOFFICE2003' ' Range("B2").Select ActiveCell.FormulaR1C1 = "100" Range("B2").Select Selection.NumberFormat = "$#,##0.00" Range("B3").Select ActiveCell.FormulaR1C1 = "200" Range("B3").Select Selection.NumberFormat = "£#,##0.00" Range("B4").Select ActiveCell.FormulaR1C1 = "300" Range("B4").Select Selection.NumberFormat = "[$$-409]#,##0.00" End Sub
Sub Macro1()'' Macro1 Macro' Macro recorded 27/01/2014 by VMOFFICE2003'
' Range("B2").Select ActiveCell.FormulaR1C1 = "100" Range("B2").Select Selection.NumberFormat = "$#,##0.00" Range("B3").Select ActiveCell.FormulaR1C1 = "200" Range("B3").Select Selection.NumberFormat = "£#,##0.00" Range("B4").Select ActiveCell.FormulaR1C1 = "300" Range("B4").Select Selection.NumberFormat = "[$$-409]#,##0.00" End Sub
I’ve tried this on 5 different machines, two of them being client machines (configured by different IT providers). All UK configured. The excel versions were 2003, 2010, 2013. All gave the same result.
Interop Results:
Format
Result
What Excel thinks the formatting is.
"$#,##0.00"
£
Currency
"£#,##0.00"
Custom
"[$$-409]#,##0.00"
$
Mike Saltzman said: And it further implies that those are not the results you are getting when you use the Infragistics Excel engine. But that would be correct. If you explicitly set a format (as I have done in my sample), then the format should be honored. If Interop is not honoring it, then that seems like a problem with the Interop behavior.
When I use the Infragistics Engine I get the following:
I was expecting the formatting to be honoured too, but that’s not what I’m experiencing :(
Mike Saltzman said:The first cell display with a Pound ("£") and the second with a Dollar ("$") sign. That's the behavior I have been getting all along, and it is what I expected. I had someone in Developer Support try it out while running under English (UK) settings and they get exactly the same results.
When you Developer has the UK settings, when he chooses the currency format in the Excel UI (the application) does it default to £. If he records a macro in Excel setting a cell to the format of Currency and it does use the £, what does the macro say the format is?
None of this makes much sense I must admit.
Kind regards
I have investigated your issue and it seems that is caused by the UK settings on your machine. Specifically when the CurrentCulture of the application uses CurrencySymbol different than “$”, when you export to excel that CurrencySymbol is always replaced with “$” - in your case the CurrecncySymbol is "£" and that is why it is beeing replaced with "$". To be able to track this issue I have created a support ticket for you in our internal tracking system with ID: CAS-130259-G3G5B6. So I will update you for the progress of this matter trough the mentioned case.
Fantastic, it works a treat. Thanks you.
Mike,
Great news and the workaround works as well! Thanks for the prompt response, another Happy customer.
Paul
Paul said: A workaround or fix is urgently required.
A workaround or fix is urgently required.
Hi Paul, try using "\£#,##0.00" as a temp fix. Excel will see it as custom but at least it has the correct currency.
Mike Saltzman said: Hi, I have been informed that the bug is fixed internally and the fix will be available in the next service release, which is due at the end of February. Infragistics Product Service Releases Schedule - www.infragistics.com
I have been informed that the bug is fixed internally and the fix will be available in the next service release, which is due at the end of February.
Infragistics Product Service Releases Schedule - www.infragistics.com
Thanks Mike for the update.
Just to support what redox is experiencing, I have found that since upgrading to 13.1.20131.2095 Infragistics4.Documents.Excel.v13.1 when exporting to Excel on any platform that is configured for UK settings, I am now experiencing the same result.
My code (VB.NET VS2010) is using the excelExporter_CellExported event and applying cell format as follows:-
Dim tmCF As IWorksheetCellFormat = e.CurrentWorksheet.Rows(e.CurrentRowIndex).Cells(e.CurrentColumnIndex).CellFormat
tmCF.FormatString = "£#,##0.00;-£#,##0.00;£0.00"
The resultant cells in Excel display as $ Currency amounts and have a "Custom" format as follows: $#,##0.00;-$#,##0.00;$0.00
This code was working fine and exporting as £ prior to the upgrade to the service pack. I have now deployed this version of the assemblies and confirm that the deployed platforms are also experiencing this effect.
Many thanks