How to add rows to a blank table, created by an excel import which only contains headers
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Mathieu NOE
2024-2-15
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 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Spreadsheets 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!