本帖最后由 flashercs 于 2018-10-11 17:51 编辑
删除列.js- var fso,
- colFiles,
- file,
- aCols = [1, 2, 4, 5],
- oExcelApp,
- oWorkbook,
- oSheet,
- j;
- 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);
- oSheet = oWorkbook.Worksheets(1);
- for (j = aCols.length - 1; j >= 0; --j) {
- oSheet.Columns(aCols[j]).Delete(-4159);
- }
- oWorkbook.Close(true);
- } catch (err) {
- WScript.Echo(file + '\n' + err.message);
- }
- }
- oExcelApp.DisplayAlerts = true;
- oExcelApp.Quit();
- WScript.Echo('Mission complete');
复制代码
|