[file,status,errMsg] = officedoc(fileName, 'open', 'mode','append'); status = officedoc(file, 'write', 'title','My data', 'data',[1,2,3;4,5,6], 'image',gcf, 'bold',1,'fgcolor','b'); status = officedoc(file, 'close');
% Open document in 'append' mode: [file,status,errMsg] = officedoc('test.xls', 'open', 'mode','append'); % Write a header line to the document at a specific position: status = officedoc(file, 'write', 'sheet','newSheet','Range','A2','data',{'A','B','C'}); % Format the header line (font, color, alignment, borders/edges): % Note: we could also append these properties to the end of the 'write' command above status = officedoc(file, 'format', 'bold','on','italic',1,'fgcolor',[1,0,0],'bgcolor','y','halign','center','EdgeBottom',{4,'b'}); % Some specific formatting not currently supported by officedoc: set(file.fid.ActiveSheet.PageSetup, 'FirstPageNumber',5, 'CenterHeader','&"Arial,Bold"- Confidential -'); % Display the document in Excel application: officedoc(file, 'display'); % Loop many times and append data to the bottom of the open document: for index = 1 : 10 data = someComputation(); % e.g., magic(3) or {1,2,3; 'a','b','c'} status = officedoc(file, 'write', 'data',data); end % Close the document, deleting standard sheets and releasing COM server: status = officedoc(file, 'close', 'release',1,'delStd','on'); % Re-display document; file is no longer valid so we must use file name: officedoc('test.xls', 'display');
% Open document in 'write' mode: [file,status,errMsg] = officedoc('test.doc', 'open', 'mode','write'); % Write a title line at a specific position: status = officedoc(file, 'write', 'title','My magic data','page',3,'line',4,'PageBreakBefore',1); % Write data beneath the header: status = officedoc(file, 'write', 'line',1,'data',magic(6),'halign','center'); % Format the data (font, color, alignment, borders/edges): % Note: we could also append these properties to the end of the 'write' command above status = officedoc(file, 'format', 'bold','on','italic',1,'fgcolor',[1,0,0],'bgcolor','y','EdgeBottom',{4,'b'}); % Some specific formatting not currently supported by officedoc: set(file.fid.PageSetup.LineNumbering,'Active',1); % Display the document in Word application: officedoc(file, 'display'); % Loop many times and append data to the bottom of the open document page: for index = 1 : 10 data = someComputation(); % e.g., magic(3) or {1,2,3; 'a','b','c'} status = officedoc(file, 'write', 'data',data); end % Close the document, releasing COM server: status = officedoc(file, 'close', 'release',1); % Re-display document; file is no longer valid so we must use file name: officedoc('test.doc', 'display');
% Open document in 'append' mode: [file,status,errMsg] = officedoc('test.ppt', 'open', 'mode','append'); % Write a new slide with title and figure screenshot (taken via clipboard): status = officedoc(file, 'write', 'title','Nice plot data','image',gcf,'meta','on'); % Format the slide footer and orientation % Note: we could also append these properties to the end of the 'write' command above status = officedoc(file, 'format', 'FooterText','copyright a@b.c','PageOrientation','landscape'); % Some specific formatting not currently supported by officedoc: set(file.fid.Application.ActivePresentation.PageSetup,'FirstSlideNumber',5); % Display the document in PowerPoint application (un-minimize and bring to front): officedoc(file, 'display'); % Loop many times and append data to the bottom of slide #5: for index = 1 : 10 data = someComputation(); % e.g., magic(3) or {1,2,3; 'a','b','c'} status = officedoc(file, 'write', 'slide',5,'data',data); end % Close the document, releasing COM server: status = officedoc(file, 'close', 'release',1); % Re-display document; file is no longer valid so we must use file name: officedoc('test.ppt', 'display');