writetable

Writes the values of table object t to file, which is an Excel-compatible file. writetable is available only on Windows systems where Microsoft Excel is installed.

Syntax

R = writetable(t, file)

R = writetable(t, file, 'Sheet', w)

R = writetable(t, file, 'Sheet', w, 'Range', range)

Inputs

t
A table object t, that was created by either the table or readtable functions.
Type: table
file
Name of the file to write. The file extension must be Excel compatible. If file does not exist, a new file is created.
Type: string | struct
w (optional)
Worksheet name or number. If no w is specified, the first worksheet will be used to store the data. Empty worksheet(s) will be added to the right of the last sheet if the worksheet number is less than what is existing in file.
Type: int | string
range (optional)
Specifies the range where the data needs to be written to. If the specified range is greater than what exists in file, additional cells will be created. If there is no range specified, data is added to the top left corner of the worksheet.
Type: string

Outputs

R
A value of 1 indicates success and 0 indicates failure.
Type: integer

Examples

Write an Excel-compatible file with defaults:
t = table({'A',1,2; 'B',3,4; 'C',5,6});
writetable(t, 'test.xlsx')
R = 1
Write an Excel-compatible file with a worksheet name specified:
t = table({'A',1,2; 'B',3,4; 'C',5,6});
writetable(t, 'test.xls', 'Sheet', 'data')
R = 1
Write an Excel-compatible file with a worksheet number and range specified:
t = table({'A',1,2; 'B',3,4; 'C',5,6});
writetable(t, 'test.xls', 'Sheet', 3, 'Range', 'B3:D6')
R = 1