Borrar filtros
Borrar filtros

Adding data to existing excel

59 visualizaciones (últimos 30 días)
syahdan edy murad
syahdan edy murad el 7 de Jul. de 2018
Respondida: Hazem Kamel el 25 de Jul. de 2024 a las 17:28
Hi, I want to ask a question I want a program where I can add more row data every time I execute this program, but when i execute this code, only row 2 got added, not 3, 4, etc. I want it to stack, every time I run the program
here is the code :
tgl=4;
Jumlah=1;
nama='adawd';
ntgl=3;
nJumlah=3;
nnama='dddd';
A = {'Tanggal','Jumlah Laki-Laki','Nama Video'; tgl,Jumlah,nama};
baru = {ntgl,nJumlah,nnama};
A(end+1,:) = baru;
xlswrite('Masukkan nama file.xls',A);

Respuesta aceptada

Image Analyst
Image Analyst el 7 de Jul. de 2018
You need to use the xlsread() first to determine what the last row of your existing data it. Then use xlswrite's 3rd and 4th arguments to make sure you're writing additional data to the end of the existing data.
  14 comentarios
halawati cm
halawati cm el 30 de Mzo. de 2020
ok, if i have different set of data to write into excel file like this:
data1= [0.1, 0.2, 0.3, 0.4];
data2= [0.5, 0.6, 0.7, 0.8];
data3=[0.9, 0.10, 0.11, 0.12];
the question is:
1-how to write it to the excel file with different set of data?
2-after close the application and run again, how to append the new set of data into the existing excel file without missing the existing data in the file?
tqvm for your response.
Image Analyst
Image Analyst el 30 de Mzo. de 2020
One way to do it would be to first read it in and see what the last row is. Then write to the row below it.
[numbers, strings, raw] = xlsread(filename);
lastRow = size(raw, 1);
nextRow = lastRow + 1;
cellReference = sprintf('A%d', nextRow);
xlswrite(excelFullFileName, data1, 'Sheet1', cellReference);
nextRow = nextRow + 1;
cellReference = sprintf('A%d', nextRow);
xlswrite(excelFullFileName, data2, 'Sheet1', cellReference);
nextRow = nextRow + 1;
cellReference = sprintf('A%d', nextRow);
xlswrite(excelFullFileName, data3, 'Sheet1', cellReference);

Iniciar sesión para comentar.

Más respuestas (1)

Hazem Kamel
Hazem Kamel el 25 de Jul. de 2024 a las 17:28
Check this code. It may help to write and append data in an existing Excel sheet:
A=magic(5);
header={'Hazem', 'Gigi', 'Rita', 'Karim', 'Viola'}
xlswrite('test.xlsx',header);
[number, strings, row] = xlsread('test.xlsx');
lastRow = size(row,1)
nextRow = lastRow+1;
cellReference = sprintf('A%d', nextRow);
xlswrite('test.xlsx', A, 'Sheet1', cellReference);
winopen('test.xlsx');

Categorías

Más información sobre Data Import from MATLAB en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by