473,549 Members | 2,745 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

creating a hash of hash from excel file

41 New Member
hi,

i have one excel file, i want to create a hash of hash from the excel file, like:

Expand|Select|Wrap|Line Numbers
  1. %hash=
  2. [
  3.  sheet1 => [
  4.               {
  5.                 'VALUES' => 'tryrt',
  6.                 'ROWNUM' => 13,
  7.                 'COLUMNNUM' => 1
  8.               },
  9.               {
  10.                 'VALUES' => 'Hyderabad',
  11.                 'ROWNUM' => 7,
  12.                 'COLUMNNUM' => 1
  13.               },
  14.             ],
  15.  sheet2 => [
  16.       {
  17.               'VALUES' => 'tryrsdft',
  18.               'ROWNUM' => 1sdf3,
  19.               'COLUMNNUM' => 1sdf
  20.              },
  21.              {
  22.               'VALUES' => 'Hyddserabad',
  23.               'ROWNUM' => 7ds,
  24.               'COLUMNNUM' => 1342
  25.              },
  26.     ],
  27. ....
  28. ....
  29. ];


Expand|Select|Wrap|Line Numbers
  1. use Spreadsheet::ParseExcel;
  2. use Data::Dumper;
  3. my $oBook = Spreadsheet::ParseExcel::Workbook->Parse('source.xls');
  4. my($Row, $Col, $Wrksht, $oWkC);
  5. foreach my $Wrksht(@{$oBook->{Worksheet}}) 
  6. {
  7.  my $sheetname = $Wrksht->{Name};
  8.     for(my $Row = $Wrksht->{MinRow}; defined $Wrksht->{MaxRow} && $Row <= $Wrksht->{MaxRow} ; $Row++) 
  9.  {
  10.   for(my $Col = $Wrksht->{MinCol}; defined $Wrksht->{MaxCol} && $Col <= $Wrksht->{MaxCol} ; $Col++) 
  11.   {
  12.    $oWkC = $Wrksht->{Cells}[$Row][$Col];
  13.             if ($oWkC) 
  14.    {
  15.  
  16.     my %HoAexcel = ( SHEETNAME => $sheetname, COLUMNNUM => $Col+1, ROWNUM => $Row+1, VALUES => $oWkC->Value, );
  17.  
  18.     push (@loop, \%HoAexcel);
  19.  
  20.    }
  21.         }
  22.     }
  23. }
  24. print Dumper(@loop);
I have written a script
But i am not able to create like this.
after running that script, the result is diplaying like this:
Expand|Select|Wrap|Line Numbers
  1. $VAR1 = {
  2.           'VALUES' => '1',
  3.           'ROWNUM' => 1,
  4.           'COLUMNNUM' => 1
  5.         };
  6. $VAR2 = {
  7.           'VALUES' => '2',
  8.           'ROWNUM' => 2,
  9.           'COLUMNNUM' => 1
  10.         };
  11. $VAR3 = {
  12.           'VALUES' => '1231',
  13.           'ROWNUM' => 3,
  14.           'COLUMNNUM' => 1
  15.         };
  16.  
Can somebody help me to creating above multi dimensional hash.
Jan 23 '09 #1
6 6015
KevinADC
4,059 Recognized Expert Specialist
Your first example data is not a hash of hashes. It is an array of arrays of hashes. In the perl code you posted, change this line:

print Dumper(@loop);

change it to:

print Dumper \@loop;

and see what the output looks like.
Jan 23 '09 #2
dillipkumar
41 New Member
Hi KevinADC,

After changing the line from print Dumper(@loop) to print Dumper \@loop;

the o/p is like:
Expand|Select|Wrap|Line Numbers
  1. $VAR1 = [
  2.          { 
  3.            'VALUES' => '1', 
  4.            'ROWNUM' => 1, 
  5.            'COLUMNNUM' => 1 
  6.          },
  7.          { 
  8.            'VALUES' => '2', 
  9.            'ROWNUM' => 2, 
  10.            'COLUMNNUM' => 1 
  11.          }, 
  12.          { 
  13.            'VALUES' => '1231', 
  14.            'ROWNUM' => 3, 
  15.            'COLUMNNUM' => 1 
  16.          }
  17.  ]; 
  18.  
