How can I change the decimal separator when exporting to Excel?
조회 수: 108 (최근 30일)
이전 댓글 표시
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
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
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.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Spreadsheets에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!