Sponsored Content
Top Forums Shell Programming and Scripting Adding columns to excel files using Perl Post 302169070 by sad_angle on Wednesday 20th of February 2008 06:13:58 AM
Old 02-20-2008
Give a man a fish, you fed him once. Tech him how to fish, you fed him for life.

Spreadsheet::WriteExcel - Write to a cross-platform Excel binary file. - search.cpan.org

Good luck
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Perl: adding columns in CSV file with information in each

Hi Wise UNIX Crew, I want to add 3 different columns to the file in which: 1. The first new column pulls in today's date and time 2. Second column one has a '0' 3. Third column has the word 'ANY' going down the column If my file content is as follows: "7","a","abc",123"... (1 Reply)
Discussion started by: dolo21taf
1 Replies

2. Shell Programming and Scripting

awk adding columns from different files

Hi, I have two files and I need to add column 3 of file1 to column 3 of file 2 > file3 I also need to repeat for column 4. Thanks (1 Reply)
Discussion started by: dsstamps
1 Replies

3. Shell Programming and Scripting

PERL: Split Excel Workbook to Indiv Excel files

Hi, I am trying to find a way to read an excel work book with multiple worksheets. And write each worksheet into a new excel file using perl. My environment is Unix. For example: I have an excel workbook TEST.xls and it has Sheet1, Sheet2, Sheet3 worksheets. I would like to create... (2 Replies)
Discussion started by: sandeep78
2 Replies

4. Shell Programming and Scripting

Adding columns of two files

Hello everyone, I have two files containing 6 columns and thousands of rows. I want to add them (i.e. first column of first file + first column of second file and so on) and print the output in a third file. Can you please help me. Thanks a lot (7 Replies)
Discussion started by: chandra321
7 Replies

5. UNIX for Dummies Questions & Answers

Adding new columns to txt files

Dear all, I have a question. I have a txt.file as below. i want to add 3 more columns: column3=conlum 2*column2; column4=(1-column2)*(1-column2); column5=1-column3-column4. Do you know how to do it? Thanks a lot! file: column1 column2 a 1 b 20 c 30 d 3 ... (2 Replies)
Discussion started by: forevertl
2 Replies

6. Shell Programming and Scripting

Adding Multiple Files via Columns

I have a number of files with multiple rows that I need to add together. Let say I have 10 files: Each file has a great number of rows and columns. I need to add these files together the following way. In other words, If, for example, file A occupies Columns 1 to 19, I want to add file B... (7 Replies)
Discussion started by: Ernst
7 Replies

7. UNIX for Dummies Questions & Answers

Perl - adding columns to file

I have a file in which I need to add more columns to based on a key in the first file: File1 key1,abc,123, key2,def,456, key3,ghi,789, File2 key2,zyx,111,qqq, key3,yuu,222,www, key1,pui,333,eee, key4,xxx,999,rrr, I would like to create the following output: Output (1 Reply)
Discussion started by: WongSifu
1 Replies

8. Shell Programming and Scripting

Perl script to Merge contents of 2 different excel files in a single excel file

All, I have an excel sheet Excel1.xls that has some entries. I have one more excel sheet Excel2.xls that has entries only in those cells which are blank in Excel1.xls These may be in different workbooks. They are totally independent made by 2 different users. I have placed them in a... (1 Reply)
Discussion started by: Anamika08
1 Replies

9. Shell Programming and Scripting

Perl script to accept specific columns from excel

Hi All, I have below perl script which writes xml from .xls file. Now i want to add below two conditions in this script : 1. to check if the the input .xls file has ony two columns , if more tahn two columns then script should pop up an error. 2. If there are two columns , then first column... (4 Replies)
Discussion started by: omkar.jadhav
4 Replies

10. Shell Programming and Scripting

Adding columns from 2 files with variable number of columns

