Hi,
I am currently working on excel validation using Perl. I am new to Excel validation but not for Perl. I have a question regarding one of the validation. Could anyone please tell me how to get the number of duplicate rows based on a particular cell value of each these duplicate rows. I mean all the cell values of a row will not be duplicated but a individual columns cell value will be duplicated and I need to create a separate excel with all these duplicates.
Eg :
Name Org Dep Place
RavindraN TCS Development Blore
Ravi TCS Scripting blore
Vimal AOL Development blore
Ram Aol Development blore
Priya aol Scripting blore
Here, I need to get the duplicate rows based on Dep. The output should be :
RavindraN TCS Development Blore
Vimal AOL Development blore
Ram Aol Development blore
and
Ravi TCS Scripting blore
Priya aol Scripting blore
Thanks
Ravi
4 5435
What have you tried so far?
Hi,
Since I am new to excel validation, I am trying out the how to get the value and display them. I tried to get all the values of a particular cell and store it in a array so that I can try to get a duplicated from that cell.
I need to get the duplicate records based on the column "Dep". - #!/usr/local/bin/perl
-
-
use strict;
-
use Spreadsheet::ParseExcel;
-
-
my %UniqueCell_Row = ();
-
my $excel_name;
-
-
$excel_name = "D:\\RAVINDRAN\\Excel-Email-sending\\name.xls";
-
print "Excel Name -> <$excel_name> \n";
-
-
my $workbook = Spreadsheet::ParseExcel::Workbook->Parse($excel_name);
-
-
print "Book -> <$workbook> \n";
-
my $cont_col;
-
my $cell_value;
-
-
### To get the particular columns all the value
-
foreach my $sheet (@{$workbook->{Worksheet}}) {
-
printf("Sheet: %s\n", $sheet->{Name});
-
my @cols;
-
-
foreach my $col ($sheet->{MinCol} .. $sheet->{MaxCol}) {
-
print "Column -> <$col> \n";
-
print "$sheet->{Cells}[0][$col]->{Val} \n";
-
if ($sheet->{Cells}[0][$col]->{Val} eq "Dep") {
-
$cont_col = $col;
-
print "Column Number -> $cont_col\n";
-
last;
-
}
-
}
-
-
for(
-
my $iR = $sheet->{MinRow};
-
defined $sheet->{MaxRow} && $iR <= $sheet->{MaxRow};
-
$iR++
-
){
-
-
# fetch columns
-
my $cell = $sheet->{Cells}[$iR][$cont_col];
-
print "sheet->{Cells}[$iR][$cont_col] \n";
-
print "cell->{Val} ----> <$cell->{Val}> \n";
-
$cell_value = $cell->{Val};
-
push(@cols,$cell_value);
-
#push ( @{$UniqueCell_Row{$cell_value}},"$row,$col,$cell_value" );
-
}
-
-
print "Colllummmn : <@cols> \n";
-
}
-
-
## This is just to print all the columns value
-
foreach my $sheet (@{$workbook->{Worksheet}}) {
-
printf("Sheet: %s\n", $sheet->{Name});
-
foreach my $row ($sheet->{MinRow} .. $sheet->{MaxRow}) {
-
foreach my $col ($sheet->{MinCol} .. $sheet->{MaxCol}) {
-
-
my $cell = $sheet->{Cells}[$row][$col];
-
my $cell_value = $cell->{Val};
-
-
if ( $cell ) {
-
printf("( %s , %s ) => %s\n", $row, $col, $cell->{Val});
-
$UniqueCell_Row{$row}{$col} = $cell_value;
-
}
-
if ( $cell && $cell_value eq "Dep" ) {
-
printf("Department Cell Value is : ( %s , %s ) => %s\n", $row, $col, $cell->{Val});
-
#push ( @{$UniqueCell_Row{$cell_value}},"$row,$col,$cell_value" );
-
}
-
}
-
}
-
}
-
-
## This is just to get the values of the record
-
my @row_cont = ();
-
foreach my $row ( sort keys %UniqueCell_Row ) {
-
foreach my $cell ( sort keys %{$UniqueCell_Row{$row}} ) {
-
print "Rows and Column -----> <$row> | <$cell> | $UniqueCell_Row{$row}{$cell} \n";
-
}
-
}
Could you please help me on this.
Thanks
Hi,
I have taken the duplicate records based on the particular cell value. I need to created excel file for all the duplicate records. Here I am facing problem with writing the header only once for all the new excels created here.
Here is the updated code : - #!/usr/local/bin/perl
-
-
use strict;
-
use Spreadsheet::ParseExcel;
-
use Spreadsheet::WriteExcel;
-
-
my %UniqueCell_Row = ();
-
my $excel_name;
-
-
$excel_name = "D:\\RAVINDRAN\\Excel-Email-sending\\name.xls";
-
print "Excel Name -> <$excel_name> \n";
-
-
my $workbook = Spreadsheet::ParseExcel::Workbook->Parse($excel_name);
-
-
print "Book -> <$workbook> \n";
-
my $cont_col;
-
my $cell_value;
-
my @cols;
-
-
### To get the particular columns all the value
-
foreach my $sheet (@{$workbook->{Worksheet}}) {
-
printf("Sheet: %s\n", $sheet->{Name});
-
-
foreach my $col ($sheet->{MinCol} .. $sheet->{MaxCol}) {
-
print "Column -> <$col> \n";
-
print "$sheet->{Cells}[0][$col]->{Val} \n";
-
if ($sheet->{Cells}[0][$col]->{Val} eq "Dep") {
-
$cont_col = $col;
-
print "Column Number -> $cont_col\n";
-
last;
-
}
-
}
-
-
for(
-
my $iR = $sheet->{MinRow};
-
defined $sheet->{MaxRow} && $iR <= $sheet->{MaxRow};
-
$iR++
-
){
-
-
# fetch columns
-
my $cell = $sheet->{Cells}[$iR][$cont_col];
-
print "sheet->{Cells}[$iR][$cont_col] \n";
-
print "cell->{Val} ----> <$cell->{Val}> \n";
-
$cell_value = $cell->{Val};
-
push(@cols,$cell_value);
-
#push ( @{$UniqueCell_Row{$cell_value}},"$row,$col,$cell_value" );
-
}
-
-
print "Colllummmn : <@cols> \n";
-
}
-
-
## This is just to print all the columns value
-
foreach my $sheet (@{$workbook->{Worksheet}}) {
-
printf("Sheet: %s\n", $sheet->{Name});
-
foreach my $row ($sheet->{MinRow} .. $sheet->{MaxRow}) {
-
foreach my $col ($sheet->{MinCol} .. $sheet->{MaxCol}) {
-
-
my $cell = $sheet->{Cells}[$row][$col];
-
my $cell_value = $cell->{Val};
-
-
if ( $cell ) {
-
printf("( %s , %s ) => %s\n", $row, $col, $cell->{Val});
-
$UniqueCell_Row{$row}{$col} = $cell_value;
-
}
-
if ( $cell && $cell_value eq "Dep" ) {
-
printf("Department Cell Value is : ( %s , %s ) => %s\n", $row, $col, $cell->{Val});
-
#push ( @{$UniqueCell_Row{$cell_value}},"$row,$col,$cell_value" );
-
}
-
}
-
}
-
}
-
-
## This is just to get the unique record
-
my @row_cont = ();
-
foreach my $row ( sort keys %UniqueCell_Row ) {
-
foreach my $cell ( sort keys %{$UniqueCell_Row{$row}} ) {
-
print "Rows and Column -----> <$row> | <$cell> | $UniqueCell_Row{$row}{$cell} \n";
-
#if ( $UniqueCell_Row{$row}{$cont_col}
-
-
}
-
}
-
-
print "========================================= \n";
-
-
my @Dup;
-
my %uniqISU = ();
-
my $duplicate;
-
my $unique;
-
-
foreach my $row ( sort keys %UniqueCell_Row ) {
-
foreach my $cell ( sort keys %{$UniqueCell_Row{$row}} ) {
-
print "Rows and Column -----> <$row> | <$cell> | $UniqueCell_Row{$row}{$cont_col} \n";
-
if ( grep( /$UniqueCell_Row{$row}{$cont_col}/, @Dup ) ) {
-
print "Present : <$UniqueCell_Row{$row}{$cont_col}> | <@cols> \n";
-
$duplicate = $UniqueCell_Row{$row}{$cont_col};
-
$uniqISU{$duplicate}{$row}{$cell} = $UniqueCell_Row{$row}{$cell};
-
}
-
else {
-
print "NOT PRESENT : <$UniqueCell_Row{$row}{$cont_col}> \n";
-
push @Dup, $UniqueCell_Row{$row}{$cont_col};
-
$duplicate = $UniqueCell_Row{$row}{$cont_col};
-
$uniqISU{$duplicate}{$row}{$cell} = $UniqueCell_Row{$row}{$cell};
-
}
-
}
-
}
-
-
print "***************************************************** \n";
-
foreach my $cell_val ( sort keys %uniqISU ) {
-
print "Cell Value ---> <$cell_val> \n";
-
foreach my $rows ( sort keys %{$uniqISU{$cell_val}} ) {
-
foreach my $cell ( sort keys %{$uniqISU{$cell_val}{$rows}} ) {
-
print "Cell_val -> <$cell_val> | rows -> <$rows> | columns -> <$cell> | Col Val -> <$uniqISU{$cell_val}{$rows}{$cell}> \n";
-
}
-
}
-
}
-
-
my $format;
-
my ($header1,$header2,$header3);
-
my %header;
-
-
foreach my $cell_val ( sort keys %uniqISU ) {
-
my $header = 1;
-
my $workbook;
-
my $sheet1;
-
-
if ( $cell_val ne "Dep" ) {
-
$workbook = Spreadsheet::WriteExcel->new("$cell_val.xls");
-
$sheet1 = $workbook->add_worksheet("$cell_val");
-
-
# Add a Format
-
$format = $workbook->add_format();
-
$format->set_bold();
-
$format->set_size(12);
-
$format->set_color('blue');
-
$format->set_align('center');
-
-
$sheet1->set_column(0, 0);
-
}
-
-
-
foreach my $rows ( sort keys %{$uniqISU{$cell_val}} ) {
-
foreach my $cell ( sort keys %{$uniqISU{$cell_val}{$rows}} ) {
-
if ( $header == 1 && $cell_val eq "Dep" ) {
-
print "Header Detail ************ $rows, $cell, $uniqISU{$cell_val}{$rows}{$cell}\n";
-
$header{$cell_val}{$rows}{$cell} = $uniqISU{$cell_val}{$rows}{$cell};
-
}
-
elsif ( $cell_val ne "Dep" ) {
-
print "$header{$cell_val},$header{$cell_val}{$rows},$header{$cell_val}{$rows}{$cell} \n";
-
$sheet1->write($header{$cell_val},$header{$cell_val}{$rows},$header{$cell_val}{$rows}{$cell}) if ( $header == 1 );
-
$sheet1->write($rows, $cell, $uniqISU{$cell_val}{$rows}{$cell});
-
}
-
$header++;
-
}
-
}
-
}
hi ,
Just want to let you know that the code that you have pasted helped me understand how to solve one of my problem..i was new to perl and wondering where/how to start and it gave me a good starting point..
thanks,
vijay
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Dixie |
last post by:
How do I, in VBA from an access form module, add 5 rows to the top of a
spreadsheet called MySpreadsheet.xls. The worksheet is called MyWorksheet
and there is already data in the first 5 rows. I simply need to insert 5
blank rows at the top and move the rest of the data down so it starts at row
6.
dixie
|
by: Peter |
last post by:
I am having a problem reading an Excel file that is XML based. The directory
I am reading contains Excel files that can be of two types. Either generic Microsoft
based or XML based. I am reading the Microsoft based files with an OleDbDataAdapter.
Then filling the contents of the first worksheet into a dataset.
However when I try to add the XML based file to my dataset using an XmlTextReader
I can never seem to get it to save to a...
|
by: Chris Becker |
last post by:
I want to create a TableCell object once and add it to many tables:
Dim cell As New TableCell
cell.Style.Add("background-color", s)
cell.Style.Add("cursor", "pointer")
cell.Width = Unit.Pixel(CELLDIMENSION)
cell.Height = Unit.Pixel(CELLDIMENSION)
cell.HorizontalAlign = HorizontalAlign.Center
cell.Text = " "
cell.Attributes.Add("Title", s)
|
by: clare at snyder.on.ca |
last post by:
I have a SQL query I need to design to select name and email addresses
for policies that are due and not renewed in a given time period. The
problem is, the database keeps the information for every renewal in
the history of the policyholder.
The information is in 2 tables, policy and customer, which share the
custid data. The polno changes with every renewal Renewals in 2004
would be D, 2005 S, and 2006 L. polexpdates for a given customer...
|
by: Frank M. Walter |
last post by:
Hello,
I have made an small AddIn with udf for excel 2003.
I use vs2003.
The point of view is the function __T()
I call it in excel sheet writing =__T()
I am not able to set a value to a given cell.
region.Value2="qwe"; //bumm!
A exception will be trown. On all PCs with excel.
HRESULT 0x800A03EC
| |
by: Tempo |
last post by:
Hello. I am getting the error that is displayed below, and I know
exactly why it occurs. I posted some of my program's code below, and if
you look at it you will see that the error terminates the program
pre-maturely. Becasue of this pre-mature termination, the program is
not able to execute it's final line of code, which is a very important
line. The last line saves the Excel spreadsheet. So is there a way to
make sure the last line...
|
by: deep022in |
last post by:
guys,
I have written a perl script using Win32::OLe module.
I was able to read it completly.
but I have to specify the number of rows in excel sheet as command line option.
I want to know how to retrieve number of rows of the excel sheet and number of columns also.
i tried to retrieve the properties using the each methode.
see below
|
by: Terry |
last post by:
Hi
Language: VBA (Excel)
I am wanting to execute different functions/subs dependent on a value picked up in a cell on Excel. For example if Cell A1 has the value "name" then I want to be able to run the NewName() sub and send to it the value of Cell B1 (which will contain a name). However, if Cell A1 contains the value "Age" then I want to run the NewAge() sub and send it the value of cell B1 (which will contain the age).
The reason...
|
by: sitko |
last post by:
Hi,
I have an Order tracking spreadsheet that I need help with.
I have a 2 worksheets "Open", and "Closed".
I have entries on the "Open" sheet which may or may not be grouped together. I've called the rows :Parents and Children. There are basically 3 types of rows. Parents with Children, Parents without Children, and Children. I have a reference cell for each row, where I identify what type of row it is, "-1" = Child, "0" = Parent with...
|
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 usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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 captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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: 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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |