MS-Excel 排序- @set @n=0;// & cscript -nologo -e:jscript "%~0"<a.txt>b.txt & pause & exit/b
-
- txt = WScript.StdIn.ReadAll() + "\r\n";
- arr = txt.replace(/^(\s*\n)+/, "").replace(/(\s*\n)+/g, "\n").split("\n");
- oExcel = new ActiveXObject("Excel.Application");
- oExcel.Visible = false;
- oBook = oExcel.WorkBooks.Add();
- oSheet = oBook.WorkSheets(1);
-
- for (i=0; i<arr.length-1; i++) {
- a = arr[i].split(/ +/g);
- for (j=0; j<a.length; j++){ oExcel.Cells(i+1, j+1) = a[j] };
- oRange = oSheet.Range(oExcel.Cells(i+1, 1), oExcel.Cells(i+1, a.length));
- oRange.Sort(oRange, 1, "", "", 1, "", 1, 0, 1, false, 2, 2, 0);
- for (j=0; j<a.length; j++){ a[j] = oExcel.Cells(i+1, j+1) };
- WScript.Echo(a.join(" "))
- }
- oBook.Saved = true;
- oBook.Close();
- oExcel.Quit()
复制代码
|