Error[8]: Undefined offset: 1, File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 121
File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 473, decode(

概述本程序版权归xiaobin所有。 有一表格需要进行格式化处理,其要求如下: 1. 档案编号重复     少部分在xls文件中,大部分与数据库冲突。 2. 日期格式错误     正确格式:xxxx-xx-xx 3. 所有汉字的空格问题 4. 非法性别     除了男女之外 程序如下: #! /usr/bin/perl########################################

本程序版权归xiaobin所有。


有一表格需要进行格式化处理,其要求如下:

1. 档案编号重复
    少部分在xls文件中,大部分与数据库冲突。
2. 日期格式错误
    正确格式:xxxx-xx-xx
3. 所有汉字的空格问题
4. 非法性别
    除了男女之外


程序如下:

#! /usr/bin/perl################################################################################ Author:               **斌# Date:                 2012-02-22# Version:              V0.1############################################################################################################################################################### ModifIEd by:          xiaobin (XB)# ModifIEd date:        2012-03-31# Version:              V0.3############################################################################################################################################################### ModifIEd by:          xiaobin (XB)# ModifIEd date:        2012-04-01# Version:              V0.4############################################################################################################################################################### ModifIEd by:          # ModifIEd date:        # Version:              ############################################################################################################################################################### 版权说明:                                                                  ##           本程序版权归李贵斌所有,解释权属于所有者。                        ##           作为一个整体使用时,请附带以上说明。                              ##                                                                             ##           本程序完全免费使用。                                              ################################################################################ ################################################################################                               使用说明                                      #################################################################################                                                                             ##   命令行:perl processData.PL xxx.xls >> xxx.txt                            ##                                                                             ##   参数解释:                                                                ##           1. xxx.xls 为要进行处理的Excel文件名                              ##           2. >> 为管道符号                                                  ##           3. xxx.txt 为要保存的文件                                         ##                                                                             ################################################################################use strict;use warnings;use EnCoding;use Spreadsheet::ParseExcel;use Spreadsheet::ParseExcel::FmtUnicode;################################################################################ 主程序################################################################################my $oExcel = Spreadsheet::ParseExcel->new;dIE "You must provIDe a filename to [+++]"        ."to be parsed as an Excel file" unless @ARGV; #set for charactormy $oFmtC = Spreadsheet::ParseExcel::FmtUnicode->new(Unicode_Map => "GB2312");if($#ARGV < 0) {    exit;}my $oBook = $oExcel->Parse($ARGV[0],$oFmtC);my($iR,$iC,$oWkS,$oWkC);PrnBook($oBook);################################################################################ 主子程序################################################################################sub PrnBook {    my($oBook) = @_;    my($iR,$oWkC);    for(my $iSheet=0; $iSheet < $oBook->{SheetCount}; $iSheet++) {        $oWkS = $oBook->{Worksheet}[$iSheet];                my $sn = 0;                print "序号\t建档日期\t性别\t出生日期\r\n";        print "====\t==========\t====\t==========\r\n";                for(my $iR = $oWkS->{MinRow};                 defined $oWkS->{MaxRow} && $iR < $oWkS->{MaxRow} + 1; $iR++) {            $sn = $iR + 1;            print "$sn,\t";                                 for(my $iC = $oWkS->{MinCol};                        defined $oWkS->{MaxCol} && $iC < $oWkS->{MaxCol} + 1;                         $iC++) {                                                $oWkC = $oWkS->{Cells}[$iR][$iC];                                checkDateFmt($iC,$oWkC);                check2Sex($iC,$oWkC);            }                        print "\r\n";        }        print "============ 共处理 $sn 行数据 ============\r\n";    }}################################################################################ 模块说明:子程序## 功能说明:检查日期格式#           $_[0] == 4 为检查第4列的数据(0,1,2,3,4)#           $_[0] == 7 为检查第7列的数据(0,4,5,6,7)###############################################################################sub checkDateFmt {    if ($_[0] == 4 || $_[0] == 7) {                if ($_[1]->Value =~ m{ \s }xms) {        	 dIE "Not Value!";        }                if ($_[1]->Value =~             m{                ^                ([1-9]) ([0-9]) ([0-9]) ([0-9])     # Year                [-] +                               # -                ([0-9]) ([0-9])                     # Month                [-] +                               # -                ([0-9]) ([0-9])                     # Day                $            }xms            ) {            if ($_[0] == 4) {                print "--,\t";            }            else {                print "--\t";            }        }        elsif ($_[1]->Value =~             m{                ^                ([1-9]) ([0-9]) ([0-9]) ([0-9])     # Year                [-] ?                               # -                ([0-9]) ([0-9])                     # Month                [-] ?                               # -                ([0-9]) ([0-9])                     # Day                $            }xms            ) {            print "--\t";        }        else {            print "not match.\t";        }            }}################################################################################ 模块说明:子程序## 功能说明:检查性别#           (男,女)#           $_[0] == 5 为检查第4列的数据(0,5)###############################################################################sub check2Sex {    my $strMan = Encode::decode("CP936","男");    my $strWoman = Encode::decode("CP936","女");        if ($_[0] == 5) {        unless (Encode::decode("CP936",$_[1]->Value) =~             m{                ( $strMan | $strWoman )            }xms            ) {            print "UnkNow\t";        }        else {            print Encode::encode("CP936",).",\t";        }    }}
总结

以上是内存溢出为你收集整理的使用Perl对Excel进行处理全部内容,希望文章能够帮你解决使用Perl对Excel进行处理所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

)
File: /www/wwwroot/outofmemory.cn/tmp/route_read.php, Line: 126, InsideLink()
File: /www/wwwroot/outofmemory.cn/tmp/index.inc.php, Line: 166, include(/www/wwwroot/outofmemory.cn/tmp/route_read.php)
File: /www/wwwroot/outofmemory.cn/index.php, Line: 30, include(/www/wwwroot/outofmemory.cn/tmp/index.inc.php)
使用Perl对Excel进行处理_语言综合_内存溢出

