When using a writetable to write a table file containing data in datetime format to Excel, the saved datetime data in Excel is not in the same format as the datetime data

5 次查看(过去 30 天)
The table data is as follows:
Use the following writetable function code to save data to Excel,the exported result is shown in the following figure:
The time display is incomplete.
How to set the exported time format to be the same as the original data?
writetable(T, filePath);

采纳的回答

Cris LaPierre
Cris LaPierre 2025-4-9
编辑:Cris LaPierre 2025-4-9
For Excel files, writetable writes table variables containing datetime arrays as Excel dates. The time data is still all there, but Excel applies its own formatting to dates. You will need to set the display format in Excel using their settings to see the same details.
  2 个评论
HCH
HCH 2025-4-10
This method is effective.You are truly an expert in this field!
I have obtained the required custom format by following the prompts in the above answer and the steps 1, 2, and 3 in the image below:
But can similar or other settings be made directly in the code to make the exported time in Excel conform to the above format.
Because this time format is directly saved to Excel in other software, how can Matlab achieve such functionality?

请先登录,再进行评论。

更多回答(1 个)

Thorsten
Thorsten 2025-4-9
Try
writetable(T, filePath, Encoding="ISO-8859-15", DateLocale="en_US");

产品


版本

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by