![]() |
中国DOS联盟-- 联合DOS 推动DOS 发展DOS --联盟域名:www.cn-dos.net 论坛域名:www.cn-dos.net/forum |
| 游客 | 登录 | 注册 | 会员 | 搜索 | 中国DOS联盟 |
|
中国DOS联盟论坛 现在时间是 2026-08-12 06:15 |
共 47,811 主题排行 / 349,897 发帖 / 今日 0 篇 / 48,256 会员排行 |
| DOS批处理 & 脚本技术(批处理室) » [已结]请教问题 : P是否可以将 excel *.xls 转成 *.txt 吗? |
| 可打印版本 968 / 3 |
| 第1楼 pdanniel66 | 发表于 2010-06-05 10:18 |
| 初级用户 发帖 64 积分 68 | |
|
[已结]请教问题 : P是否可以将 excel *.xls 转成 *.txt 吗? 请教问题 : P是否可以将 excel *.xls 转成 *.txt 吗?
[ Last edited by pdanniel66 on 2010-6-5 at 16:24 ] |
|
| 第2楼 vwase | 发表于 2010-06-05 12:07 |
| 新手上路 发帖 4 积分 7 | |
|
不可以.他们的编码不同,没法当做简单的文本处理
|
|
| 第3楼 HAT | 发表于 2010-06-05 13:41 |
| 版主 发帖 5,017 积分 9,023 | |
|
VBS可以
|
|
| 第4楼 pdanniel66 | 发表于 2010-06-05 16:11 |
| 初级用户 发帖 64 积分 68 | |
|
Reference link as below
http://bathome.l3.wuyou.com/thread-6921-1-1.html Reference the above link and share my code -- the batch and vbs as below Transfer *.xls to *.txt (1) main batch scripts ==> main01.bat del hhh.txt call xzt.vbs "123.xls" hhh.txt call del_blank.bat (2) xzt.vbs '另存工作表为txt文件,并将空值替换为# dim hang,lie,counter,counter1 '声明变量 on error resume next '忽略错误 '设置对象 set wshshell=createobject ("wscript.shell") path=wshshell.currentdirectory '当前路径 set objexcel=createobject ("excel.application") set objworks=objexcel.workbooks.open (path&"\"&wscript.arguments(0)) 'arguments(0)表示参数1 set objfso=createobject("scripting.filesystemobject") set objtext=objfso.opentextfile(path&"\"&wscript.arguments(1),2,true) 'arguments(1)表示参数2 objexcel.worksheets(1).activate '获取工作表有效总行列数,但工作表的第一行和第一列不得有空值 counter=0 do counter=counter+1 loop until objexcel.cells(1,counter).value="" lie=counter-1:counter=0 do counter=counter+1 loop until objexcel.cells(counter,1).value="" hang=counter-1:counter=0 '读取工作表数据并将空值替换为# for counter=1 to hang for counter1=1 to lie if objexcel.cells(counter,counter1).value="" then strexcel=strexcel&" #" else strexcel=strexcel&" "&objexcel.cells(counter,counter1).value end if next strexcel=strexcel&vbcrlf next objtext.write strexcel objtext.close objworks.close '清空对象,释放内存 set objtext=nothing set objfso=nothing set objworks=nothing set objexcel=nothing set wshshell=nothing (3) del_blank.bat ( delete the blank per line ) @echo off del hhh_fin.txt for /f "tokens=* delims= " %%s in (hhh.txt) do call :str %%s >> hhh_fin.txt :str echo %* [ Last edited by pdanniel66 on 2010-6-5 at 16:23 ] |
|
|
[ 联系联盟系统管理团队 -
中国DOS联盟 -
标准版 ] Sponsored by ifanr Inc | © 2001–2023 |