Exporting table data to excel with no headers
53 views (last 30 days)
Show older comments
HI i'm a beginner in matlab and I am having trouble at exporting my data into excel without headers (var 1, var 2, var 3, ...) whenever I use writetable.
I was wondering is their anyway (in general) that I can populate my data into excel without having headers (meaning not even a blank space as a header)? I have nested loops tied above the lines below and it would be so much more convient if I could export the data with no headers every time so I don't have headers cutting off the table above everytime... I'm not sure if there is a way to export with xlswrite or if I can even use it because whenever/however I use that funciton it gives me a message saying "error exporting to excel, exported as csv instead. use writetable instread." My matlab is in basic mode for excel so if I can force writetable to work with no headers that would be beautiful. Thank you, any feeback would be extremely appreciated!
%a bunch of lines above...
for jj = 1:length(impt_rows)
hours_populate(jj) = xlsColNum2Str(impt_rows(jj)+5) %for whatever col num starting on
table_hours_per_emp = table(hours_data_populate(jj))
hours_populate_range = [hours_populate{jj} num2str(ii + 6)] %populate info starting at the 7 th row
writetable(table_hours_per_emp, 'Copy of !Workplan Template 4PM V3.xlsx', 'Sheet', 1, 'Range', hours_populate_range)
end
2 Comments
dpb
on 29 Sep 2019
writetable(table_hours_per_emp, 'Copy of !Workplan Template 4PM V3.xlsx', ...
'Sheet', 1, ...
'Range', hours_populate_range, ...
'WriteVariableNames',0)
Read all the documentation about optional parameters...there may be others you could find of use as well.
Answers (1)
TED MOSBY
on 13 Nov 2024
Edited: TED MOSBY
on 18 Nov 2024
To export data from MATLAB to Excel without headers using‘writetable’, you can use the‘WriteVariableNames’option and set it to‘false’.
for jj = 1:length(impt_rows)
hours_populate(jj) = xlsColNum2Str(impt_rows(jj) + 5);
table_hours_per_emp = table(hours_data_populate(jj));
hours_populate_range = [hours_populate{jj} num2str(ii + 6)];
% Use writetable with 'WriteVariableNames', false
writetable(table_hours_per_emp, 'Copy of !Workplan Template 4PM V3.xlsx', ...
'Sheet', 1, 'Range', hours_populate_range, 'WriteVariableNames', false);
end
You may also use ‘writecell’ for Cell Arrays (MATLAB R2019b or Later):
for jj = 1:length(impt_rows)
hours_populate(jj) = xlsColNum2Str(impt_rows(jj) + 5); % Calculate column
% Create cell array with data
data_to_export = {hours_data_populate(jj)};
% Define the range to start writing to Excel
hours_populate_range = [hours_populate{jj} num2str(ii + 6)];
% Use writecell to export data without headers
writecell(data_to_export, 'Copy of !Workplan Template 4PM V3.xlsx', 'Sheet', 1, 'Range', hours_populate_range);
end
Here is the documentation for both the functions:
0 Comments
See Also
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!