File Exchange

image thumbnail


version (4.82 KB) by Seth Bashford
This provides a simple interface for reading/writing Microsoft Excel files from MATLAB.

1 Download

Updated 06 Jun 2017

From GitHub

View license on GitHub

Why not just use xlswrite()?
When called more than ~3 times, xlswrite() is an expensive function in terms of time. excelMatlab provides a simple, optimized approach to writing Excel files when multiple calls are needed. Moreover, xlswrite() requires a string (such as 'A1:B3') representing the range of cells to write. Programmatically this is inconvenient. excelMatlab requests the row and column number of the upper left cell from which to write.


Open file called fileName and write random matrix to sheet called sheetName. The matrix will be anchored to its top left corner, specified by row 1 and column 5 (cell E1).

fullPathToFile = [pwd(), filesep(), 'fileName'];
myExcel = ExcelMatlab(fullPathToFile, 'w');
data = rand(20);
sheet = 'sheetName';
row = 1;
col = 5;
myExcel.writeToSheet(data, sheet, row, col);
Open file called fileName and read cell G8 from sheet called sheetName.

fullPathToFile = [pwd(), filesep(), 'fileName'];
myExcel = ExcelMatlab(fullPathToFile);
sheet = 'sheetName';
row = 8;
col = 7;
cellRead = myExcel.readCell(sheet, row, col);

Cite As

Seth Bashford (2021). sbashford/excelMatlab (, GitHub. Retrieved .

Comments and Ratings (3)

Seth Bashford

I think I know what may be causing the problem you note. It isn't clear from the description above, but without supplying the argument 'w' to the constructor the class will only try to open the workbook in "read-only" mode. Therefore if the workbook didn't exist in the first place, the constructor will throw.

That argument ('w') is only needed when obtaining write-access. It is also the only other valid (but optional) argument to the constructor.

If you have suggestions for a better design I'd be happy to hear them. Submit pull requests on

Stephen Forczyk

I can get this to work if I create a workbook before running the script. However if the workbook does not exist prior to running the script I get a crash

wen-feng Huang

it can't work with following warnings:
The following error was caught while executing 'ExcelMatlab' class
Error using Interface.Microsoft_Excel_16.0_Object_Library._Workbook/Close

MATLAB Release Compatibility
Created with R2017a
Compatible with any release
Platform Compatibility
Windows macOS Linux
Tags Add Tags

Community Treasure Hunt

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

Start Hunting!