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

1 次查看(过去 30 天)
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?

标签

Community Treasure Hunt

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

Start Hunting!

Translated by