- 论坛徽章:
- 0
|
20可用积分
大家帮忙看看这个问题:
perl处理excel中的法文等欧美国家语言的时候写入到txt中是问号!
我用perl脚本读取指定excel中的某些字段,然后写入到txt中,相对中文和英文来说都没有问题,但是针对泰文和法文就会有不识别的文字!txt中要么是问号要么就是空格!
请达人们给予启示!谢谢!
- #printf qq(please input the language\n);
- #$yy = <STDIN>;
- #perl cdma_utf8.pl Chinese strings_Test.xls chinese.brx
- #2008=0928use map to control language
- use Win32::OLE qw(in with);
- use Win32::OLE::Const 'Microsoft Excel';
- use utf8;
- use Unicode::UCD 'charinfo';
- use Encode qw(encode from_to _utf8_off);
- $Win32::OLE::Warn = 3;
- $yy = $ARGV[0];
- chomp $yy;
- $cvs = $ARGV[1];
- $brx =$ARGV[2];
- chomp $cvs;
- chomp $brx;
- printf "$cvs \n";
- printf "$yy \n";
- printf "$brx \n";
- if($yy eq "h"){
- printf qq(cdma language infile outfile\n);
- exit;
- }
- $Excel = Win32::OLE->GetActiveObject('Excel.Application')|| Win32::OLE->new('Excel.Application', 'Quit');
- #$Book = $Excel->Workbooks->Open("$cvs");
- $Book=$Excel->Workbooks->Open("$cvs");
- $Sheet = $Book->Worksheets(1);
- $col="1";
- while($col < 20){
- $shuju = $Sheet->Cells(1,$col)->{'Value'};
- if($shuju eq "$yy"){
- $colnum = "$col";
- last;
- }
- else{
- $col++;
- }
- }
- system qq(del /q $brx);
- open (H,">$brx");
- close H;
- $title = qq(\<\?xml version="1.0" encoding="utf-8"\?\>\n);
- $title1=qq(\<BREWRes Name="$yy" VERSION="1"\>\n);
- $title2=qq(\<Strings Encoding=\"Unicode\"\>\n);
- open (H,">>$brx");
- print H "$title";
- print H "$title1";
- print H "$title2";
- close H;
- #open(CVS,"$cvs");
- $id = "1001";
- $lie = "2";
- while($lie < 1471){
- #while($lie < 3){
- $guding = $Sheet->Cells($lie,2)->{'Value'};
- $huoqu =$Sheet->Cells($lie,$col)->{'Value'};
- $huoqu =~s/&/&/;
- $huoqu =~s/</</;
- $huoqu =~s/>/>/;
- # if($yy eq Chinese){
- # $huoqu =encode('gb2312',$huoqu);
- # }
- # else{
- #$huoqu1 =$huoqu;
- $huoqu2=Encode::decode('gb2312',$huoqu);
- #printf "$huoqu \n";
- #$huoqu3 =Encode::encode_utf8($huoqu2);
-
- # }
- $neirong = qq(\<String Id="$id" Name="$guding"\>\n);
- #$neirong1 = qq( \<Text\>$huoqu1\</Text\>\n);
- $neirong2 = qq( \<Text\>$huoqu2\</Text\>\n);
- #$neirong3 = qq( \<Text\>$huoqu3\</Text\>\n);
- $neirong3 = qq( \</String\>\n);
- open (H,">>$brx");
- print H "$neirong";
- #print H "$neirong1";
- print H "$neirong2";
- print H "$neirong3";
- close H;
- ++$lie;
- $id++;
- }
- $final=qq(\</Strings\>\n);
- $final1=qq( \</BREWRes\>\n);
- open (H,">>$brx");
- print H "$final";
- print H "$final1";
- close H;
- $Book->Close;
- #$Book->Quit();
- exit;
-
复制代码 |
|