how to save in specific row and column with this code in excel?

15 vues (au cours des 30 derniers jours)
sandy
sandy le 13 Août 2013
Commenté : NoYeah le 20 Nov 2020
hi..below code is to fetch files and append in separate excel file..i done..but existing is getting saved from A1(first row),but i need to write my data's from 3rd,(starts form C1)..I couldnt bring it..help with this code..
pathName = 'F:\test folder\run\';
fileList = dir(fullfile(pathName, '*.run'));
out = fopen(fullfile(pathName, 'append.xlsx'), 'w');
for k = 1:numel(fileList)
s = fileread(fullfile(pathName, fileList(k).name));
fwrite(out, s,'char');
end
fclose(out);

Réponses (2)

David Sanchez
David Sanchez le 13 Août 2013
To write in a precise cell within a xls file, use the built-in function xlswrite, which gives that feature.
Example from documentation:
Write mixed text and numeric data to testdata2.xls, starting at cell E1 of Sheet1:
d = {'Time','Temperature'; 12,98; 13,99; 14,97};
xlswrite('testdata2.xls', d, 1, 'E1')
  1 commentaire
sandy
sandy le 13 Août 2013
I AGREE...but my question is..need to store without overwriting.. i tested with 3 .run files(input).i need to append it one by one...if i use xlswrite..its overwriting..only last file data's alone getting saved. below are my values in each file
file01.run: SAMPLE_20120807_1806 0 +1.122117E+1 +7.190077E+0 +1.460343E+1 file02.run: SAMPLE_20120807_1816 0 +1.122317E+1 +7.150077E+0 +1.460983E+1 file03.run: SAMPLE_20120807_1826 0 +1.132117E+1 +7.190077E+0 +1.430343E+1
i need to append this to single excel file from A3(ROW).IS IT POSSIBLE?

Connectez-vous pour commenter.


David Sanchez
David Sanchez le 13 Août 2013
Instead of writing values one at a time on each iteration, you should better save the values in an array and then write the whole array into the *.xls file. It's much faster than writing to the .xls on each iteration.
  3 commentaires
David Sanchez
David Sanchez le 13 Août 2013
From your code, it is not easy to see what your variable(s) will be. I would go to
doc xlswrite
to see the full documentation and some examples. I am sure you will adapt them to your needs.
My example:
y = zeros(3); % initialization of final matrix
for k=1:3
x=rand(3,1); % array random numbers
y(:,k) = x; % copy previous array to kth column of the matrix
end
xlswrite('my_xls.xls',y,'B2'); % write the matrix to xls file, starting in cell 'B2'.
NoYeah
NoYeah le 20 Nov 2020
useless

Connectez-vous pour commenter.

Community Treasure Hunt

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

Start Hunting!

Translated by