本帖最后由 flashercs 于 2018-12-3 13:00 编辑
是修改第一个表格Sheet1吗?
保存 修改Excel.js 到Excel文件的目录下;- var shell = WScript.CreateObject('WScript.Shell'),
- fso = WScript.CreateObject('Scripting.FileSystemObject'),
- curDir;
- curDir = shell.CurrentDirectory = fso.GetParentFolderName(WScript.ScriptFullName);
- var aExcelFiles = ['1.xlsx', '2.xls', '3.xlsx', '4.xls'];
- var oInsertStr = {
- 'B3': '文字一',
- 'B4': '文字二',
- 'B5': '文字三'
- };
- try {
- var oExcelApp = WScript.CreateObject('ET.Application');
- } catch (e) {
- try {
- oExcelApp = WScript.CreateObject('Excel.Application');
- } catch (e) {
- showError(e, 'Cannot create Excel.Application and ET.Application');
- WScript.Quit(11);
- }
- }
- oExcelApp.AutomationSecurity = 3;
- oExcelApp.DisplayAlerts = false;
- for (var i = 0; i < aExcelFiles.length; ++i) {
- try {
- var oWorkbook = oExcelApp.Workbooks.Open(curDir + '\\' + aExcelFiles[i], 0, false);
- var oWorksheet = oWorkbook.Worksheets(1);
- for (var key in oInsertStr) {
- oWorksheet.Range(key).Value = oInsertStr[key];
- }
- oWorkbook.Close(true);
- } catch (e) {
-
- }
- }
- oExcelApp.Workbooks.Close();
- oExcelApp.Quit();
复制代码
|