FUNCTION REFERENCE
xlswrite
Write a matrix or cell array to a spreadsheet (legacy form).
Write a matrix or cell array to a spreadsheet (legacy form).
Syntax
xlswrite('book.xlsx', A)Syntax
xlswrite('book.xlsx', A, sheet)Syntax
xlswrite('book.xlsx', A, 'B2:D5')Syntax
xlswrite('book.xlsx', A, sheet, 'B2')Syntax
status = xlswrite(...)Writes an .xlsx workbook (a name without an extension gets .xlsx). A is a numeric, logical, character vector, string or cell array; cells of a cell array hold real scalars, text or empty values. sheet is a sheet name or 1-based index ('' or omitted: the first sheet); a sheet that does not exist is added (an index past the last sheet adds sheets named Sheet1, Sheet2, ...). A range that is one cell is the top-left corner; a rectangle clips A to its size. A single text argument containing ':' is a range on the first sheet. An existing workbook keeps its other sheets and the cells outside the written area. NaN, Inf and empty values clear their cells. status is true when the file was written.
Example
xlswrite('book.xlsx', magic(3)) % 3x3 block at A1 of Sheet1Example
xlswrite('book.xlsx', {'x', 'y'; 1, 2}, 'Data', 'B2') % header row and values on sheet DataDifferences from MATLAB: No Excel automation: only .xlsx is written (not .xls, .xlsm or .xlsb). Updating an existing workbook keeps cell values only: formatting, formulas, charts, merged cells and defined names are not kept. No message output and no "Added specified worksheet" warning. A rectangle larger than A leaves the extra cells as they were instead of filling #N/A.
These are the engine’s help pages. Each page keeps its compatibility notes. File operations are unavailable in the browser.