Perl实现将将.txt中内容写入到excel中
2012-07-17 15:06
302 查看
在处理存于txt中的大数据时,查看非常不方便,可以考虑写入到excel中。以下是一个简单的用perl实现的写入excel的程序。
#写文件到excel #输入:待写入到excel表中的.txt文件 #输出:excel文件,注意要用绝对路径 ##################################################### use strict; use Win32; use Cwd; use Win32::OLE qw(in with); use Win32::OLE::Const 'Microsoft Excel'; $Win32::OLE::Warn = 3; # die on errors... # get already active Excel application or open new my $Excel = Win32::OLE->GetActiveObject('Excel.Application') || Win32::OLE->new('Excel.Application', 'Quit'); use Encode; my $infile1="a.txt"; my $outexcel1="E:/PerlCode/cyliu/a.xlsx"; open IN1,"$infile1" or die "could not open the input file!"; my $Book = $Excel->Workbooks->Open("$outexcel1") or die "Could not open the $outexcel1 !!!\n"; my $Sheet = $Book->Worksheets(1); my $row=0; my %hangye; my %num; my %word; my %word1; while(my $aline=<IN1>) { $row++; print $row."\n"; $aline=~s/\n$//; my @array=split(/\t/,$aline); $Sheet->Cells($row,1)->{'Value'}=$array[0]; $Sheet->Cells($row,2)->{'Value'}=$array[1]; $Sheet->Cells($row,3)->{'Value'}=$array[2]; $Sheet->Cells($row,4)->{'Value'}=$array[3];#$big.":".$name{$big}; $Sheet->Cells($row,5)->{'Value'}=$array[4]; $Sheet->Cells($row,6)->{'Value'}=$array[5]; } $Book->Close;
相关文章推荐
- python实现读Excel写入.txt
- Python读取txt内容写入xls格式excel中的方法
- perl 读取Excel写入txt 乱码
- python将文件夹里所有的txt文件内容写入excel
- Python读取txt内容写入xls格式的excel中
- 【Python小工具】Python实现批量解析PDF文件提取内容并写入到Excel中
- C#控制台基础 写入txt文本中的内容实现换行
- python实现读Excel写入.txt的方法
- python 将txt内容写入excel
- python数据清理——将excel单元格的内容写入到txt
- Python读取txt内容写入xlsx格式的excel中
- java实现持续写入内容到txt文件
- 从Excel中读取内容写入txt文件中
- java实现持续写入内容到txt文件
- Java读取txt文本内容并写入Excel
- PYTHON实现把PPT文档中的内容导出到TXT文件中
- 用Excel VBA代码实现去重录入某字段内容
- Asp.Net输出指定内容的Word、Excel、TXT、HTM等类型的文档
- POI实现Excel写入
- 数据导入,可以将txt文本文件或excel的内容导入到数据库