xlswrite — Write numeric, logical, string, character, or cell data to Excel-compatible spreadsheet files.

xlswrite provides MATLAB's legacy spreadsheet export forms for older scripts. It writes an OOXML workbook payload for .xlsx and legacy .xls filenames, accepts worksheet and range selectors, preserves supported cells in workbooks previously created by RunMat xlswrite, and returns status/message outputs when requested.

Syntax

status = xlswrite(filename, A)
status = xlswrite(filename, A, sheetOrRange)
status = xlswrite(filename, A, sheet, range)
status = xlswrite(filename, A, sheet, range, '-basic')
[status,message] = xlswrite(filename, A)
[status,message] = xlswrite(filename, A, sheetOrRange)
[status,message] = xlswrite(filename, A, sheet, range)
[status,message] = xlswrite(filename, A, sheet, range, '-basic')

Inputs

NameTypeRequiredDefaultDescription
filenameStringScalarYesSpreadsheet file path.
AAnyYesNumeric, logical, string, character, or cell data to write.
sheetOrRangeAnyYesWorksheet name/index or Excel A1 range start.
sheetAnyYesWorksheet name or one-based worksheet index.
rangeStringScalarYesExcel A1 range start or range.
modeStringScalarNo"basic"Legacy '-basic' compatibility flag.

Returns

NameTypeDescription
statusLogicalArrayTrue when the spreadsheet was written successfully.
messageAnyDiagnostic struct with message and identifier fields.

Returned values from xlswrite depend on how many outputs the caller requests.

Errors

IdentifierWhenMessage
RunMat:xlswrite:InvalidArgumentArgument list does not match supported xlswrite call forms.xlswrite: invalid argument
RunMat:xlswrite:FilenameFilename is invalid or cannot be normalized.xlswrite: invalid filename
RunMat:xlswrite:RangeRange specification is malformed or exceeds worksheet limits.xlswrite: invalid range

How xlswrite works

  • xlswrite(filename, A) writes A to the first worksheet starting at A1. If the filename has no extension, .xlsx is appended.
  • xlswrite(filename, A, sheet) selects a worksheet by name or one-based numeric index.
  • xlswrite(filename, A, range) writes to an A1-style range start such as "B2" on the default worksheet.
  • xlswrite(filename, A, sheet, range) combines worksheet and range selection.
  • When the destination workbook already exists and was created by RunMat xlswrite, xlswrite preserves supported existing worksheets and cells outside the overwritten range.
  • Existing unmarked Excel workbooks are rejected instead of being flattened into RunMat's minimal workbook representation; this avoids silently discarding formulas, macros, styles, charts, images, or workbook metadata.
  • Numeric sheet selectors are one-based worksheet ordinals. Missing ordinal sheets are created as SheetN placeholders so later xlsread(filename, N, ...) calls address the same worksheet.
  • Numeric, sparse, logical, string, character, and heterogeneous cell inputs are supported. Cell contents must be scalar spreadsheet values.
  • A1 ranges may use absolute markers such as $B$2:$C$3; malformed range endpoints are rejected.
  • The legacy '-basic' mode flag is accepted as a no-op because RunMat writes spreadsheets directly rather than using Excel COM automation.
  • status = xlswrite(...) returns true on success. [status,message] = xlswrite(...) captures write failures as false plus a diagnostic struct with message and identifier fields.

Does RunMat run xlswrite on the GPU?

xlswrite performs file I/O and spreadsheet serialization on the CPU. It is not fusible and does not call acceleration provider hooks.

GPU memory and residency

xlswrite consumes host-side file data. gpuArray inputs are gathered before writing; outputs are CPU-resident status/message values.

Examples

Write a numeric matrix

status = xlswrite('measurements.xlsx', [1 2 3; 4 5 6]);

Write to a named worksheet and range

status = xlswrite('measurements.xlsx', {'Voltage', 1.5, true}, 'Data', 'B2');

Capture a failure message

[status, message] = xlswrite('out.xlsx', 1+2i);
if ~status
    disp(message.message)
end

Using xlswrite with coding agents

Open a RunMat example with live inputs, then ask the agent to explain how xlswrite changes the result.

Run a small xlswrite example, explain the result, then change one input and compare the output.

FAQ

Does xlswrite use Microsoft Excel?

No. RunMat writes workbook files directly on the host. The '-basic' flag is accepted for compatibility, but COM automation is not used.

What happens with .xls filenames?

RunMat accepts legacy .xls filenames and writes the same OOXML workbook payload used for .xlsx. This keeps old scripts running in RunMat and remains readable by RunMat's content-based spreadsheet reader.

Can xlswrite update an existing Excel workbook created elsewhere?

No. RunMat rejects unmarked existing workbooks rather than rewriting them as a minimal value-only workbook and losing formulas, macros, formatting, charts, images, comments, or metadata.

What should I use for new code?

xlswrite exists for legacy MATLAB compatibility. For new code, prefer writematrix, writecell, or table-oriented export APIs where available.

Open-source implementation

Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how xlswrite is executed, line by line, in Rust.

About RunMat

RunMat is an open-source runtime that executes MATLAB-syntax code blazing on any GPU. It is licensed under the Apache 2.0 license.

  • RunMat automatically optimizes your math for GPU execution on Apple, Nvidia, and AMD hardware. No code changes needed. Simulations that took hours now take minutes.
  • Start running code in seconds. RunMat runs in the browser, on the desktop, or from the CLI. No license server, no IT ticket.

Getting started · Benchmarks · Pricing

Download RunMat

Download RunMat for full performance, or use RunMat in your browser for zero setup.