Is there an example of printing an Excel sheet programmatically from MATLAB 7.8 (R2009a)?

4 Ansichten (letzte 30 Tage)
I have written data to an Excel file using the XLSWRITE function using the following code.
filename = 'C:\SomeExcelFile.xls';
% Write Random Data
xlswrite(filename,rand(10));
Now I would like to programmatically print this file.

Akzeptierte Antwort

MathWorks Support Team
MathWorks Support Team am 3 Feb. 2010
Using the following workflow, you can print your Excel file to a printer.
filename = 'C:\SomeExcelFile.xls';
% Write Random Data
xlswrite(filename,rand(10));
Excel = actxserver('excel.application');
Excel.visible = 1
Workbooks = Excel.Workbooks;
% Make Excel visible
Excel.Visible=1;
% Open Excel file
Workbook=Workbooks.Open(filename);
% The Syntax for PrintOut on the Excel Developer reference is:
% PrintOut(From, To, Copies, Preview, ActivePrinter, PrintToFile, Collate,
% PrToFileName, IgnorePrintAreas)
% It is possible to pass these arguments to the function as shown below
Excel.ActiveWorkbook.PrintOut(1,1,1,'False','PrinterName');
% You can also use the default settings and just PrintOut
% Excel.ActiveWorkbook.PrintOut
Excel.Quit;

Weitere Antworten (0)

Tags

Noch keine Tags eingegeben.

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by