곰팅이의 열정

검색 :
RSS 구독 : 글 / 댓글 / 트랙백 / 글+트랙백

Excel을 xml로 저장하기.

2009/07/15 11:56, 글쓴이 혜승아빠

php의 엑셀 파서는 너무 후지다. 무슨 이유에선지 원본 파일의 내용과 파싱한 내용이 다르다.
다른 이름으로 저장을 해봤더니 정상적으로 읽어진다. 하지만 고객들에게 매번 저장을 새로 하라고 할 수는 없는 노릇이다.

perl로 테스트를 해 봤더니 원본도 이상없이 파싱이 된다. 흠 php엑셀 파서를 perl로 변경해야 할까?

#!/usr/bin/perl -w

    use strict;
    use Spreadsheet::ParseExcel;
    use Spreadsheet::ParseExcel::FmtUnicode;
    my $oExcel = new Spreadsheet::ParseExcel;
    my $oFmt = Spreadsheet::ParseExcel::FmtUnicode->new(Unicode_Map => "euc-kr");
    use XML::Excel;
    my $parser   = Spreadsheet::ParseExcel->new();
    my $excel_obj = XML::Excel->new({ParseExcel => $parser});

    my @arr_data;
    my $workbook = $parser->Parse('20090713101853_10002.XLS',$oFmt);

    for my $worksheet ( $workbook->worksheets() ) {

        my ( $row_min, $row_max ) = $worksheet->row_range();
        my ( $col_min, $col_max ) = $worksheet->col_range();

        for my $row ( $row_min .. $row_max ) {
            my @_row;
            for my $col ( $col_min .. $col_max ) {
                my $cell = $worksheet->get_cell( $row, $col );
                next unless $cell;
                push(@_row, $cell->value());

                #print "Row, Col    = ($row, $col)\n";
                #print "Value       = ", $cell->value(),       "\n";
                #print "Unformatted = ", $cell->unformatted(), "\n";
                print "#";
            }

            $arr_data[$row] = \@_row;
        }
    }
    $excel_obj->{column_data} = \@arr_data;
    $excel_obj->print_xml('aa.xml');

2009/07/15 11:56 2009/07/15 11:56

맨 위로

crontab에 작업 watchdog 설정.

2009/06/17 14:42, 글쓴이 혜승아빠
perl로 watchdog 프로그램을 하나 만든 후 crontab에 작업을 등록함
[root@pimz13 ~]# crontab -e
00,5,10,15,19,20,25,30,35,38,40,45,50,55 * * * * /usr/bin/perl /root/watchdog.sh
5분에 한 번씩 watchdog을 실행 함

crontab은 환경을 전혀 load하지 않는다. 그러므로 shell 프로그램에서 사용자 환경을 load 한 후
perl로 만든 프로세스 관리 프로그램을 실행해야 함.

#!/bin/sh
. ~root/.bash_profile
perl /root/watchdog.pl

등록되지 않은 프로세스들을 검사해서 자동으로 실행한다.


2009/06/17 14:42 2009/06/17 14:42

맨 위로

perl에서 utf-8 을 cp949 로 변경하기 Text::Iconv사용

2009/05/22 12:53, 글쓴이 혜승아빠
use Text::Iconv;
$c = Text::Iconv->new("utf8","cp949");
$_datas = $c->convert( $str_utf8);

Encode 모듈에서 오류 나던것들이 해결 됨.
2009/05/22 12:53 2009/05/22 12:53

맨 위로

perl 날짜 계산하기..

2009/05/20 16:41, 글쓴이 혜승아빠
#!/usr/bin/perl -w

use strict ;
use Date::Calc qw(Add_Delta_Days) ;

my ( $todayd, $todaym, $todayy ) = (localtime)[3..5] ;
$todaym += 1 ;
$todayy  += 1900 ;

my ($yesty,$yestm,$yestd) = Add_Delta_Days($todayy,$todaym,$todayd, -1) ;



어제 구하기..

2009/05/20 16:41 2009/05/20 16:41

맨 위로

ActivePerl사용시 DBD::mysql 설치

2009/05/12 13:24, 글쓴이 혜승아빠

DBD::mysql - A Perl5 Database Interface to the MySQL database
=============================================================

The driver installation is described in

  INSTALL.html

In short: If you are using

  Windows/ActivePerl

    1.) If you need to use an HTTP Proxy, set the environment
        variable http_proxy, for example like this:

          set http_proxy=http://myproxy.com:8080/

    2.) The actual installation is as simple as

   ppm install DBI
          ppm install DBD::mysql

        As of this writing, the above procedure won't work with
        ActivePerl 5.8.0, because so far a PPM for DBD::mysql is
        not available from the ActiveState server. I don't know
        why. However, Randy Kobes has kindly donated a PPM package
        to his own repository. You can use this as follows:

          ppm install http://theoryx5.uwinnipeg.ca/ppms/DBD-mysql.ppd

2009/05/12 13:24 2009/05/12 13:24

맨 위로

[패턴] euc-kr의 패턴 매칭 예제 2

2008/12/05 15:18, 글쓴이 혜승아빠
use Encode qw/encode decode/;

my $utf8   = decode("euc-kr", $content);
my $cnt = 0;

# utf-8 로 format이 변경되면 [\w]에서 인식 가능한 상태가 됨
while ($utf8 =~ /_OBJ_GRID.setTextOnly\(\"([\w]+)\", ([\w]+), \"([\w\(\)\-]+)\"\);/g) {
    # 한글을 화면으로 보려면 다시 euc-kr로 변경해야 한다
    my $val = encode("euc-kr", $3);
    print $val . "\n";
    $cnt++;
}


2008/12/05 15:18 2008/12/05 15:18

맨 위로