本帖最后由 terse 于 2015-9-11 14:42 编辑
xls文件 试试这样呢- @if(0)==(0) echo off
- cscript -nologo -e:jscript %0 "%~dp01.xls" "%~dp02.xls" "%~dp03.xls"
- pause & exit
- @end
- var xlApp = new ActiveXObject("Excel.Application");
- var xlBook = xlApp.Workbooks.open(WScript.Arguments.Item(0));
- xlBook.worksheets(1).activate;
- var XlSheet = xlBook.activeSheet;
- var Ojb = {};
- var Count = XlSheet.usedrange.rows.count;
- for(var i = 3; i <= Count; i += 2) {
- var L1 = XlSheet.Cells(i, 1).value;
- var L2 = XlSheet.Cells(i, 2).value;
- var L3 = XlSheet.Cells(i + 1, 2).value;
- Ojb[L1] = L3 ? L2 ? [L2, L3] : [L3] : L2 ? [L2] : "";
- }
- xlBook = xlApp.Workbooks.open(WScript.Arguments.Item(1));
- xlBook.worksheets(1).activate;
- XlSheet = xlBook.activeSheet;
- Count = XlSheet.usedrange.rows.count;
- for (i = 2; i <= Count; i++) {
- var len = Ojb[XlSheet.Cells(i, 1)].length
- if (len) {
- if (len >1) {
- XlSheet.Cells(i, 2).value = Ojb[XlSheet.Cells(i, 1)][0];
- XlSheet.Cells(i, 3).value = Ojb[XlSheet.Cells(i, 1)][1];
- }
- else { XlSheet.Cells(i, 2).value = Ojb[XlSheet.Cells(i, 1)] }
- }
- }
- //xlBook.SaveAs(WScript.Arguments.Item(2));
- xlBook.Save()
- xlBook.Close();
- xlApp.Quit();
复制代码
|