blib/lib/Spreadsheet/Excel2Text.pm

filter: Statementstmt 87.5% 14 / 16 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 5 / 5 Podpod n/a totaltotal 90.4% 19 / 21 CC 1 SCAR 0.6
CC
1
Cov
88%
BEGIN
1.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.1
↑ Summary
1 package Spreadsheet::Excel2Text;
2
3 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5
6 our $VERSION = '0.04';
7
8 1 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶ use Exporter;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 our @ISA = qw( Exporter );
11 1 our @EXPORT = qw( );
12 1 our %EXPORT_TAGS = ( );
13 1 our @EXPORT_OK = qw( &XlsSaveToText );
14 }
15
16 sub XlsSaveToText($$) {
17
18 my $xlsFile = shift;
19 my $txtFile = shift;
20 my $excelTab = "";
21
22 0 ▶ use Win32::OLE qw(in with);
Subroutine BEGIN: called CC=1 SCAR=2.6
23 use Win32::OLE::Const 'Microsoft Excel';
24
25 $Win32::OLE::Warn = 3;
26
27 my $excel = Win32::OLE->GetActiveObject('Excel.Application') || Win32::OLE->new('Excel.Application', 'Quit');
28
29 my $book = $excel->Workbooks->Open("$xlsFile");
30 my $sheet = $book->Worksheets(1);
31
32 $excel->ActiveCell->SpecialCells(xlLastCell)->Select;
33 my $lastLine = $excel->ActiveCell->Row;
34 my $lastRow = $excel->ActiveCell->Column;
35
36 my $array = $sheet->Range($sheet->Cells(1,1),$sheet->Cells($lastLine,$lastRow))->{'Value'};
37
38 $book->Close;
39
40 open(my $fhText, ">$txtFile") or die $!;
41
42 my $line = "";
43 my $field = "";
44 foreach my $refArray (@$array) {
45 $line = "";
46 foreach my $excelTab (@$refArray) {
47 $field = $excelTab;
48 no warnings;
49 $line .= $field."\t";
50 use warnings;
51 } # foreach
52 $line =~ s%\r?\n?%%g;
53 print $fhText $line, "\n";
54 } # foreach
55
56 $excel->Quit();
57
58 close($fhText) or die $!;
59
60 $txtFile;
61
62 } # XlsSaveToText
63
64 1;
65 __END__
↑ Summary