使用Perl对Excel进行处理

使用Perl对Excel进行处理,第1张

概述本程序版权归xiaobin所有。 有一表格需要进行格式化处理,其要求如下: 1. 档案编号重复     少部分在xls文件中,大部分与数据库冲突。 2. 日期格式错误     正确格式:xxxx-xx-xx 3. 所有汉字的空格问题 4. 非法性别     除了男女之外 程序如下: #! /usr/bin/perl########################################

本程序版权归xiaobin所有。


有一表格需要进行格式化处理,其要求如下:

1. 档案编号重复
    少部分在xls文件中,大部分与数据库冲突。
2. 日期格式错误
    正确格式:xxxx-xx-xx
3. 所有汉字的空格问题
4. 非法性别
    除了男女之外


程序如下:

#! /usr/bin/perl################################################################################ Author:               **斌# Date:                 2012-02-22# Version:              V0.1############################################################################################################################################################### ModifIEd by:          xiaobin (XB)# ModifIEd date:        2012-03-31# Version:              V0.3############################################################################################################################################################### ModifIEd by:          xiaobin (XB)# ModifIEd date:        2012-04-01# Version:              V0.4############################################################################################################################################################### ModifIEd by:          # ModifIEd date:        # Version:              ############################################################################################################################################################### 版权说明:                                                                  ##           本程序版权归李贵斌所有,解释权属于所有者。                        ##           作为一个整体使用时,请附带以上说明。                              ##                                                                             ##           本程序完全免费使用。                                              ################################################################################ ################################################################################                               使用说明                                      #################################################################################                                                                             ##   命令行:perl processData.PL xxx.xls >> xxx.txt                            ##                                                                             ##   参数解释:                                                                ##           1. xxx.xls 为要进行处理的Excel文件名                              ##           2. >> 为管道符号                                                  ##           3. xxx.txt 为要保存的文件                                         ##                                                                             ################################################################################use strict;use warnings;use EnCoding;use Spreadsheet::ParseExcel;use Spreadsheet::ParseExcel::FmtUnicode;################################################################################ 主程序################################################################################my $oExcel = Spreadsheet::ParseExcel->new;dIE "You must provIDe a filename to "        ."to be parsed as an Excel file" unless @ARGV; #set for charactormy $oFmtC = Spreadsheet::ParseExcel::FmtUnicode->new(Unicode_Map => "GB2312");if($#ARGV < 0) {    exit;}my $oBook = $oExcel->Parse($ARGV[0],$oFmtC);my($iR,$iC,$oWkS,$oWkC);PrnBook($oBook);################################################################################ 主子程序################################################################################sub PrnBook {    my($oBook) = @_;    my($iR,$oWkC);    for(my $iSheet=0; $iSheet < $oBook->{SheetCount}; $iSheet++) {        $oWkS = $oBook->{Worksheet}[$iSheet];                my $sn = 0;                print "序号\t建档日期\t性别\t出生日期\r\n";        print "====\t==========\t====\t==========\r\n";                for(my $iR = $oWkS->{MinRow};                 defined $oWkS->{MaxRow} && $iR < $oWkS->{MaxRow} + 1; $iR++) {            $sn = $iR + 1;            print "$sn,\t";                                 for(my $iC = $oWkS->{MinCol};                        defined $oWkS->{MaxCol} && $iC < $oWkS->{MaxCol} + 1;                         $iC++) {                                                $oWkC = $oWkS->{Cells}[$iR][$iC];                                checkDateFmt($iC,$oWkC);                check2Sex($iC,$oWkC);            }                        print "\r\n";        }        print "============ 共处理 $sn 行数据 ============\r\n";    }}################################################################################ 模块说明:子程序## 功能说明:检查日期格式#           $_[0] == 4 为检查第4列的数据(0,1,2,3,4)#           $_[0] == 7 为检查第7列的数据(0,4,5,6,7)###############################################################################sub checkDateFmt {    if ($_[0] == 4 || $_[0] == 7) {                if ($_[1]->Value =~ m{ \s }xms) {        	 dIE "Not Value!";        }                if ($_[1]->Value =~             m{                ^                ([1-9]) ([0-9]) ([0-9]) ([0-9])     # Year                [-] +                               # -                ([0-9]) ([0-9])                     # Month                [-] +                               # -                ([0-9]) ([0-9])                     # Day                $            }xms            ) {            if ($_[0] == 4) {                print "--,\t";            }            else {                print "--\t";            }        }        elsif ($_[1]->Value =~             m{                ^                ([1-9]) ([0-9]) ([0-9]) ([0-9])     # Year                [-] ?                               # -                ([0-9]) ([0-9])                     # Month                [-] ?                               # -                ([0-9]) ([0-9])                     # Day                $            }xms            ) {            print "--\t";        }        else {            print "not match.\t";        }            }}################################################################################ 模块说明:子程序## 功能说明:检查性别#           (男,女)#           $_[0] == 5 为检查第4列的数据(0,5)###############################################################################sub check2Sex {    my $strMan = Encode::decode("CP936","男");    my $strWoman = Encode::decode("CP936","女");        if ($_[0] == 5) {        unless (Encode::decode("CP936",$_[1]->Value) =~             m{                ( $strMan | $strWoman )            }xms            ) {            print "UnkNow\t";        }        else {            print Encode::encode("CP936",).",\t";        }    }}
总结

以上是内存溢出为你收集整理的使用Perl对Excel进行处理全部内容,希望文章能够帮你解决使用Perl对Excel进行处理所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://www.outofmemory.cn/langs/1293094.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-10
下一篇 2022-06-10

发表评论

登录后才能评论

评论列表(0条)

保存