File Exchange

image thumbnail


version (3.7 KB) by Brett Shoelson
Writes data to multiple ranges of existing Excel file.


Updated 15 Oct 2004

View License

Uses ActiveX commands to write data_n into range_n in an existing Excel spreadsheet. Inputs (excluding fileloc and promptforsave) must be paired.

As of 10/04 update, you may provide the target range (upper left cell to lower right cell) OR just the upper right cell. If the range is specified, the function will verify that the corresponding data block is the correct size, and give an error if not. (This may be useful for error checking, for instance.) If only the upper left cell is provided, write2excel will now compute the target range.

Additionally, you may now specify cells by address (eg., 'H3') OR row, column (eg, '[3,8]').

SEE ALSO: readfromexcel

Cite As

Brett Shoelson (2021). write2excel (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (21)

xiaoyu he


Thank you for the excellent code!


and one more thing: is there a way to give input information regarding the sheet one wants to be written to?


Dear Brett,

I know excel is evil and doesn't implement the NaN standard, but is there a way to get your program to write something sensible, like "-" or ".." to a cell when the data array has an NaN?

Right now it writes 65535 for me, which is far to close to a real number to be helpful.

Cheers and thanks for the great coding,

Pete sherer

Why do I get this error message?

??? Error using ==> Write2Excel at 157
Sorry...unable to open file ./loss_summary_v11_IEDv11_20090827_1438.xls

I checked the file path, and the file exists.
K>> exist(fileloc,'file')
ans =



mm pp

R. Pelaez

Thanks a lot for your work.

Ruoyu Cheng

It can be further improved if multiple sheets can be writen by just calling this function once as to function 'readfromexcel'. Thanks for this excellent work!


It's a good method to integrate datas of experiment to a computing software

Mario Trevino Villegas

Excellent program! Now Im storing thousands of graphs and results in predefined excel files. Excellent to share data with excel users. Thanks a lot!

g w

excellent, just solved my problem! you are the best.

Alex Ross

Very useful command, thx!
The only thing is that when i call this function, the program take like 30 secs tu run it, is there a way it can be faster??

kim l

the file woks fine, but exel exel shoul be a forbiden program for humans! SO this file just can be bad!


Really good file. Very versatile...

Rohan More

This is the best command. It makes life very easy.

Onur Uncu

I use this function all the time. Very handy and simple. Brett did a great job!

Daniel Camp

This is an excellent function. It is one of the essential functions I have used in writing a data aquisition script.

Andre Camenzind

Wonderful - can't believe there wasn't capacity to do this already actually.

Beautiful piece of code

martyn dorey

Very practical routine. Good effort.

Urs Schwarz (us)

excellent add-on for users running in a typical wintel environment! should be included in the basic package.

MATLAB Release Compatibility
Created with R13
Compatible with any release
Platform Compatibility
Windows macOS Linux

Inspired: MATLAB read/write/control Excel, MAT2XLS v2.0

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!