[Help] writetable text alignment and saving pre 0

조회 수: 6 (최근 30일)
Waqar Ali Memon
Waqar Ali Memon 2019년 8월 7일
댓글: Waqar Ali Memon 2019년 8월 7일
Hello Everyone,
I am incurring a little problem on execution of following code
filename='myExcelFile.xlsx';
myTable = cell2table(Dataset, 'VariableNames', header);
writetable(myTable, filename, 'WriteVariableNames', true);
By writing a table to excel, it removes pre 0. I mean it saves 0409 to 409. Is there any way to preserve initial zeros?
Second, can we sort the data in columns as well? For instance, it sorts Text data to flush left and numerical data to flush right. Can we initialize a directon for that?
Any help would be appreciated.
Thank you :-)
  댓글 수: 3
Adam Danz
Adam Danz 2019년 8월 7일
Sometimes there's a glitch in the system that allows for >1 answer to be accepted within a quick window of time but generally only 1 acceptance is allowed. That discussion is here:
Flip a coin or choose Guillaume's since he beat me by <1 minute ;)
Waqar Ali Memon
Waqar Ali Memon 2019년 8월 7일
Yeahhh... Done for both answers :-)
Thank you :-) By the way Guillaume won the toss :-p

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

채택된 답변

Adam Danz
Adam Danz 2019년 8월 7일
"By writing a table to excel, it removes pre 0. I mean it saves 0409 to 409. Is there any way to preserve initial zeros?"
Numerically it makes no difference whether there are leading 0s or not. There are settings within Excel (see link) to allow for leading zeros. Alternatively you can convert the numers to strings and write them as strings ('0409', with quotes) but then you'll need to convert them back to numeric for the data to be useful so this would be a poor choice.
"can we sort the data in columns as well? For instance, it sorts Text data to flush left and numerical data to flush right. Can we initialize a directon for that?"
I believe you're asking about right/left justification (not sorting). Please correct me if I'm wrong. Again, that's a setting you can control from excel (see link).
If I'm understanding your questions correctly, none of these issues are controllable from Matlab. The 2 links I shared where among the first links provided by a quick google search.

추가 답변 (1개)

카테고리

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

제품


릴리스

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by