xlswrite1, Object returned error code: 0x800A03EC at line 142
Mostrar comentarios más antiguos
I am first time using xlswrite1 and tried to not use xlswrite in the for loop, I want to enter the data from a structure, which contains 27 fields, each field has Mx1 Data,
I first tried with xlswrite:
for VariableNum = 1:length(fieldnames(Data))
xlswrite(FileAddress,Data.(ColumnName{VariableNum}),1,[Column{VariableNum} num2str(4)]);
end
Although it took me half minute to complete. the above line worked perfectly fine. and then i tried with the xlswrite1, didn't change any input except adding a few lines to open excel,
Excel = actxserver ('Excel.Application');
File=FileAddress;
if ~exist(File,'file')
ExcelWorkbook = Excel.workbooks.Add;
ExcelWorkbook.SaveAs(File,1);
ExcelWorkbook.Close(false);
end
for VariableNum = 1:length(fieldnames(Data))
xlswrite1(FileAddress,Data.(ColumnName{VariableNum}),1,[Column{VariableNum} num2str(4)]);
end
invoke(Excel.ActiveWorkbook,'Save');
Excel.Quit
Excel.delete
clear Excel
I uses this xlswrite1 in my custom function, which is used in a GUI function. I also changed the second line in xlswrite1 from
Excel=evalin('base','Excel');
to
Excel=evalin('caller','Excel');
as suggested.
for some reason this gave me error indicated in the title.
Respuesta aceptada
Más respuestas (1)
Austin Bond
el 8 de Oct. de 2018
Editada: Austin Bond
el 8 de Oct. de 2018
So I recently encountered the same error while using the xlswrite1.m function
Error using COM.Excel_Application/Range Error: Object returned error code: 0x800A03EC
It turns out there is a bug in the xlswrite1.m function that has to due with converting the column number into a column letter. For example, I was exporting data that had 684 columns, which would correspond to a column LETTER 'ZH'.
The xlswrite1.m function I have uses the functions:
s = dec2base27(d) d = base27dec(s)
to convert column number to column letter. The problem is this algorithm fails for column letters "ZA -- ZZ".
The solution is pretty simple (NOTE: SEE ATTACHED .M FILE):
function range = calcrange(range,m,n) ... ... ... LINE 260: % lastcol = dec2base27(base27dec(firstcol)+n-1); % DELETE THIS LINE OF CODE!!! THIS IS WHERE THE ERROR IS
% THIS IS THE SOLUTION TO THE PROBLEM % - Basically just use MathWorks canned functions from the xlswrite.m function, specifically calcrange.m % columnNumber.m - xlswrite1.m will need access to these (whether in the main body of the script, same directory, or added to the path) % columnLetter.m - xlswrite1.m will need access to these (whether in the main body of the script, same directory, or added to the path)
%ANSWER IS HERE!!! RIGHT BELOW!!!
lastcol = columnLetter(columnNumber(firstcol)+n-1); % Construct last column. ADD THIS LINE OF CODE
Categorías
Más información sobre Spreadsheets en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!