473,396 Members | 2,081 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,396 software developers and data experts.

Spreadsheet::WriteExcel

Hello,

there's a module called Spreadsheet::WriteExcel. It allows me to create
a new worksheet and edit its cells:

my $workbook = Spreadsheet::WriteExcel->new('my.xls');
my $worksheet = $workbook->addworksheet();
$worksheet -> write('A2', 222);

But how can I put some values into the cells of an existing worksheet?
Thanks for any advice.

...:: fabio

Jul 19 '05 #1
2 7363
Fabio <fa***@anti-spam.inet.alpha.pl> wrote in message >
But how can I put some values into the cells of an existing worksheet?
Thanks for any advice.


Use either Spreadsheet::ParseExcel::SaveParser for rudimentary changes
to existing workbooks. If you need to do complex stuff, it may
(unfortunately) be easier to use OLE to do it.

w
Jul 19 '05 #2
Fabio <fa***@anti-spam.inet.alpha.pl> wrote in message news:<c2**********@nemesis.news.tpi.pl>...
Hello,

there's a module called Spreadsheet::WriteExcel. It allows me to create
a new worksheet and edit its cells:

my $workbook = Spreadsheet::WriteExcel->new('my.xls');
my $worksheet = $workbook->addworksheet();
$worksheet -> write('A2', 222);

But how can I put some values into the cells of an existing worksheet?
Thanks for any advice.

..:: fabio


Dunno Spreadsheet::WriteExcel.
Here is sth I wrote recently using Win32::OLE
-------------
#for OLE automation
use Win32::OLE;
use Win32::OLE::Const "Microsoft Excel";
use Win32::OLE 'in';
use Win32::OLE::Variant;
#get current directory
use Cwd;

#writes array of changes to existing excel spreadsheet as new excel spreadsheet
#arguments:
# input_file - name of existing Excel spreadsheet
# output_file - name under which changed file is to be save under (SaveAs option)
# change_array_ref - reference to array of changes - (row \t column \t new value)

sub write_changes_into_excel_file
{
#name of existing Excel spreadsheet
my $input_file = shift;
#name under which changed file is to be save under (SaveAs option)
my $output_file = shift;

#reference to array of changes - (row, column, new value)
my $change_array_ref = shift;

my $dir = cwd();
my $fullname_input_file = $dir.'/'.$input_file;
my $fullname_output_file = $dir.'/'.$output_file;

#check if input file exists in first place
unless(-f $fullname_input_file)
{
print STDERR "Input file: $fullname_input_file does not exists.\n";
exit;
}

# use existing instance if Excel is already running
eval
{
$excel = Win32::OLE->GetActiveObject('Excel.Application')
};
die "Excel not installed" if $@;

unless (defined $excel)
{
$excel = Win32::OLE->new('Excel.Application', 'Quit')
or die "Oops, cannot start Excel";
}
#to avoid excessive dialogs when saving in non-Excel format
$excel->{DisplayAlerts} = 0;

my $wbook;
if($wbook = Win32::OLE->GetObject($fullname_input_file)){;}
else
{
#the failure og GetObject is potentially due to the fact
#that file $fullname_input_file is already opened.
#In such case we need to find workbook that corresponds
#to already opened file and if we cannot we print error
#message and exit.
my $wbooks = $excel->Workbooks();
my $name = Variant($fullname_input_file);
if($wbooks->{"$name"}->Activate())
{
$wbook = $wbooks->{"$name"};
}
else
{
print STDERR "Could not open the file $fullname_input_file: $!\n";
exit;
}
}

# write to a particular cell
my $wsheet = $wbook->Worksheets(1);

my $line;
my $cell_value;
my $row_num;
my $col_num;
my $do_next;
foreach $line (@{$change_array_ref})
{
(
$row_num,
$col_num,
$cell_value
)
= split("\t",$line);

$row_num =~ s/\s//g;
$col_num =~ s/\s//g;

$wsheet->Cells($row_num,$col_num)->{Value} = "$cell_value";
$wsheet->Cells($row_num,$col_num)->Select();
}

$wbook->SaveAs($fullname_output_file);
undef $wbook;
}
Jul 19 '05 #3

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

Similar topics

0
by: Dorthe Luebbert | last post by:
Hi, there is a new(er) version of John McNammara's Excel package for Perl: http://homepage.eircom.net/~jmcnamara/perl/prerel/Spreadsheet-WriteExcel-0.49.7.tar.gz The package writes Excel97...
0
by: FSD | last post by:
I am using the Spreadsheet-WriteExcel-211 module to write values into a spreadsheet. The module is very powerful and robust, but there is one thing that I cannot seem to do. I need to open a...
4
by: tito | last post by:
I am using Active Perl for running perl programs.I am finding difficulty in installing Spreadsheet::WriteExcel,Spreadsheet:ParseExcel to the machine for writing a program which will retrieve data...
1
by: tito | last post by:
I would like to write a program which will retrieve the data from the EXCEL file and write into an SQL Server using Perl script.Spreadsheet::WriteExcel programs are working fine.But while executing...
5
by: rasmitasah25 | last post by:
hi, I am very new to perl.I have written a perl script which is writing data into an excel file.The problem is that it is creating one new excel file while executing but my need id to write into...
5
by: bvithya | last post by:
Hi Gurus, I am in need of your guidance. I have installed Perl5.8.8 on my server running with SunOS 5.8 and then I installed Spreadsheet::WriteExcel perl module. It has been installed...
8
by: Perl Beginner | last post by:
I am using Win32. I have created an excel spreadsheet, formatted the columns and rows, and would like to write to the cells…all of this using Spreadsheet::WriteExcel. My issue is, my script is very...
2
by: lavsaxena | last post by:
Can we edit a worksheet of excel through spreadsheet::writeExcel. Because when I am using my $workbook = Spreadsheet::WriteExcel->new('D:\test_result.xls'); this statement is creating the...
7
by: somsub | last post by:
Hi, When I tried to open excel sheet created by below code with MSexcel it showing "Unable to read file " error . use Spreadsheet::WriteExcel; $workbook =...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...
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...

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.