hi,
i have one excel file, i want to create a hash of hash from the excel file, like: - %hash=
-
[
-
sheet1 => [
-
{
-
'VALUES' => 'tryrt',
-
'ROWNUM' => 13,
-
'COLUMNNUM' => 1
-
},
-
{
-
'VALUES' => 'Hyderabad',
-
'ROWNUM' => 7,
-
'COLUMNNUM' => 1
-
},
-
],
-
sheet2 => [
-
{
-
'VALUES' => 'tryrsdft',
-
'ROWNUM' => 1sdf3,
-
'COLUMNNUM' => 1sdf
-
},
-
{
-
'VALUES' => 'Hyddserabad',
-
'ROWNUM' => 7ds,
-
'COLUMNNUM' => 1342
-
},
-
],
-
....
-
....
-
];
- use Spreadsheet::ParseExcel;
-
use Data::Dumper;
-
my $oBook = Spreadsheet::ParseExcel::Workbook->Parse('source.xls');
-
my($Row, $Col, $Wrksht, $oWkC);
-
foreach my $Wrksht(@{$oBook->{Worksheet}})
-
{
-
my $sheetname = $Wrksht->{Name};
-
for(my $Row = $Wrksht->{MinRow}; defined $Wrksht->{MaxRow} && $Row <= $Wrksht->{MaxRow} ; $Row++)
-
{
-
for(my $Col = $Wrksht->{MinCol}; defined $Wrksht->{MaxCol} && $Col <= $Wrksht->{MaxCol} ; $Col++)
-
{
-
$oWkC = $Wrksht->{Cells}[$Row][$Col];
-
if ($oWkC)
-
{
-
-
my %HoAexcel = ( SHEETNAME => $sheetname, COLUMNNUM => $Col+1, ROWNUM => $Row+1, VALUES => $oWkC->Value, );
-
-
push (@loop, \%HoAexcel);
-
-
}
-
}
-
}
-
}
-
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: - $VAR1 = {
-
'VALUES' => '1',
-
'ROWNUM' => 1,
-
'COLUMNNUM' => 1
-
};
-
$VAR2 = {
-
'VALUES' => '2',
-
'ROWNUM' => 2,
-
'COLUMNNUM' => 1
-
};
-
$VAR3 = {
-
'VALUES' => '1231',
-
'ROWNUM' => 3,
-
'COLUMNNUM' => 1
-
};
-
Can somebody help me to creating above multi dimensional hash.
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.
Hi KevinADC,
After changing the line from print Dumper(@loop) to print Dumper \@loop; the o/p is like: -
$VAR1 = [
-
{
-
'VALUES' => '1',
-
'ROWNUM' => 1,
-
'COLUMNNUM' => 1
-
},
-
{
-
'VALUES' => '2',
-
'ROWNUM' => 2,
-
'COLUMNNUM' => 1
-
},
-
{
-
'VALUES' => '1231',
-
'ROWNUM' => 3,
-
'COLUMNNUM' => 1
-
}
-
];
-
But I need the the excel sheet name in this hash of hash.
Tx,
Dillip.
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
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: -
my $oBook = Spreadsheet::ParseExcel::Workbook->Parse('source.xls');
-
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.
what do you get if you dump the \%HoAexcel at the same point in your script as the print Dumper(@loop);
bazz
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
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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...
|
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...
|
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...
|
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...
|
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...
| |
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
|
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.
|
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.
|
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...
|
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...
|
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...
| |
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...
|
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...
|
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...
|
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...
|
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
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |