|
|
发表于 2026-1-2 23:38:03
|
显示全部楼层
本帖最后由 aloha20200628 于 2026-1-2 23:45 编辑
回复 1# 霖僡
以下代码存为 test.bat 运行,运行结果会在当前目录中生成 all.csv 文件,其中包含当前目录及其子目录下 *.doc,*.docx 文件中的全部表格数据,每个表格中的数据行与 all.csv 文件行依序对应...
- 2>1/* ::
- @echo off & dir /b/s/a-d *.docx *.doc|cscript /nologo /e:jscript "%~f0" "%cd%\all.csv"
- pause&exit/b */
- ws=WSH.stdin, fso=WSH.createObject('Scripting.FileSystemObject');
- v=WSH.arguments, cF=fso.CreateTextFile(v(0), 2, true);
- wa=WSH.createObject('word.application'), wa.visible=false, wa.displayAlerts=0;
- while (!ws.atendofstream) {
- f=ws.readline(), doc=wa.documents.open(f);
- for (t=1,tc=doc.tables.count; t<=tc; t++)
- for (r=1,rc=doc.tables(t).rows.count; r<=rc; r++) {
- line=[];
- for (c=1,cc=doc.tables(t).rows(r).cells.count; c<=cc; c++) {
- v=doc.tables(t).rows(r).cells(c).range.text;
- line.push(v.replace(/\x07|\r|\n/g, '')); }
- cF.writeLine(line.join(',')); }
- doc.close(false); }
- cF.close(), wa.quit(), WSH.quit();
复制代码 |
|