日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

excel转txt工具

發布時間:2023/12/10 编程问答 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 excel转txt工具 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

? ? 有個任務需要讀好多eccel,實際讀起來并不方便,變手工把ecxcel轉換成文本文檔,心累。。。。于是閑暇寫了個ecxcel轉txt的小工具。主要是用的Spreadsheet::XLSX。

use strict;
use warnings;
use strict;
use Spreadsheet::XLSX;
die "Usage :perl $0 <xlsx> <resultDIR>\n" unless @ARGV==2; ####需要輸入需要轉換的ecxel文件 以及生成結果文件的路徑
my $file=shift @ARGV;
my $dir=shift @ARGV;
my $excel=Spreadsheet::XLSX->new($file);
foreach my $sheet(@{$excel->{Worksheet}}){
? ? ? ? ? my $name=$sheet->{Name};###sheet名字
? ? ? ? ?open OUT,">$dir/$name.txt";##默認結果是一個sheet轉換成一個文本文檔,名字為sheet名字 ,可自行調整
? ? ? ? ?$sheet->{MaxRow}||=$sheet->{MinRow};
? ? ? ? ?foreach my $row ($sheet->{MinRow}..$sheet->{MaxRow}){
? ? ? ? ? ? ? ? ? ? $sheet->{MaxCol}||=$sheet->{MinCol};
? ? ? ? ? ? ? ? ? ?foreach my $col($sheet->{MinCol}..$sheet->{MaxCol}){
? ? ? ? ? ? ? ? ? ? ? ? ? ? my $cell=$sheet->{Cells}[$row][$col];
? ? ? ? ? ? ? ? ? ? ? ? ? ? if($cell){
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? print OUT"$cell->{Val}\t";
? ? ? ? ? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ?}
? ? ? ? ? ? ? ? ? print OUT"\n";
? ? ? }
}

寫完之后,發現每次只能轉換一個文件,于是就把它做成了一個包,名字為excel2txt.pm,隨便用~

主程序perl.pl

use strict;
use warnings;
use package::excel2txt;
my $dir="/home/escel2txt";
my @sample=("test");
foreach my $sample(@sample){
? ? ? ? ? my $file="$dir/$sample.xlsx";
? ? ? ? ? my $reportdir="/home/escel2txt";
? ? ? ? ?package::excel2txt::change($file,$reportdir);##在report下批量生成轉換過后的文檔
}

包:excel2txt.pm

package package::excel2txt;

use strict;
use warnings;
use strict;?
use Spreadsheet::XLSX;

sub change{
my $file=shift @_;
my $dir=shift @_;
my $excel=Spreadsheet::XLSX->new($file);
? foreach my $sheet(@{$excel->{Worksheet}}){
? ? ? ? ? my $name=$sheet->{Name};###sheet名字
? ? ? ? ?open OUT,">$dir/$name.txt";##默認結果是一個sheet轉換成一個文本文檔,名字為sheet名字 ,可自行調整
? ? ? ? ?$sheet->{MaxRow}||=$sheet->{MinRow};
? ? ? ? ?foreach my $row ($sheet->{MinRow}..$sheet->{MaxRow}){
? ? ? ? ? ? ? ? ? ? $sheet->{MaxCol}||=$sheet->{MinCol};
? ? ? ? ? ? ? ? ? ?foreach my $col($sheet->{MinCol}..$sheet->{MaxCol}){
? ? ? ? ? ? ? ? ? ? ? ? ? ? my $cell=$sheet->{Cells}[$row][$col];
? ? ? ? ? ? ? ? ? ? ? ? ? ? if($cell){
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? print OUT"$cell->{Val}\t";
? ? ? ? ? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ?}
? ? ? ? ? ? ? ? ? ?print OUT"\n";
? ? ? ? ? }
? ? ?}

}

1

轉載于:https://www.cnblogs.com/gui-/p/6889608.html

總結

以上是生活随笔為你收集整理的excel转txt工具的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。