Code covered by the BSD License  

Highlights from
xlswritefig

3.66667

3.7 | 4 ratings Rate this file 9 Downloads (last 30 days) File Size: 2.42 KB File ID: #24424
image thumbnail

xlswritefig

by Scott Hirsch

 

12 Jun 2009

Write a MATLAB figure to a Microsoft Excel spreadsheet.

| Watch this File

File Information
Description

XLSWRITEFIG allows you to programmatically place a MATLAB figure inside of an Excel spreadsheet. This can be a useful supplement to XLSWRITE.

MATLAB release MATLAB 7.6 (R2008a)
Other requirements Runs on Microsoft Windows only. Requires Excel.
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (6)
27 Aug 2009 Peter Lindberg

I've added a "add a new worksheet function":

WorkSheets = Excel.sheets;
message = struct('message',{''},'identifier',{''});

try
    Sheets = Excel.ActiveWorkBook.Sheets;
    target_sheet = get(Sheets, 'Item', sheetname);
catch %#ok<CTCH> Suppress so that this function works in releases without MException
    % Error if the sheet doesn't exist. It would be nice to create it, but
    % I'm too lazy.
    % The alternative to try/catch is to call xlsfinfo to see if the sheet exists, but
    % that's really slow.
    disp(['Sheet ' sheetname ' does not exist!']);
    Sheet = invoke(WorkSheets,'Add')
    Sheet.name = sheetname
    target_sheet = Sheet
end;

27 Aug 2009 Peter Lindberg  
02 Sep 2009 Anand

Hello Scott,

Thanks for the M-File. Its very helpful.

I had few queries:
1. Can we resize the figure in Excel automatically.
2. I am running a loop, so the same set of instructions are iterated. Is there any way by which we could advance the cell where the figure has to be saved.

Any help is appreciated.

Thanks
Anand

04 Feb 2010 Peter Lindberg

I changed line 80 to:

op = invoke(Excel.Workbooks, 'open', [filename]);

before it read:

op = invoke(Excel.Workbooks, 'open', [pwd filesep filename]);

but pwd filesep assumes you have the xl file in the same catalogue as your program. Just a thought.

22 Jun 2011 Krishna Kumar  
22 Jun 2011 Krishna Kumar  
Please login to add a comment or rating.
Tag Activity for this File
Tag Applied By Date/Time
excel Scott Hirsch 02 Jul 2009 15:18:45
data export Scott Hirsch 02 Jul 2009 15:18:46

Contact us at files@mathworks.com