Writing cell of dates to Excel file

조회 수: 13 (최근 30일)
John Cruce
John Cruce 2023년 4월 2일
댓글: Adam Drake 2023년 4월 13일
I have a cell of dates (characters - 4700x1 cell) formatted as mm/dd/yyyy. When I attempt to write to an Excel file using xlswrite, it places all the dates in one cell, with line breaks for each backslash. How might I get an Excel file with each date as a separate row within the same column?

채택된 답변

Adam Drake
Adam Drake 2023년 4월 2일
Recommend using writecell and readcell instead. If you can't I will reinvestigate. Ex:
Y = [2014;2013;2012];
M = [01;02;03];
D = [31;30;31];
t = datetime(Y,M,D,'Format','MM/dd/yyyy');
datecells = cellstr(t);
filename = 'text.xlsx';
sheet = 1;
xlRange = 'B1';
writecell(datecells,filename,'Sheet',sheet,'Range',xlRange)
readcell(filename,'Sheet',sheet,'Range',xlRange)
ans = 3×1 cell array
{'01/31/2014'} {'03/02/2013'} {'03/31/2012'}
  댓글 수: 2
Peter Perkins
Peter Perkins 2023년 4월 5일
There's no need to create that cell array, at least in recent versions of MATLAB:
writematrix(t,filename,'Sheet',sheet,'Range',xlRange)
Adam Drake
Adam Drake 2023년 4월 13일
The question was that they already had a cell of dates. I was just providing an example of using writecell. Everything before that was just to set that up.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Spreadsheets에 대해 자세히 알아보기

제품


릴리스

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by