473,382 Members | 1,332 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,382 software developers and data experts.

Unable to put array as a comment on excel sheet cell .

16
Hi,

I m facing a problem to add an array as a comment to a MS excel cell using Spreadsheet :: WriteExcel .

I m using the below code

Expand|Select|Wrap|Line Numbers
  1. use Spreadsheet::WriteExcel;
  2. $workbook = Spreadsheet::WriteExcel->new('perl.xls');
  3. $worksheet = $workbook->add_worksheet();
  4. print "\n \n Enter a path value to take its contns \n";
  5.     $pth=<STDIN>;
  6.     chomp $pth;
  7.     $pth =~ tr#\\#/#;
  8.     open(MF, "$pth" ) || die "$!";
  9.     @contents = <MF>;
  10.     close(MF);
  11.         $worksheet->write_comment(10, 2, @contents);
  12.     $workbook->close();
  13.  

above script reads the contents of the specified text file and takes it in to an array @contents and writes it to the secified cell (ie is 10 th row 2nd column ) using write_comment method .

But executing this i got the following output .

Uneven number of additional arguments at s4.pl line 11.

also the last line $workbook->close(); is not executed after that .


Could anyone help me how to add an array or a filehandle in a MS excel cell comment .
Oct 20 '09 #1
3 3186
nithinpes
410 Expert 256MB
The write_comment method accepts the comment string as a single argument. When you pass an array, each element of the array will be considered as an argument and this violates syntax of the method.
You can read entire chunk of the file as a single string and pass it as comment.
Expand|Select|Wrap|Line Numbers
  1. use Spreadsheet::WriteExcel; 
  2. $workbook = Spreadsheet::WriteExcel->new('perl.xls'); 
  3. $worksheet = $workbook->add_worksheet(); 
  4. print "\n \n Enter a path value to take its contns \n"; 
  5.     $pth=<STDIN>; 
  6.     chomp $pth; 
  7.     $pth =~ tr#\\#/#; 
  8.     $/= "" ;   # undefine input record separator to read entire file
  9.     open(MF, "$pth" ) || die "$!"; 
  10.     $contents = <MF>; # entire file is read into variable
  11.     close(MF); 
  12.         $worksheet->write_comment(10, 2, $contents); 
  13.     $workbook->close(); 
  14.  
Oct 21 '09 #2
somsub
16
Yaa it worked peoperly ....!! thnx a lot.. for ur help
Oct 21 '09 #3
lanurk
1
My Perl Script is generating excel and updating it daily by extracting contents from server logs, which are writtent o various sheets and colums,
I have used Spreadsheet::WriteExcel and Spreadsheet::ParseExcel . I am able to comment also, But when the file is saved again with older data,
simply by
Expand|Select|Wrap|Line Numbers
  1. my $workbook;
  2.     {
  3.         local $^W = 0;
  4.         # Rewrite the file or save as a new file
  5.         $workbook = $existingReport->SaveAs($FILE);
  6.     }
  7.  
The older comments on other cells are removed.
In short, The new comments are still written along with all data except the comments from cells which were written in last run. thank you in advance. Please let me know if detail are needed. Thanks again :)
Oct 21 '11 #4

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

Similar topics

3
by: Otie | last post by:
I am trying to copy the cell contents in an MSFLXGRD control (using VB5) into Excel, retaining the foreground colors of the text and numbers. I have tried using the Clipboard.SetText...
18
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...
12
by: kath | last post by:
How do I read an Excel file in Python? I have found a package to read excel file, which can be used on any platform. http://www.lexicon.net/sjmachin/xlrd.htm I installed and working on the...
2
by: Ch Pravin | last post by:
Hi All: I am having the following xml which i need to convert to excel using xslt. Please help me out. Afghanistan.xml <?xml version="1.0" encoding="utf-16"?> <Languages...
0
by: nphankey | last post by:
I'm struggling to tame Excel using Python and COM. Most of the following code is working except for the setting of the activesheet. Also, I would like to know how to release a COM object...
1
mehj123
by: mehj123 | last post by:
HI, I am writing a code in jsp to retrieve the details from a database and saving it as excel sheet. I am first retrieving the company name and then according to the company, I am grouping the...
7
by: TG | last post by:
hi! I am trying to create a sql server table from an excel sheet. Here is the code I have: 'This procedure the xlsx file and dumps it to a table in SQL Server
2
hemantbasva
by: hemantbasva | last post by:
Note We need to have a template on server for generating report in multiple sheet as we do not had msoffice on server moreover this require a batch job to delete excel file created by the...
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: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...

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.