Apr 24, 2014, 5:04 AM
Post #4 of 4
Re: [C_PRASANNA] Export Data to MS Excel Sheet
[In reply to]
Hi Guys, Thts a pretty Vague question , As, I just do not know what exactly are you getting from DB.
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.
And whether some/all columns are considered to excel sheet .
Anyways, below code might help u out
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();
my $Test_WorkSheet = $workbook->add_worksheet("Test");
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";
for (my $col = 0; $col < n ; $col++)
$Test_WorkSheet->write ($row, $col, @_[$col]);
(This post was edited by Tejas on Apr 24, 2014, 5:06 AM)