Sponsored Content
Top Forums Shell Programming and Scripting Adding columns to excel files using Perl Post 302169031 by dolo21taf on Wednesday 20th of February 2008 04:09:12 AM
Old 02-20-2008
Adding columns to excel files using Perl

How do I add 4 columns to an excel file using Perl? The 4 headers for those columns will all have different names? Please help and I greatly appreciate...
 

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
TabularDisplay(3pm)					User Contributed Perl Documentation				       TabularDisplay(3pm)

NAME
Text::TabularDisplay - Display text in formatted table output SYNOPSIS
use Text::TabularDisplay; my $table = Text::TabularDisplay->new(@columns); $table->add(@row) while (@row = $sth->fetchrow); print $table->render; +----+--------------+ | id | name | +----+--------------+ | 1 | Tom | | 2 | Dick | | 3 | Barry | | | (aka Bazza) | | 4 | Harry | +----+--------------+ DESCRIPTION
Text::TabularDisplay simplifies displaying textual data in a table. The output is identical to the columnar display of query results in the mysql text monitor. For example, this data: 1, "Tom Jones", "(666) 555-1212" 2, "Barnaby Jones", "(666) 555-1213" 3, "Bridget Jones", "(666) 555-1214" Used like so: my $t = Text::TabularDisplay->new(qw(id name phone)); $t->add(1, "Tom Jones", "(666) 555-1212"); $t->add(2, "Barnaby Jones", "(666) 555-1213"); $t->add(3, "Bridget Jones", "(666) 555-1214"); print $t->render; Produces: +----+---------------+----------------+ | id | name | phone | +----+---------------+----------------+ | 1 | Tom Jones | (666) 555-1212 | | 2 | Barnaby Jones | (666) 555-1213 | | 3 | Bridget Jones | (666) 555-1214 | +----+---------------+----------------+ METHODS
Text::TabularDisplay has four primary methods: new(), columns(), add(), and render(). new() creates a new Text::TabularDisplay instance; columns() sets the column headers in the output table; add() adds data to the instance; and render() returns a formatted string representation of the instance. There are also a few auxiliary convenience methods: clone(), items(), reset(), populate(), and paginate(). new A Text::TabularDisplay instance can be created with column names passed as constructor args, so these two calls produce similar objects: my $t1 = Text::TabularDisplay->new; $t1->columns(qw< one two >); my $t2 = Text::TabularDisplay->new(qw< one two >); Calling new() on a Text::TabularDisplay instance returns a clone of the object. See "clone" in Text::TabularDisplay. columns Gets or sets the column names for an instance. This method is called automatically by the constructor with any parameters that are passed to the constructor (if any are passed). When called in scalar context, columns() returns the number of columns in the instance, rather than the columns themselves. In list context, copies of the columns names are returned; the names of the columns cannot be modified this way. add Takes a list of items and appends it to the list of items to be displayed. add() can also take a reference to an array, so that large arrays don't need to be copied. As elements are processed, add() maintains the width of each column so that the resulting table has the correct dimensions. add() returns $self, so that calls to add() can be chained: $t->add(@one)->add(@two)->add(@three); render render() does most of the actual work. It returns a string containing the data added via add(), formatted as a table, with a header containing the column names. render() does not change the state of the object; it can be called multiple times, with identical output (including identical running time: the output of render is not cached). If there are no columns defined, then the output table does not contains a row of column names. Compare these two sequences: my $t = Text::TabularDisplay->new; $t->add(qw< 1 2 3 4 >); $t->add(qw< 5 6 7 8 >); print $t->render; $t->columns(qw< one two three four >); print $t->render; # Example 1 output +---+---+---+---+ | 1 | 2 | 3 | 4 | | 5 | 6 | 7 | 8 | +---+---+---+---+ # Example 2 output +-----+-----+-------+------+ | one | two | three | four | +-----+-----+-------+------+ | 1 | 2 | 3 | 4 | | 5 | 6 | 7 | 8 | +-----+-----+-------+------+ render() takes optional $start and $end arguments; these indicate the start and end indexes for the data to be rendered. This can be used for paging and the like: $t->add(1, 2, 3)->add(4, 5, 6)->add(7, 8, 9)->add(10, 11, 12); print $t->render(0, 1), " "; print $t->render(2, 3), " "; Produces: +-------+--------+-------+ | First | Second | Third | +-------+--------+-------+ | 1 | 2 | 3 | | 4 | 5 | 6 | +-------+--------+-------+ +-------+--------+-------+ | First | Second | Third | +-------+--------+-------+ | 7 | 8 | 9 | | 10 | 11 | 12 | +-------+--------+-------+ As an aside, note the chaining of calls to add(). The elements in the table are padded such that there is the same number of items in each row, including the header. Thus: $t->columns(qw< One Two >); print $t->render; +-----+-----+----+ | One | Two | | +-----+-----+----+ | 1 | 2 | 3 | | 4 | 5 | 6 | | 7 | 8 | 9 | | 10 | 11 | 12 | +-----+-----+----+ And: $t->columns(qw< One Two Three Four>); print $t->render; +-----+-----+-------+------+ | One | Two | Three | Four | +-----+-----+-------+------+ | 1 | 2 | 3 | | | 4 | 5 | 6 | | | 7 | 8 | 9 | | | 10 | 11 | 12 | | +-----+-----+-------+------+ OTHER METHODS
clone() The clone() method returns an identical copy of a Text::TabularDisplay instance, completely separate from the cloned instance. items() The items() method returns the number of elements currently stored in the data structure: printf "There are %d elements in $t. ", $t->items; reset() Reset deletes the data from the instance, including columns. If passed arguments, it passes them to columns(), just like new(). populate() populate() as a special case of add(); populate() expects a reference to an array of references to arrays, such as returned by DBI's selectall_arrayref method: $sql = "SELECT " . join(", ", @c) . " FROM mytable"; $t->columns(@c); $t->populate($dbh->selectall_arrayref($sql)); This is for convenience only; the implementation maps this to multiple calls to add(). NOTES
/ ISSUES Text::TabularDisplay assumes it is handling strings, and does stringy things with the data, like length() and sprintf(). Non-character data can be passed in, of course, but will be treated as strings; this may have ramifications for objects that implement overloading. The biggest issue, though, is that this module duplicates a some of the functionality of Data::ShowTable. Of course, Data::ShowTable is a large, complex monolithic tool that does a lot of things, while Text::TabularDisplay is small and fast. AUTHOR
darren chamberlain <darren@cpan.org> CREDITS
The following people have contributed patches, suggestions, tests, feedback, or good karma: David N. Blank-Edelman Eric Cholet Ken Youens-Clark Michael Fowler Paul Cameron Prakash Kailasa Slaven Rezic Harlan Lieberman-Berg Patrick Kuijvenhoven VERSION
This documentation describes "Text::TabularDisplay" version 1.33. perl v5.14.2 2012-07-05 TabularDisplay(3pm)
All times are GMT -4. The time now is 08:18 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy