|
xycoordinate
中级用户
  
积分 493
发帖 228
注册 2007-2-16 来自 安徽
状态 离线
|
『楼 主』:
如何用批处理将TXT文件直接转换成XLS文件
使用 LLM 解释/回答一下
如何用批处理将TXT文件直接转换成XLS文件
report.txt
1 13 45 0 4500 15615
2 13 45 0 4500 15600
3 26 255 0 25500 15601
4 18 81 0 8100 15602
5 29 188 0 18800 15605
6 25 150 0 15000 15606
7 84 333 12 33900 15609
8 20 105 1 10550 15610
9 26 128 0 12800 15611
10 14 149 0 14900 15612
11 5 33 0 3300 15613
12 0 0 0 0 15616
13 48 190 16 19800 15617
14 321 1702 29 171650
Last edited by xycoordinate on 2007-2-23 at 11:34 AM ]
How to directly convert a TXT file to an XLS file using batch processing
report.txt
1 13 45 0 4500 15615
2 13 45 0 4500 15600
3 26 255 0 25500 15601
4 18 81 0 8100 15602
5 29 188 0 18800 15605
6 25 150 0 15000 15606
7 84 333 12 33900 15609
8 20 105 1 10550 15610
9 26 128 0 12800 15611
10 14 149 0 14900 15612
11 5 33 0 3300 15613
12 0 0 0 0 15616
13 48 190 16 19800 15617
14 321 1702 29 171650
Last edited by xycoordinate on 2007-2-23 at 11:34 AM ]
|
|
2007-2-24 00:29 |
|
|
slore
铂金会员
      
积分 5212
发帖 2478
注册 2007-2-8
状态 离线
|
『第 2 楼』:
使用 LLM 解释/回答一下
xls
你用记事本打开是什么格式?
xls
What format do you see when you open it with Notepad?
|
|
2007-2-24 00:47 |
|
|
anqing
高级用户
   
积分 859
发帖 413
注册 2006-8-14
状态 离线
|
『第 3 楼』:
使用 LLM 解释/回答一下
txt中的数字,能准确给xls文件吗?
Can the numbers in the txt be accurately given to the xls file?
|
|
2007-2-24 01:32 |
|
|
slore
铂金会员
      
积分 5212
发帖 2478
注册 2007-2-8
状态 离线
|
『第 4 楼』:
使用 LLM 解释/回答一下
格式有规律当然可以。
Of course, if the format is regular.
|
|
2007-2-24 01:34 |
|
|
zh159
金牌会员
     
积分 3687
发帖 1467
注册 2005-8-8
状态 离线
|
『第 5 楼』:
使用 LLM 解释/回答一下
现在没时间写代码,给你一个思路:
先将双空格替换为单空格,再将单空格替换为{TAB}+单空格({TAB}:制表符)
然后直接用 Excel 打开该 TXT 文件
Now there's no time to write code. Here's an idea:
First, replace double spaces with single spaces, then replace single spaces with {TAB} + single space ({TAB}: tab character)
Then directly open the TXT file with Excel
|
|
2007-2-24 01:34 |
|
|
slore
铂金会员
      
积分 5212
发帖 2478
注册 2007-2-8
状态 离线
|
『第 6 楼』:
使用 LLM 解释/回答一下
看了本来有的xls文档,貌似不是纯文本样子……
那就5楼的模拟输入咯。。。
After looking at the original existing xls document, it seems not in plain text form...
Then it's the simulated input on the 5th floor...
|
|
2007-2-24 01:53 |
|
|
slore
铂金会员
      
积分 5212
发帖 2478
注册 2007-2-8
状态 离线
|
『第 7 楼』:
使用 LLM 解释/回答一下
脚本可以引用这个对象Excel.Application
The script can reference this object Excel.Application
|
|
2007-2-24 02:40 |
|
|
vkill
金牌会员
     
积分 4103
发帖 1744
注册 2006-1-20 来自 甘肃.临泽
状态 离线
|
『第 8 楼』:
使用 LLM 解释/回答一下
这个不可以吧?xls文件用记事本打开是乱码的
This shouldn't be possible. An XLS file is garbled when opened with Notepad.
|
|
2007-2-24 02:50 |
|
|
amao
中级用户
  
积分 316
发帖 152
注册 2006-6-18
状态 离线
|
『第 9 楼』:
使用 LLM 解释/回答一下
sed "s/^*//;s/\+/\t/g" report.txt> result.xls
sed的下载和使用请用"sed"搜索本论坛
Last edited by amao on 2007-2-24 at 03:22 AM ]
sed "s/^*//;s/\+/\t/g" report.txt> result.xls
For downloading and using sed, please search the forum with "sed"
Last edited by amao on 2007-2-24 at 03:22 AM ]
|
|
2007-2-24 03:20 |
|
|
NaturalJ0
银牌会员
    
积分 1181
发帖 533
注册 2006-8-14
状态 离线
|
『第 10 楼』:
使用 LLM 解释/回答一下
如果隔着空格或TAB或逗号,倒是可以直接用EXCEL打开TXT文件,EXCEL会问你如何分隔。
PS:按TAB键分隔好,复制到剪贴板,再打开EXCEL粘贴,倒也可行,如果这样的话要用VBS了。
If separated by spaces, tabs, or commas, you can directly open the TXT file with EXCEL, and EXCEL will ask you how to separate.
PS: Tabs are well separated. Copy to the clipboard, then open EXCEL and paste. If so, you need to use VBS.
|
|
2007-2-24 03:27 |
|
|
zh159
金牌会员
     
积分 3687
发帖 1467
注册 2005-8-8
状态 离线
|
『第 11 楼』:
使用 LLM 解释/回答一下
生成的“test.xls”可以直接用 Excel 打开
@echo off
setlocal EnableDelayedExpansion
cd.>test.xls
for /f "delims=" %%n in (test.txt) do (
set "str=%%n"
set "str=!str: = !"
set "str=!str: ={TAB} !"
echo !str!
>>test.xls echo !str!
)
pause
{TAB}:键盘TAB制表符
PS:你的数据最后一行“14 321 1702 29 171650 ”是不是有问题,少了第三个数据?
Last edited by zh159 on 2007-2-23 at 06:16 PM ]
The generated "test.xls" can be directly opened with Excel
@echo off
setlocal EnableDelayedExpansion
cd.>test.xls
for /f "delims=" %%n in (test.txt) do (
set "str=%%n"
set "str=!str: = !"
set "str=!str: ={TAB} !"
echo !str!
>>test.xls echo !str!
)
pause
{TAB}: Keyboard TAB tab
PS: Is there a problem with the last line of your data "14 321 1702 29 171650 ", missing the third data?
Last edited by zh159 on 2007-2-23 at 06:16 PM ]
|
|
2007-2-24 03:56 |
|
|
xycoordinate
中级用户
  
积分 493
发帖 228
注册 2007-2-16 来自 安徽
状态 离线
|
『第 12 楼』:
使用 LLM 解释/回答一下
Originally posted by zh159 at 2007-2-23 02:56 PM:
生成的“test.xls”可以直接用 Excel 打开
@echo off
setlocal EnableDelayedExpansion
cd.>test.xls
for /f "delims=" %%n in (test.txt) do (
set "str=%%n"
set "str=!str: = !"
set "str=!str: ={TAB} !"
echo !str!
>>test.xls echo !str!
)
pause
先将双空格替换为单空格,再将单空格替换为{TAB}+单空格({TAB}:制表符)
谢谢!!!
NNNNNN!!!!!!!!!!!!!
还有:
cd.>test.xls
set "str=!str: = !"
set "str=!str: ={TAB} !"
意思不太明白???
是这个吗?
set /?
环境变量替换已如下增强:
%PATH:str1=str2%
会扩展 PATH 环境变量,用 "str2" 代替扩展结果中的每个 "str1"。
要有效地从扩展结果中删除所有的 "str1","str2" 可以是空的。
"str1" 可以以星号打头;在这种情况下,"str1" 会从扩展结果的
开始到 str1 剩余部分第一次出现的地方,都一直保持相配。
我直接用tab分割列就OK了!!!!
20070131.txt如下格式,直接更改扩展名为xls,就能如我愿了!!!
1 13 45 0 4500 15615
2 13 45 0 4500 15600
3 26 255 0 25500 15601
4 18 81 0 8100 15602
5 29 188 0 18800 15605
6 25 150 0 15000 15606
7 84 333 12 33900 15609
8 20 105 1 10550 15610
9 26 128 0 12800 15611
10 14 149 0 14900 15612
11 5 33 0 3300 15613
12 0 0 0 0 15616
13 48 190 16 19800 15617
14 321 1702 29 171650
Last edited by xycoordinate on 2007-2-23 at 10:53 PM ]
Originally posted by zh159 at 2007-2-23 02:56 PM:
The generated "test.xls" can be directly opened with Excel
@echo off
setlocal EnableDelayedExpansion
cd.>test.xls
for /f "delims=" %%n in (test.txt) do (
set "str=%%n"
set "str=!str: = !"
set "str=!str: ={TAB} !"
echo !str!
>>test.xls echo !str!
)
pause
First replace double spaces with single spaces, then replace single spaces with {TAB} + single space ({TAB}: tab character)
Thank you!!!
NNNNNN!!!!!!!!!!!!!
Also:
cd.>test.xls
set "str=!str: = !"
set "str=!str: ={TAB} !"
The meaning is not very clear???
Is it this?
set /?
Environment variable substitution has been enhanced as follows:
%PATH:str1=str2%
This will expand the PATH environment variable, replacing each "str1" with "str2" in the expanded result.
To effectively remove all "str1" from the expanded result, "str2" can be empty.
"str1" can start with an asterisk; in this case, "str1" will match from the start of the expanded result to the first occurrence of the remaining part of "str1".
I can directly use tab to separate columns and it's OK!!!!
The 20070131.txt has the following format, directly changing the extension to xls will be as I wish!!!
1 13 45 0 4500 15615
2 13 45 0 4500 15600
3 26 255 0 25500 15601
4 18 81 0 8100 15602
5 29 188 0 18800 15605
6 25 150 0 15000 15606
7 84 333 12 33900 15609
8 20 105 1 10550 15610
9 26 128 0 12800 15611
10 14 149 0 14900 15612
11 5 33 0 3300 15613
12 0 0 0 0 15616
13 48 190 16 19800 15617
14 321 1702 29 171650
Last edited by xycoordinate on 2007-2-23 at 10:53 PM ]
|
|
2007-2-24 09:38 |
|
|
vkill
金牌会员
     
积分 4103
发帖 1744
注册 2006-1-20 来自 甘肃.临泽
状态 离线
|
|
2007-2-24 09:39 |
|
|
chainliq
高级用户
    学无尽止
积分 635
发帖 244
注册 2006-4-15 来自 广西贵港
状态 离线
|
『第 14 楼』:
使用 LLM 解释/回答一下
呵呵,这样也简单哈`````
@echo off
type report.txt echo >>report.xls
Hehe, this is also simple`````
@echo off
type report.txt echo >>report.xls
|

学无尽止 |
|
2007-2-24 10:46 |
|
|
xycoordinate
中级用户
  
积分 493
发帖 228
注册 2007-2-16 来自 安徽
状态 离线
|
『第 15 楼』:
使用 LLM 解释/回答一下
Originally posted by chainliq at 2007-2-23 09:46 PM:
呵呵,这样也简单哈`````
@echo off
type report.txt echo >>report.xls
<img src="images/smilies/face-sad.png" align="absmiddle" border="0">
F:\>type report.txt echo >>report.xls
report.txt
系统找不到指定的文件。
处理: echo 时出错。
为何会报错?????
report.xls倒是生成了,但是格式不对!!!
Originally posted by chainliq at 2007-2-23 09:46 PM:
Hehe, this is also simple.`````
@echo off
type report.txt echo >>report.xls
:(
F:\>type report.txt echo >>report.xls
report.txt
The system cannot find the specified file.
Error occurred while processing: echo
Why does it report an error?????
The report.xls is indeed generated, but the format is incorrect!!!
|
|
2007-2-24 11:43 |
|