필터 지우기
필터 지우기

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

조회 수: 108 (최근 30일)
Johannes
Johannes 2024년 3월 28일
편집: Stephen23 2024년 8월 8일
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
  댓글 수: 6
Dyuman Joshi
Dyuman Joshi 2024년 4월 2일
이동: Dyuman Joshi 2024년 4월 2일
You could replace the commas with dots using replace and then save the data.
Stephen23
Stephen23 2024년 4월 2일
편집: Stephen23 2024년 8월 8일
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 date 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 (if you really must: the only practical approach is to convert the numeric data to text).
"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 numeric data are displayed in Excel.

댓글을 달려면 로그인하십시오.

답변 (2개)

Alexander
Alexander 2024년 4월 2일
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
Johannes 2024년 4월 2일
편집: Johannes 2024년 4월 2일
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

카테고리

Help CenterFile Exchange에서 Spreadsheets에 대해 자세히 알아보기

제품


릴리스

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by