fopen and xlswrite error
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
fod = fopen(outputfile,'w');
fprintf(fod, '%s \t%s \t%s \t%s \t%s \t%s', 'WS Corr 10m', 'WS Corr 21m', 'WS Corr 72m', 'WS Corr 138m', 'length', 'slopelength');
inputdata_c1=xlsread(output_c1,'C2:C442');
xlswrite(outputfile, inputdata_c1, 'A2:A442');
with this code I get the error, described below
Error using xlswrite (line 220)
Invoke Error, Dispatch Exception:
Source: Microsoft Excel
Description: excel cannot open the file '.xlsx' because the file format or file extension is not valid
Help File: xlmain11.chm
Help Context ID: 0
I also cannot open the created file.
0 commentaires
Réponses (2)
David Sanchez
le 4 Sep 2013
close the file before attempting the its opening:
fod = fopen(outputfile,'w');
fprintf(fod, '%s \t%s \t%s \t%s \t%s \t%s', 'WS Corr 10m', 'WS Corr 21m', 'WS Corr 72m', 'WS Corr 138m', 'length', 'slopelength');
fclose(fod);
xlswrite(outputfile, inputdata_c1, 'A2:A442');
What is the value of your output_c1?
Image Analyst
le 4 Sep 2013
Why are you creating the xlsx file with fopen(), only to use xlswrite() later to do the same thing (just to copy & paste column 3 of the input spreadsheet to column 1 of the output spreadsheet)? Why not just create the "WS Corr 72m" column in xlswrite() right from the start? Also, you are creating a text file with 6 column headers and then trying to add only 1 column, not 6 column, to the workbook file. Why do you have 6 column headers with only 1 column of data? Whatever you do with xlswrite will blow away what was there before, that is assuming you closed the file with fclose. Anyway, the source of your error is that you did not close the file with fclose() before you called xlswrite(). Or possibly you have an old version of Excel that doesn't understand the .xlsx file format and extension. But like I explained, that won't be all you need to fix.
2 commentaires
Image Analyst
le 5 Sep 2013
I'm not 100% sure if it blows it away or not - the help doesn't say so I'd have to check. Regardless, you can create the whole thing in one single call to xlswrite() if you just construct your cell array correctly to begin with. Something like (untested)
ca(1,1) = {'WS Corr 10m'};
ca(1,2) = {'WS Corr 21m'};
ca(1,3) = {'WS Corr 72m'};
ca(1,4) = {'WS Corr 138m'};
ca(1,5) = {'length'};
ca(1,6) = {'slopelength'};
[rows, columns] = size(inputdata_c1);
ca(2:rows+1, 1:columns) = inputdata_c1
xlswrite(filename, ca, 'A1');
Voir également
Catégories
En savoir plus sur Spreadsheets dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!