Issue with writing multiple variable to excel sheet
3 次查看(过去 30 天)
显示 更早的评论
Hi,
I have three interger values and one string. I need to write it to excel sheet. I have tried to concatenate three integers to a single variable but for the strings i cant concatenate.
a=[1 1 1], b={'name'}
How do i write all these variable to the excel sheet to range of A1:D1, D1 should have the string.
I have thousands of similar data to write to excel, so i use xlswrite1, since i dont want matlab to open and close everytime(this happens if is use standard xlswrite) http://www.mathworks.com/matlabcentral/fileexchange/10465-xlswrite1
so in this case if i write xlswrite1 for writing variable 'a' and then xlswrite1 for writing variable 'b' in next line, then i get the error, as the excel sheet is already open.
So is there any alternate way to do the xls writing?
0 个评论
回答(2 个)
Ahmed A. Selman
2013-4-17
It is not practical to write a single line in an excel file, for a large amount of data or inside a long-time running loop. If your task is to do so, then it's natural to take to infinity to finish, no matter the type of the function you've used, because Matlab has to open the excel file when writing to it and close it afterwords.
But you can first concatenate two large matrices within the loop, one for numeric values and the other for string, then write the matrices into the excel file using a single command, that is as:
A=[a1
a2
a3
...]
b={'name1'
'name2'
'name3'
...etc}
then use xlswrite('excelFileName',A,Range)..etc.
0 个评论
Iman Ansari
2013-4-17
Hi
a=[1 1 1];
b={'name'};
xlswrite('New.xlsx',a,1,'A1')
xlswrite('New.xlsx',b,1,'D1')
2 个评论
Iman Ansari
2013-4-17
This works with xlswrite1 too:
a=[1 1 1];
b={'name'};
xlswrite1('New a.xls',a,1,'A1')
xlswrite1('New a.xls',b,1,'D1')
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Spreadsheets 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!