本帖最后由 flashercs 于 2018-10-11 17:51 编辑
printExcel.js- var fso,
- colFiles,
- file,
- oExcelApp,
- oWorkbook,
- oSheet;
- oExcelApp = new ActiveXObject('Excel.Application');
- // oExcelApp.DisplayAlerts = false;
- fso = new ActiveXObject('Scripting.FileSystemObject');
- colFiles = new Enumerator(fso.GetFolder(fso.GetParentFolderName(WScript.ScriptFullName)).Files);
- for (; !colFiles.atEnd(); colFiles.moveNext()) {
- file = colFiles.item().Path;
- if ('xlsx' !== fso.GetExtensionName(file).toLowerCase()) continue;
- try {
- oWorkbook = oExcelApp.Workbooks.Open(file, 3, true);
- oSheet = oWorkbook.Worksheets(1);
- oSheet.PageSetup.Orientation = 2;
- oSheet.PrintOut();
- oWorkbook.Close(false);
- } catch (err) {
- WScript.Echo(file + '\n' + err.message);
- }
- }
- // oExcelApp.DisplayAlerts = true;
- oExcelApp.Quit();
- WScript.Echo('printing complete');
复制代码
|