%% Write Tabular Data to Spreadsheet File
% To export a table in the workspace to a Microsoft® Excel® spreadsheet file, use the writetable function. You can export data from the workspace to any worksheet in the file, and to any location within that worksheet. By default, writetable writes your table data to the first worksheet in the file, starting at cell A1.
% For example, create a sample table of column-oriented data and display the first five rows.

load patients.mat
T = table(LastName,Age,Weight,Smoker);
T(1:5,:)

% Write table T to the first sheet in a new spreadsheet file named patientdata.xlsx, starting at cell D1. To specify the portion of the worksheet you want to write to, use the Range name-value pair argument. By default, writetable writes the table variable names as column headings in the spreadsheet file.

filename = 'patientdata.xlsx';
writetable(T,filename,'Sheet',1,'Range','D1')

% Write the table T without the variable names to a new sheet called 'MyNewSheet'. To write the data without the variable names, specify the name-value pair WriteVariableNames as false.

writetable(T,filename,'Sheet','MyNewSheet','WriteVariableNames',false);

% Copyright 2012 The MathWorks, Inc.