Exporting table data to excel with no headers
120 次查看(过去 30 天)
显示 更早的评论
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 个评论
dpb
2019-9-29
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.
回答(1 个)
TED MOSBY
2024-11-13,4:43
编辑:TED MOSBY
2024-11-18,19:54
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Spreadsheets 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!