How to overwrite an excel file, matlab 2018?
Show older comments
I need to overwrite an excel file each time write table function runs but I don’t have Matlab 2020. And I cannot delete the file as I am later using it to be uploaded in my app for creating a table in my app.
How can I solve the problem
4 Comments
Image Analyst
on 25 Dec 2023
So let me see if I have this correct. You have an existing Excel file on disk. You want to read in the existing data into a table, and then overwrite some or all elements of the data table, perhaps even adding columns or rows, then write the new data table back out to the same file. Is that correct?
Muazma Ali
on 25 Dec 2023
Image Analyst
on 25 Dec 2023
Then just call the writetable function over and over again. It will overwrite the existing file.
Muazma Ali
on 25 Dec 2023
Answers (1)
Here is one code if understood your question correctly:
FName = 'Renew_Table.xlsx';
D = array2table(randi(255, 7, 3))
writetable(D,FName,'Sheet',1);
for ii=1:3
D = readtable(FName);
D{:,:} = D{:,:}*ii;
writetable(D,FName,'Sheet',1);
end
D = readtable(FName)
1 Comment
Muazma Ali
on 25 Dec 2023
Categories
Find more on Spreadsheets in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!