I have two files, file1 and file2 who have identical number of rows and columns. However, the script is supposed to be used for for different files and I cannot know the format in advance. Also, the number of columns changes within the file, some rows have more and some less columns (they are... (13 Replies)
Discussion started by: maya3
13 Replies
Spreadsheet::ParseExcel::SaveParser(3pm)		User Contributed Perl Documentation		  Spreadsheet::ParseExcel::SaveParser(3pm)

NAME
Spreadsheet::ParseExcel::SaveParser - Rewrite an existing Excel file. SYNOPSIS
Say we start with an Excel file that looks like this: ----------------------------------------------------- | | A | B | C | ----------------------------------------------------- | 1 | Hello | ... | ... | ... | 2 | World | ... | ... | ... | 3 | *Bold text* | ... | ... | ... | 4 | ... | ... | ... | ... | 5 | ... | ... | ... | ... Then we process it with the following program: #!/usr/bin/perl use strict; use warnings; use Spreadsheet::ParseExcel; use Spreadsheet::ParseExcel::SaveParser; # Open an existing file with SaveParser my $parser = Spreadsheet::ParseExcel::SaveParser->new(); my $template = $parser->Parse('template.xls'); # Get the first worksheet. my $worksheet = $template->worksheet(0); my $row = 0; my $col = 0; # Overwrite the string in cell A1 $worksheet->AddCell( $row, $col, 'New string' ); # Add a new string in cell B1 $worksheet->AddCell( $row, $col + 1, 'Newer' ); # Add a new string in cell C1 with the format from cell A3. my $cell = $worksheet->get_cell( $row + 2, $col ); my $format_number = $cell->{FormatNo}; $worksheet->AddCell( $row, $col + 2, 'Newest', $format_number ); # Write over the existing file or write a new file. $template->SaveAs('newfile.xls'); We should now have an Excel file that looks like this: ----------------------------------------------------- | | A | B | C | ----------------------------------------------------- | 1 | New string | Newer | *Newest* | ... | 2 | World | ... | ... | ... | 3 | *Bold text* | ... | ... | ... | 4 | ... | ... | ... | ... | 5 | ... | ... | ... | ... DESCRIPTION
The "Spreadsheet::ParseExcel::SaveParser" module rewrite an existing Excel file by reading it with "Spreadsheet::ParseExcel" and rewriting it with "Spreadsheet::WriteExcel". METHODS
Parser new() $parse = new Spreadsheet::ParseExcel::SaveParser(); Constructor. Parse() $workbook = $parse->Parse($sFileName); $workbook = $parse->Parse($sFileName , $formatter); Returns a "Workbook" object. If an error occurs, returns undef. The optional $formatter is a Formatter Class to format the value of cells. Workbook The "Parse()" method returns a "Spreadsheet::ParseExcel::SaveParser::Workbook" object. This is a subclass of the Spreadsheet::ParseExcel::Workbook and has the following methods: worksheets() Returns an array of "Worksheet" objects. This was most commonly used to iterate over the worksheets in a workbook: for my $worksheet ( $workbook->worksheets() ) { ... } worksheet() The "worksheet()" method returns a single "Worksheet" object using either its name or index: $worksheet = $workbook->worksheet('Sheet1'); $worksheet = $workbook->worksheet(0); Returns "undef" if the sheet name or index doesn't exist. AddWorksheet() $workbook = $workbook->AddWorksheet($name, %properties); Create a new Worksheet object of type "Spreadsheet::ParseExcel::Worksheet". The %properties hash contains the properties of new Worksheet. AddFont $workbook = $workbook->AddFont(%properties); Create new Font object of type "Spreadsheet::ParseExcel::Font". The %properties hash contains the properties of new Font. AddFormat $workbook = $workbook->AddFormat(%properties); The %properties hash contains the properties of new Font. Worksheet Spreadsheet::ParseExcel::SaveParser::Worksheet Worksheet is a subclass of Spreadsheet::ParseExcel::Worksheet. And has these methods : The "Worksbook::worksheet()" method returns a "Spreadsheet::ParseExcel::SaveParser::Worksheet" object. This is a subclass of the Spreadsheet::ParseExcel::Worksheet and has the following methods: AddCell $workbook = $worksheet->AddCell($row, $col, $value, $format [$encoding]); Create new Cell object of type "Spreadsheet::ParseExcel::Cell". The $format parameter is the format number rather than a full format object. To specify just same as another cell, you can set it like below: $row = 0; $col = 0; $worksheet = $template->worksheet(0); $cell = $worksheet->get_cell( $row, $col ); $format_number = $cell->{FormatNo}; $worksheet->AddCell($row +1, $coll, 'New data', $format_number); TODO
Please note that this module is currently (versions 0.50-0.60) undergoing a major restructuring and rewriting. Known Problems You can only rewrite the features that Spreadsheet::WriteExcel supports so macros, graphs and some other features in the original Excel file will be lost. Also, formulas aren't rewritten, only the result of a formula is written. Only last print area will remain. (Others will be removed) AUTHOR
Maintainer 0.40+: John McNamara jmcnamara@cpan.org Maintainer 0.27-0.33: Gabor Szabo szabgab@cpan.org Original author: Kawai Takanori kwitknr@cpan.org COPYRIGHT
Copyright (c) 2009-2010 John McNamara Copyright (c) 2006-2008 Gabor Szabo Copyright (c) 2000-2002 Kawai Takanori and Nippon-RAD Co. OP Division All rights reserved. You may distribute under the terms of either the GNU General Public License or the Artistic License, as specified in the Perl README file. perl v5.10.1 2010-09-17 Spreadsheet::ParseExcel::SaveParser(3pm)
All times are GMT -4. The time now is 08:53 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy