CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate: Problem: Converting XLSX file to CSV : Edit Log



vsmeruga
Novice

Apr 29, 2014, 8:11 AM


Views: 13542
Problem: Converting XLSX file to CSV

<p>I am 3 days old to perl programming and I am trying hard to read the posts through google to my problems and finding solutions.</p>

<p>During that process I found a script for the solution and Implemented it with my source file.</p>

</p>I am seeing an issue with it and not able to understand how to resolve it.</p>

<p> Issue is: Source file has 45 fields and 21st field data is Blanks. </p>

<p>In the csv file output: Next fields(22nd fields) data is placed in 21st field and remaining follows.. Due to that output is wrong.</p>

<p> Please help me with this issue as I am new to Perl scripting </p>


Code
 
#!/usr/bin/perl

use strict;
use warnings;
use Spreadsheet::XLSX;

open STDOUT, ">", "output.csv" or die "$0: open: $!";
open STDERR, ">&STDOUT" or die "$0: dup: $!";

my $excel = Spreadsheet::XLSX -> new ('/home/source/srcfile.xlsx');


my $line;
foreach my $sheet (@{$excel -> {Worksheet}}) {
#printf("Sheet: %s\n", $sheet->{Name});
$sheet -> {MaxRow} ||= $sheet -> {MinRow};
foreach my $row ($sheet -> {MinRow} .. $sheet -> {MaxRow}) {
$sheet -> {MaxCol} ||= $sheet -> {MinCol};
foreach my $col ($sheet -> {MinCol} .. $sheet -> {MaxCol}) {
my $cell = $sheet -> {Cells} [$row] [$col];
if ($cell) {
$line .= "\"".$cell -> {Val}."\",";
}
}
chomp($line);
print "$line\n";
$line = '';
}
}



(This post was edited by FishMonger on Apr 30, 2014, 6:33 AM)


Edit Log:
Post edited by FishMonger (Veteran) on Apr 30, 2014, 6:33 AM


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives