xlsread not extracting formatted content
3 次查看(过去 30 天)
显示 更早的评论
I'm trying to use the xlsread function to extract a column of dates/times in a custom format. The original date format of the cell is "M/D/YY H:MM AM/PM". My custom format is "DD MMM YYYY HH:MM:SS.000" (because this is the format that STK/Matlab Object-model recognizes).
[~,dateTimeFixArray,~] = xlsread(filename,'D2:D1000')
When I use xlsread to import the data as a str I get an array in the original format instead of my custom format. Is there any way to force xlsread to extract my custom format instead?
0 个评论
回答(1 个)
Star Strider
2015-6-30
The xlsread function uses Excel to read the contents of the file. If you want the dates and times in your custom format, first convert them to MATLAB date numbers with datenum, then convert them to your custom date strings with datestr.
2 个评论
Star Strider
2015-6-30
My pleasure.
Not to my knowledge. The easiest way might be to use the Excel custom date format options and format the date column in every Excel file in the format you want. (You might be able to do that through MATLAB, but that could involve some significant ‘ActiveX’ programming that I’ve only read about in a few threads here. I’ve no experience with it.)
If I wanted to export the date in a particular format, I would do it in Excel and then not bother with the date string format conversions in MATLAB.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Spreadsheets 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!