Clear Filters
Clear Filters

How can I change the decimal separator when exporting to Excel?

173 views (last 30 days)
In my Matlab App (App Designer) I am reading an Excel file to show the data in a UITable. The Excel formatting is european, so the decimal separator is a comma. As Matlab reads the Excel sheet it interprets the comma correctly as separator. The UITable in the app shows only dots instead of commas, but thats fine. I also have some numeric Edit fields that are filled with calculation results, with a dot as decimal separator (as usual in Matlab). So the app surface looks clean and consistent with dots as decimal separators only.
The problem starts with the export of the data in a prepared Excel sheet, thats also in european format:
I would like to keep the dot as separator overall, but it keeps writing different separators in the file. The calculation results from the numeric fields are stored as a number with a dot as separator. But the UITable data is - again - with a comma. First I exported this directly after importing it from the other Excel, as its not changed in the callback. Then I tried to export the Data of the table in reference to app.UITable.Data hoping this would use the dot as separator. This did not work.
I am using the writematrix command
Dyuman Joshi
Dyuman Joshi on 2 Apr 2024
Moved: Dyuman Joshi on 2 Apr 2024
You could replace the commas with dots using replace and then save the data.
Stephen23 on 2 Apr 2024
Edited: Stephen23 on 2 Apr 2024
Your question does not specify the file format, so I will presume XLSX.
"The Excel formatting is european"
That is not how Excel's XLSX formatting works. For numeric data, MS Excel displays the decimal comma/point based on the locale settings of your OS: e.g. if you open an XLSX file on a computer with decimal comma then it will show the numeric data with decimal commas. It can also change the data formats, function names, and many other things to suit the locale: these things are not saved in the XLSX file itself. It is one of the best features of MS Excel.
You will really get yourself confused if you try to save numeric data with a particular decimal character.
"How can I change the decimal separator when exporting to Excel?"
The simple answer is don't. Just save the numeric data as numeric.
And then use your locale settings to change how it numeric data is displayed in Excel.

Sign in to comment.

Answers (2)

Alexander on 2 Apr 2024
Excel uses the operating system defaults. To change this open a file in Excel and click on the windows butten (top left). Go to Excel Options (bottom, 2nd from right) go to advanced, there you should see a checkbox "Deliminter from OS". Uncheck it and put your delimiter in.
To be honest: I never used this option and I don't know whether it's working accoring your intention. I'm working with an old Excel (2007) and an old OS (Win7). Hence, I'm not sure if it's the same in a modern Excel.
Also my Excel is in German. It might be possible, that my translations of the steps above are not perfect.

Johannes on 2 Apr 2024
Edited: Johannes on 2 Apr 2024
I just found my mistake. In the export of the calculation results I combined numeric and text results in one matrix. That's why Excel saved some numbers as text and made it impossible to format it as a number. I separated the text results from the numeric results and exported them individually. Now the decimal separator is uniform over the whole spreadsheet and the numbers are correctly formatted as numbers. So when a user with european system preferences opens the sheet, it's all commas. With US/UK settings it is all dots. That's how it should be. Thank you everyone for your answers and your time




Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!