But I need the the excel sheet name in this hash of hash.

Tx,
Dillip.
Jan 27 '09 #3
numberwhun
3,509 Recognized Expert Moderator Specialist
dillipkumar,

We have corrected your code tags a couple of times now. Please be sure and use them the next time you post code into the forums.

Regards,

Jeff
Jan 27 '09 #4
KevinADC
4,059 Recognized Expert Specialist
@dillipkumar
My only suggestion is to read the module documentation. Apparently this line returns a reference to an array of hashes:

Expand|Select|Wrap|Line Numbers
  1. my $oBook = Spreadsheet::ParseExcel::Workbook->Parse('source.xls');
  2.  
Look over the module and see if it has a method for returning a hash of hashes if you're sure thats what you really want. The array is probably used to keep the original order of the records. If you use a hash of hashes the original order of the records will most likely not be retained.
Jan 27 '09 #5
bazz
3 New Member
what do you get if you dump the \%HoAexcel at the same point in your script as the print Dumper(@loop);

bazz
Oct 5 '09 #6
numberwhun
3,509 Recognized Expert Moderator Specialist
@bazz
I hate to say this, but this thread is about 8 months old. I am sure the OP either solved this or moved on. Please keep an eye on the age of the thread you are viewing.

Also, you may want to try PMing the OP who asked the question instead of looking like you are hijacking their thread.

Regards,

Jeff
Oct 5 '09 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
7010
by: Jeremy Langworthy | last post by:
Hi I am trying to create a MS Excel format CSV but I can't figure out how to get the line feed/carriage return/new record working properly. I am nding each line/record with these characters: "\r\n" but the Excel file just loads all the field in one row as if it doesn't recognise these characters. These are the headers I am using to...
9
8875
by: Paul | last post by:
Hi all Arggghhh........... The problem.....I want the user to be able to create an excel document and name particular cells in the document where they want the data to be placed and then save this out of an XML file or Excel Template file. Next I need to convert a dataset to xml and try and transform this data into the users xml...
4
3007
by: Del | last post by:
I need to create Pivot table in Excel from Access. Currently I run a query and output the data to an excel worksheet and create the pivots via automation. The issue I face is that the query may return more than 65000 rows of data. Is there a way I can create the Pivot tables without having to output the data to excel first? Any help...
5
4689
by: Mike Turco | last post by:
What is the difference between creating relationships in the front-end vs. the back-end database? I was trying to create a relationship in a database front-end and noticed that I could not check the referential integrity box. What gives? Continuing on with that line of thinking, I understand what do the relationships do for you in a...
5
2239
by: lis0122 | last post by:
I'm a database marketing manager for a small non-profit. I created a query that prompts you for a company name and then pulls a list of all of our contacts in the database in that company. Our sales folks are always asking for company contact lists and I just plug it in to this query and send them the list in excel. I want to give them...
3
1849
by: A.M | last post by:
Hi, Using ASP.NET/VB.NET and SQL Server backend, I need to return calculation results to user as an Access MDB file or Excel XLS sheet. What would be the best way to create a MDB or XLS file inside a .NET program? Thanks, Ali
2
1961
by: morph276 | last post by:
I am working on a program and need to store sensitive data. I am able to create text files but I need to files to be secure. Do I use the hash class to secure my data and how would this affect new data being added to the file? Any help would be appreciated.
7
2682
by: Paul | last post by:
Hi I have created an excel file download feature within a .net application using Microsoft Office XP primary interop assembly for excel. I was just wondering if anyone knows if you can also embed excel formulas in the excel download, for example a running total on a column, thanks. -- Paul G Software engineer.
5
1845
numberwhun
by: numberwhun | last post by:
Ok, I have a ".csv" file that contains two lines (VERY LONG lines). Basically, the first line is the headers defining what each field in the second line is. ie: Name1,Name2,Name3,........ Value1,Value2,Value3,....... Unfortunately, I am unable to provide any sample data as it is proprietary and customer confidential, but that is...
0
7520
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7957
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7809
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6043
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5368
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3500
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1941
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1059
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
763
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.