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?

回答(1 个)

Star Strider
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 个评论
ScottPT303
ScottPT303 2015-6-30
Thanks the response. Doing the formatting in Matlab after pulling the content from excel is what I've been doing so far. My problem is that I'm working with very large data sets and I'd rather do the date/time formatting once in the excel file instead of looping through the dateTimeFixArray in Matlab to format. That way if I have to re-run my Matlab script I don't have to reformat again since its already been done on the excel side.
Maybe Matlab doesn't have this function, but is there any way using xlsread or some other function to import my content as already formatted?
Star Strider
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.

请先登录,再进行评论。

Community Treasure Hunt

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

Start Hunting!

Translated by