How to write and read string (with zero on beginning) in Excel

조회 수: 1 (최근 30일)
Jan
Jan 2016년 11월 24일
답변: Image Analyst 2016년 11월 24일
I need write the string STR='0987654321' to Excel xlsx-file and see read it again from the file to the Matlab. With this command
xlswrite('file.xlsx',{STR});
the first zero is missing in the excel file! So I insert the apostrophe as the first char.
xlswrite('file.xlsx',{['''',STR]});
I can see the string with the zero in Excel file now. But after reading to the Matlab with xlsread, the apostrophe is missing!
[ReadNUM, ReadTXT, ReadRAW]=xlsread('file.xlsx');
After next xlswrite the string lost zero on the beginning in excel file.
xlswrite('file2.xlsx',ReadTXT); OR xlswrite('file2.xlsx',ReadRAW);
Is there any possibility write and read string '0987654321' to/from xlsx-file again and again with Matlab?

답변 (1개)

Image Analyst
Image Analyst 2016년 11월 24일
Your original string in MATLAB doesn't have an apostrophe in front so why do you want one when you read it back from Excel?
Perhaps it depends how the cell is formatted in Excel. If you wrote a string '01234' it might put it in the cell but consider it as a number if the cell format is "General". What happens if you format that cell to be text, either by hand in Excel or with an ActiveX command from MATLAB?

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by