Solved

Parsing Excel Data

Posted on 2006-11-27
10
550 Views
Last Modified: 2008-02-01
I have been asking this question but due to the vague nature of the question I am not getting what exactly I am looking for.
I have come up with a mechanism how I want it and I will detail it down now. But to understand it you should open both links of the excel sheets.

http://socr.uwindsor.ca/~choudh8/output.xls
http://socr.uwindsor.ca/~choudh8/dummy.xls

As you see in the output.xls some data is sitting there. Please notice for every IPD file path there is a data. It Contents, Number of Records and Size.
Notice in the other file dummy.xls Contents are already there. All I need is to transfer these records and file sizes for every file. With the file name on top and its data underneath and then it moves towards right
Here is the Mechanism
IF{ @ column A of output file the script sees a path to IPD file
GO TO {dummy.xls on column B first row and copy/paste the IPD file name and in the next row copy/paste (Number of Records and Size)
GO back to output.xls
Match the contents underneath this IPD file
IF {the contents match place its data in front of the matched contents}
ELSE{try to match the next content (If it macths place the data otherwise move forward}
I guess    FOR LOOP    will be used
Do this process until the script hits the BLANK row (as seen in the output.xls file)
Go back to the first IF statement and do the exactly same process.
THE ONLY DIFFERENCE WILL BE THIS TIME THE IPD FILE NAME SHOULD BE COPY/PASTED TO THE NEXT COLUMN AND SO ON UNTIL THERE ARE IS NO DATA LEFT IN THE OUTPUT.XLS
To further understand the last point suppose the first IPD data copy/pasted in from Column B to C then next data should be from Column E to F and so on.
0
Comment
Question by:Musaab1
  • 5
  • 5
10 Comments
 
LVL 84

Accepted Solution

by:
ozo earned 500 total points
ID: 18027097
#is this what you mean?
use Spreadsheet::ParseExcel;
use Spreadsheet::WriteExcel::Simple;
my $oExcel = new Spreadsheet::ParseExcel;
my $contents=$oExcel->Parse('dummy.xls');
@C=map {[map{$_&&$_->{Val}}@$_]} @{$contents->{Worksheet}[0]{Cells}};
@row{map{$_->[0]=~/(\S.*\S)/}@C}=0..$#C;
my $log=$oExcel->Parse('output.xls');
for( @{$log->{Worksheet}[0]{Cells}} ){
    push @{$C[0]},$arg = $_->[0]{Val},undef if @{$_}==1;
    my($c,$n,$s)=map{$_&&$_->{Val}}@$_;
    s/^\s+//,s/\s+$// for $c;
    @{$C[$row{$c}]}[$#{$C[0]}-1,$#{$C[0]}] = $n,$s if $row{$c};
}
my $ss = Spreadsheet::WriteExcel::Simple->new;

$ss->write_row($_) for @C;
$ss->save("new.xls");
0
 

Author Comment

by:Musaab1
ID: 18027662
I am trying to test this code and it says that
Can't locate spreadsheet/writeexcel/simple.pm in @INC contains: c:/perl/lib c:/perl/site/lib .) at test1.pl line 3
BEGIN failed--compilation aborted at test1.pl line 3

Thanks a lot OZO for helping
0
 

Author Comment

by:Musaab1
ID: 18029607
Hello OZO
I placed the simple.pm in the spreadsheet/writeexcel loaction but now I see this

Can't locate object method "new" via package "spreadsheet::writeexcel::simple.pm" (
perhaps you forgot to load "spreadsheet::writeexcel::simple.pm"? at test1.pl line 15
0
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
LVL 84

Expert Comment

by:ozo
ID: 18032346
0
 

Author Comment

by:Musaab1
ID: 18032514
Hello Ozo I totally agree wiht your code as you are the master in perl but i dont know what should I do in this situation when I am getting this error even though everythign seems fine.

Thanks
0
 
LVL 84

Expert Comment

by:ozo
ID: 18032893
did you install Spreadsheet::WriteExcel::Simple?
try the command
cpan Spreadsheet::WriteExcel::Simple
0
 

Author Comment

by:Musaab1
ID: 18038528
its working now OZo but now I am getting this
It runs and then stops with this comment
Modification of read-only value attempted at  test.pl line 5
0
 
LVL 84

Expert Comment

by:ozo
ID: 18042469
Is dummy.xls the same as the one you posted?
What do you get from

use Spreadsheet::ParseExcel;
my $oExcel = new Spreadsheet::ParseExcel;
my $contents=$oExcel->Parse('dummy.xls');
use Data::Dumper;
print Dumper map{ref} @{$contents->{Worksheet}[0]{Cells}};
print Dumper map {[map{ref}@$_]} @{$contents->{Worksheet}[0]{Cells}};
0
 
LVL 84

Expert Comment

by:ozo
ID: 18042503
and what do you get from
print Dumper map {[map{$_&& join', ',keys %$_}@$_]} @{$contents->{Worksheet}[0]{Cells}};
0
 

Author Comment

by:Musaab1
ID: 18042509
Thanks for ur help Ozo I am closing this question too I wrote a macro to do this job
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Remove Malware code from PHP file 6 82
MySQL Web Database 5 115
Transforming a Soap message to a simple xml message! 10 146
Is it true to say that Python is successor of Perl? 7 173
On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

785 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question