Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game. |
| Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
02-12-2008, 12:50 PM
|
#1
|
|
Member
Registered: Dec 2005
Distribution: RHEL3, FC3
Posts: 383
Rep:
|
perl + excel + reading date values
Hi All,
I have a peculiar problem ( I think its a peculiar problem )
Am using parse, write, save parser perl modules
to read, write, update an excel file
Everything seems to work perfectly except for the following one.
I need to copy date values from sheet 1, doing some extraction and copy the values to sheet 2.
When I copy and display the date value which is of the form "12/1/2008"
I get a number instead of a date value.
Any idea what this number is and how to convert that back to a number so that I could copy it to another sheet ?
Thanks.
-kshkid
|
|
|
|
02-12-2008, 02:45 PM
|
#2
|
|
Moderator
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,903
|
Which CPAN module are you using for the Excel magic, what locale are you using, what
does that "number" look like?
Cheers,
Tink
|
|
|
|
02-12-2008, 09:35 PM
|
#3
|
|
Member
Registered: Dec 2005
Distribution: RHEL3, FC3
Posts: 383
Original Poster
Rep:
|
Following are the modules that am using
use Spreadsheet::ParseExcel;
use Spreadsheet::WriteExcel;
use Spreadsheet::ParseExcel::SaveParser;
locale is
LANG=en_US.UTF-8
numbers look something like 32416 (of that sort)
Thanks for the reply!
|
|
|
|
02-12-2008, 09:57 PM
|
#4
|
|
Guru
Registered: Mar 2006
Location: Sydney, Australia
Distribution: Fedora, CentOS, OpenSuse, Slack, Gentoo, Debian, Arch, PCBSD
Posts: 6,678
Rep: 
|
1 should be 1/1/1900, so 32416 is 30/9/1988
Is that what you mean?
Edit - I don't think you want to convert the number at all - it's simply a matter of formatting it in Excel (if it's formatted as a date, Excel will display 1 as 1/1/1900)
Last edited by billymayday; 02-12-2008 at 09:59 PM.
|
|
|
|
02-13-2008, 06:38 AM
|
#5
|
|
Member
Registered: Dec 2005
Distribution: RHEL3, FC3
Posts: 383
Original Poster
Rep:
|
Thank you very much for the reply
But that is not the case.
In sheet1 the data is available as "09/10/2001"
if this date value is copied from sheet1 ( through a perl code ) and written to sheet2 it writes that as a number something like 32416 and not as the date value "09/10/2001"
formatting are good and they are the same in both the sheets
This is really confusing !
|
|
|
|
02-13-2008, 05:35 PM
|
#6
|
|
Guru
Registered: Aug 2004
Location: Brisbane
Distribution: Centos 6.4, Centos 5.9
Posts: 15,021
|
Please show us a minimal version of the code that does this
|
|
|
|
02-14-2008, 01:13 PM
|
#7
|
|
Member
Registered: Dec 2005
Distribution: RHEL3, FC3
Posts: 383
Original Poster
Rep:
|
Sure.
Here is the snippet.
At first this seem to be quite straightforward like any other data but only for the date values I encounter these kind of problems
The code does very simple function of copying from 1 sheet to another sheet
Thanks for your time
Code:
my $oExcel = new Spreadsheet::ParseExcel::SaveParser;
die "Unable to open file " . $PROCESSED_FILE . " <$!>\n" unless defined $oExcel;
my $oBook = $oExcel->Parse($PROCESSED_FILE);
die "Unable to parse file " . $PROCESSED_FILE . " <$!>\n" unless defined $oBook;
$oBook->AddWorksheet(+OUTPUTSHEET_NAME);
my $obj = Spreadsheet::ParseExcel::Workbook->Parse($PROCESSED_FILE);
die "Unable to open file " . $PROCESSED_FILE . " <$!>\n" unless defined $obj;
my $row_num = 0;
foreach my $sheet (@{$obj->{Worksheet}}) {
next if( $sheet->{MaxRow} == -1 || $sheet->{MaxCol} == -1 );
$sheet->{MaxRow} ||= $sheet->{MinRow};
foreach my $row ($sheet->{MinRow} .. $sheet->{MaxRow}) {
$sheet->{MaxCol} ||= $sheet->{MinCol};
my $col_num = 0;
foreach my $col ($sheet->{MinCol} .. $sheet->{MaxCol}) {
my $data = $sheet->{Cells}[$row][$col]->{Val};
$oBook->AddCell(2, $row_num, $col_num++, $data);
}
$row_num++ if( $row != 0 );
}
}
$oExcel->SaveAs($oBook, $PROCESSED_FILE);
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 11:18 AM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|