2014-02-14 1 views
3

.xls.csv perl로 변환하는 방법? 이 모듈은 무엇입니까? 이것에 대한 예가 있습니까? 변환하는 가장 좋은 방법은 무엇입니까?.xls 파일을 .csv 파일로 변환하는 방법은 무엇입니까?

use Spreadsheet::ParseExcel; 
my $xlsparser = Spreadsheet::ParseExcel->new(); 
my $xlsbook = $xlsparser->parse('/home/Admin/Downloads/abc.xls'); 
my $xls = $xlsbook->worksheet(0); 
my ($row_first, $row_last) = $xls->row_range(); 
my ($col_first, $col_last) = $xls->col_range(); 
my $csv = '/home/Admin/Downloads/ram.csv'; 
for my $row ($row_first .. $row_last) {  # Step through each row 
    for my $col ($col_first .. $col_last) { # Step through each column 
     my $cell = $xls->get_cell($row, $col); # Get the current cell 
     next unless $cell; 
     $csv .= $cell->unformatted(); # Get the cell's raw data -- no border 
             # colors or anything like that 
     if ($col == $col_last) { 
      $csv .= "\n"; 
     } else { 
      $csv .= ","; 
     } 
    } 
} 
open(my$FH ,'>',"$csv") or die "oops!"; 

while (my$line = <$xlsbook>){ 
    print $FH $line; 
} 

oops!

+0

좋은 참조 http://www.ehow.com/how_7352636_convert-xls-csv-perl.html http://vinayhacks.blogspot.in/2010/04/converting-xls-to-csv- on-linux.html –

+0

내 업데이트 질문보기 – Ram

+0

가능한 [.csls 파일로 .xls 파일 변환?] (http://stackoverflow.com/questions/21772377/converting-xls-file-to-csv-file) –

답변

1

perl 스크립트를 사용하십시오. CPAN의 Spreadsheet :: ParseExcel perl 모듈을 사용하여 xls 파일을 구문 분석 한 다음 csv로 결과를 출력하면 정상적으로 작동합니다.

Here is the link

and this link

+0

내 업데이트 질문보기 – Ram

1

당신은 당신의 코드에 오타가 있습니다.

open(my $FH ,'>',"$csv") or die "oops!"; 

while (my $line = <$FH>){ 
    print $FH $line; 
} 
+0

CSV.pl 줄에서 GLOB 참조가 아닙니다.이 오류 – Ram

+0

이 오류를 수정했습니다. 다시 시도하십시오. – user1126070

+0

나는 그것이'open (my $ FH, '>', '$ csv') 또는 die oops!라고 잘못 생각합니다. while (my $ line = <$FH>) { ' – Ram