CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
Export Data to MS Excel Sheet

 



C_PRASANNA
Novice

Apr 11, 2014, 12:15 AM

Post #1 of 4 (9105 views)
Export Data to MS Excel Sheet Can't Post

Hi Guys,

Please advise the best module and code snippet for me, as i need to give the data in Ms Excel which i taken from database.

i.e, Need to run a query and give the output in Excel via Email.

Thanks - Prasanna.


BillKSmith
Veteran

Apr 11, 2014, 5:51 AM

Post #2 of 4 (8991 views)
Re: [C_PRASANNA] Export Data to MS Excel Sheet [In reply to] Can't Post

If your data is a single matrix, you can print it as a "CSV" file. Email will treat this as a text file. Excel is able to load this format.

Otherwise, you will need a module to create an Excel spreadsheet with perl. Email should not be a problem.
Good Luck,
Bill


FishMonger
Veteran / Moderator

Apr 11, 2014, 6:25 AM

Post #3 of 4 (8976 views)
Re: [C_PRASANNA] Export Data to MS Excel Sheet [In reply to] Can't Post

If you want to create an excel file instead of a csv file, then you can use the Spreadsheet::WriteExcel module.
http://search.cpan.org/~jmcnamara/Spreadsheet-WriteExcel-2.40/lib/Spreadsheet/WriteExcel.pm


Tejas
User

Apr 24, 2014, 5:04 AM

Post #4 of 4 (8764 views)
Re: [C_PRASANNA] Export Data to MS Excel Sheet [In reply to] Can't Post


In Reply To
Hi Guys,

Please advise the best module and code snippet for me, as i need to give the data in Ms Excel which i taken from database.

i.e, Need to run a query and give the output in Excel via Email.

Thanks - Prasanna.

Thts a pretty Vague question , As, I just do not know what exactly are you getting from DB.
And whether some/all columns are considered to excel sheet .
Anyways, below code might help u out

Code
my  $Input = "Your Spooled DB File"; 
my $full_path = "Path You Intend to Store Your Excel"
my $workbook = Spreadsheet::WriteExcel->new($full_path);
my $frmt = $workbook->add_format();
$frmt->set_bold();
$frmt->set_color('blue');
my $Test_WorkSheet = $workbook->add_worksheet("Test");
our $row=1;

foreach my $worksheet ($workbook->sheets()) #Just not needed , if u have a single worksheet.
{
$worksheet->write_string (0, 0, "Heading1",$frmt);
$worksheet->write_string (0, 1, "Heading2",$frmt);
.
.
.
$worksheet->write_string (0, 19, "HeadingN",$frmt);
}

while ($line = <Input>)
{
my @data = split ("\t", $line); #This takes tab seperted values,You can change it according to the delimiter you are using.
# print "@data \n";
Write_Data_To_excel(@data)

}

sub Write_Data_To_excel
{
for (my $col = 0; $col < n ; $col++)
{
$Test_WorkSheet->write ($row, $col, @_[$col]);
}
$row=$row+1
}



(This post was edited by Tejas on Apr 24, 2014, 5:06 AM)

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives