xlswrite

Writes data to file, which is either an Excel-compatible file or a structure returned from xlsopen, with functions defined in omlxlstoolbox. xlswrite is available only on Windows systems where Microsoft Excel is installed.

Syntax

R = xlswrite(file, data)

R = xlswrite(file, data, w)

R = xlswrite(file, data, w, range)

Inputs

file
Name of the file to write or a structure returned as the result of an xlsopen. If file is a filename, the file extension must be Excel compatible. If file is a structure, xlsclose must be called after all the xlswrite operations are complete. If file does not exist, a new file is created.
Type: string | struct
data
Only real matrices are supported, if data is a matrix.
Type: cell | mat | scalar | string
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:
values = {1, 2, 3 ; 'a', 'b', 'c' ; nan, inf, realmax};
headers = {'number','string','other'};
R = xlswrite('test.xlsx', [headers; values])
R = 1
Write an Excel-compatible file with a worksheet name specified:
values = {1, 2, 3 ; 'a', 'b', 'c' ; nan, inf, realmax};
headers = {'number','string','other'};
R = xlswrite('test.xls', [headers; values], 'data')
R = 1
Write an Excel-compatible file with a worksheet number and range specified:
values = {1, 2, 3 ; 'a', 'b', 'c' ; nan, inf, realmax};
headers = {'number','string','other'};
R = xlswrite('test.xls', [headers; values], 3, 'B3:D6')
R = 1
Write an Excel-compatible file with defaults using structure from xlsopen/xlsclose:
values = {1, 2, 3 ; 'a', 'b', 'c' ; nan, inf, realmax};
headers = {'number','string','other'};
file = xlsopen('test.xlsx', 1);
xlswrite(file,  [headers; values], 'sheet1');
xlsclose(file);