How to add rows to a blank table, created by an excel import which only contains headers
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Ali
le 15 Fév 2024
Réponse apportée : Mathieu NOE
le 15 Fév 2024
I've created an excel sheet with contains 1 row of just headers.
when using the
readtable("scriptTable.xlsx")
it created an empty table of size 0x7 (7 being the number of columns with headers)
however when i populate a row in excel and import it, i do indeed get a 1x7 table with the headers correctly set but the aim of this script is to populate this table programmatically.
I cannot get any of the add row functions commonly suggest online to add a row to the table of size 0x7.
is there a correct way to add a row in this case? or can I import it in a specifc way (I do not want to force a 'blank' row from within excel.
if isfile("scriptTable.xlsx")
T = readtable("scriptTable.xlsx","Sheet", "Artifacts",'PreserveVariableNames', true);
welcomePrompt;
else
disp("File does not exist")
end
(the excel sheet is nothing complex, just a single row of 7 headers, firstname, surname, dob etc)
1 commentaire
Réponse acceptée
Mathieu NOE
le 15 Fév 2024
hello
why not this ? I simply used readcell to get the variable names from the excel file then populated the table (tehn you could save it to another excel file
TXT = readcell('DEMO1.xlsx'); % get the variable names (header line)
sz = [4 size(TXT,2)];
data = rand(sz); % populate with data
%create the table
T = array2table(data,'VariableNames',TXT)
0 commentaires
Plus de réponses (0)
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!