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!