473,404 Members | 2,187 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

How to append an excel sheet using perl

Hi,

I am writing a script which should update an excel sheet daily. So how do I determine which is the last row which contains data and then write the latest data into the sheet.


Expand|Select|Wrap|Line Numbers
  1. use Spreadsheet::WriteExcel;
  2. use Spreadsheet::ParseExcel;
  3.  
  4.    $datetime=localtime();
  5.  
  6.  # $count variable is used to track the no of in the excel
  7.     $count=0;
  8. #    $loc=$ENV{"TEMP"};
  9.     $loc="D:\\SpaceUsage";
  10.     $vob="";
  11.     $vobsize=0;
  12.     $totalvobsize+=0;
  13.     $vd="";
  14.     $sum=0;
  15.  
  16. #    print " $loc -- ";    
  17.  # Create a new Excel workbook
  18.     my $workbook = Spreadsheet::WriteExcel->new("$loc\\spacesize.xls");
  19.  
  20.     # Add a worksheet
  21.     $worksheet = $workbook->add_worksheet();
  22.  
  23.     #  Add and define a format
  24.     $format = $workbook->add_format(); # Add a format
  25.     $format->set_bold();
  26.     $format->set_color('blue');
  27.     $format->set_align('center');
  28.  
  29. #    $worksheet->write($count,-2, "VOB Space Usage on BLRKCF9A",$format);
  30.     $worksheet->write($count,0,"Updated on $datetime",$format);
  31.     $worksheet->write($count,1,"VOB Name",$format);
  32.     $worksheet->write($count,2,"db",$format);
  33.     $worksheet->write($count,3,"cdft",$format);
  34.     $worksheet->write($count,4,"ddft",$format);
  35.     $worksheet->write($count,5,"sdft",$format);
  36.     $worksheet->write($count,6,"Total Size in (MB)",$format);
  37.     $worksheet->write($count,7,"Total VOB Size in (GB)",$format);
  38.  
  39.  
  40.  
  41.     @vobs =("\\AXIS");
  42.  
  43.     foreach $vob (@vobs)
  44.     {
  45.  
  46.             $vobname=$vob;
  47.             chomp($vobname);
  48. #            chop($vobname);
  49.             print "\n VOB Name :: $vobname \n";
  50.             @vobdiskuse = `cleartool space -vob -update $vob`;
  51.             foreach $vd (@vobdiskuse)
  52.             {
  53.  
  54.                 if ($vd =~ /VOB database/)
  55.                 {
  56.                     if ($vd =~ /(\d+\.\d+)\s+/)
  57.                     {
  58.                         $dbsize = $1;
  59.                         print "\n DB Pool:$dbsize Mb\n";
  60.                     }
  61.                 }
  62.                 if ($vd =~ /cleartext/)    
  63.                 {
  64.                     if ($vd =~ /(\d+\.\d+)\s+/)
  65.                     {
  66.                         $csize = $1;
  67.                         print "\n C Pool:$csize Mb\n";
  68.                     }
  69.  
  70.                 }
  71.                 if ($vd =~ /derived object/)    
  72.                 {
  73.                     if ($vd =~ /(\d+\.\d+)\s+/)
  74.                     {
  75.                         $dosize = $1;
  76.                         print "\n DO Pool:$dosize Mb\n";
  77.                     }
  78.                 }
  79.                 if ($vd =~ /source pool/)    
  80.                 {
  81.                     if ($vd =~ /(\d+\.\d+)\s+/)
  82.                     {
  83.                         $srcsize = $1;
  84.                         print "\n SOURCE Pool:$srcsize Mb\n";
  85.                     }
  86.  
  87.                 }
  88.  
  89.  
  90.                       if ($vd=~ /^Total*/)
  91.                       {
  92.                     chomp($vd);
  93.  
  94.  
  95.                     if ($vd=~ /\s(\d+\.\d+)\s/)
  96.                     {
  97.                         $vobsize=$1;
  98.                         chomp($vobsize);
  99.                         print "VOB Size :: $vobsize \n";
  100.  
  101.                             $count++;
  102.                             $worksheet->write($count,1,$vobname);
  103.                             $worksheet->write($count,2,$dbsize);
  104.                         $worksheet->write($count,3,$csize);
  105.                         $worksheet->write($count,4,$dosize);
  106.                         $worksheet->write($count,5,$srcsize);
  107.                         $worksheet->write($count,6,$vobsize);    
  108.  
  109.  
  110.                     }
  111.                     $totalvobsize+=$vobsize;
  112.                     $totalvobsize = ($totalvobsize / 1024);
  113.                     $sum+=$totalvobsize;
  114.                     print "\nTotal Vobsize: $totalvobsize GB \n";
  115.                     $worksheet->write($count,7,$totalvobsize);    
  116.  
  117.                        }
  118.               }
  119.  
  120.     }
  121.                     $worksheet->write($count,7,$sum);
  122.  
Kindly suggest me.

THT,
Raghavendra
Dec 20 '07 #1
2 5377
gpraghuram
1,275 Expert 1GB
I havent used this utility.
But my idea is if you want to write to the previously written excel file then you have to open the file in append mode.
Check whether this utility provides you that option.

Raghuram
Dec 21 '07 #2
Hi,
You can use Spreadsheet::ParseExcel::SaveParser module to change the existing excel sheet.

max rows and columns should be checked using
Expand|Select|Wrap|Line Numbers
  1. $worksheet->{MaxRow}
  2. $worksheet->{MaxCol}
  3.  
Regards,
Manimaran.K
Dec 21 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: rahatekarabhijeet | last post by:
I want to create excel sheet using perl, i had installed all the necessary modules from CPAN. The perl program i taken from CPAN itself it is given below, #!/usr/bin/perl -w use warnings; use...
0
by: rajeshkothuru | last post by:
Hi I am new to perl programming, i stcked at one line. I have written code such that new excel sheet will save accordingly even though if already existed Excel sheet persists. The problem is if...
8
by: rssd | last post by:
can somebody help me. I'm trying to read some excel files but i'm always getting this error No type library matching "Microsoft Excel" found at D:\Genes_datasets\exp.pl line 4 Win32::OLE(0.16):...
5
by: Sport Girl | last post by:
Hi everybody. I am new in PERL language and working in it since little hours, actually i am still a trainee and i need help please. In fact, i need a script in PERL that enables me to retrieve...
1
by: Sport Girl | last post by:
Hi everybody , i have the task of developing in Perl a script that retrieves data from 3 tables ( bugs, profiles, products) from a MySQL database called bugs and display them in an excel sheet...
0
by: shintu | last post by:
Hallo, I am trying to write french accented characters é è ê in Excel worksheet using my perl script , But I am stuck here as I couldnt find a way of writing it !: My code: use strict;...
1
by: pvenu | last post by:
Hi, I know basic perl (regular expressions, pattern matching, string manipulation, reading writing into text files). Yet, my requirement is to read an input text file -> process this input file...
6
by: poolboi | last post by:
hi all, i've got the following program that needs yr help: use Win32::OLE; # use existing instance if Excel is already running eval {$ex =...
2
by: ravir81 | last post by:
Hi, I am working on excel reporting using Perl. I am facing problem with writing the header part only once for all the excels created using Perl. Here is the code : ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
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,...
0
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...
0
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...

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.