How to get same xlsread "raw" output whithout using xlsread?
조회 수: 6 (최근 30일)
이전 댓글 표시
Hello,
xlsread is no more recommanded. So what is the correct solution to get exactly the same variable "raw" I was getting when using the following command :
[~, ~, raw] = xlsread('MyExcelFile.xls');
I have tried to use readcell function like this :
raw = readcell('MyExcelFile.xls', 'DateTimeType', 'text');
but that doesn't return me the same result :
- When I was using xlsread, date was returned as text with format 'dd/mm/yyyy', example : '01/01/2014'
- When I use readcell, date is returned as text with the exact same format as the cell in Excel 'dd-mmm-yyyy', example : '01-janv-2014'
I have to get the same result I got with xlsread, regardless of Excel language, regardless of Excel cells date format...
What is/are the command(s) I should use?
Other constraint : The command(s) do(es) not have to use/launch Excel.
Thanks!
댓글 수: 0
답변 (1개)
Walter Roberson
2021년 9월 20일
mask = cellfun(@isdatetime, YourCell);
YourCell(mask) = cellfun(@(DT) datetime(DT, 'format', 'dd/MM/yyyy'), 'uniform', 0);
Now the datetime objects will be reformatted to the style you want.
If you want text, then
mask = cellfun(@isdatetime, YourCell);
YourCell(mask) = cellfun(@(DT) char(datetime(DT, 'format', 'dd/MM/yyyy')), 'uniform', 0);
댓글 수: 6
Walter Roberson
2021년 9월 20일
You might be able to use a 'Range' option to specifically read that line. If not then use
filename = 'MyExcelFile.xls';
opt = detectImportOptions(filename, 'DataTimeType', 'text', 'ReadVariableNames', false);
opt.DataLines = [1 inf];
table2cell(readtable(filename, opt))
참고 항목
카테고리
Help Center 및 File Exchange에서 Spreadsheets에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!