Sponsored Content
Top Forums Shell Programming and Scripting Sending SQL Queries output to different Excel sheets Post 302320431 by dinjo_jo on Thursday 28th of May 2009 03:44:07 AM
Old 05-28-2009
I have being doing it in sybase using perl.

use Spreadsheet::WriteExcel;
use Spreadsheet::WriteExcel::Worksheet;
use Sybase:SmilieBlib;

my @results;


my $sql = "select *"
my $dbh = Sybase:SmilieBlib->new($user , $passwd , $server);
if (defined $dbh)
{
@results = $dbh->nsql($sql , "HASH");
}
else
{
print "No DB Connection found for $server";
}

my $ebook = Spreadsheet::WriteExcel->new(file);
my $esheet = $ebook->addworksheet($title);
my $format = $ebook->addformat();
my $formatheader = $ebook->addformat();
my $formatcolumn = $ebook->addformat();

$formatheader->set_size(20);
$formatheader->set_font('Verdana');
$formatheader->set_color('brown');
$formatheader->set_align('center');
$formatheader->set_bold();
$formatheader->set_merge();


$formatcolumn->set_size(10);
$formatcolumn->set_font('Verdana');
$formatcolumn->set_color('navy');
$formatcolumn->set_align('center');
$formatcolumn->set_bold();
$formatcolumn->set_italic();

$format->set_color('black');
$format->set_font('Verdana');
$format->set_align('center');

$esheet->write_blank(0,0,$formatheader);
$esheet->write_blank(0,1,$formatheader);
$esheet->write_blank(0,2,$formatheader);
$esheet->write_blank(0,3,$formatheader);
$esheet->set_column(0, 2, 25,$formatheader);


$esheet->set_column(2, 0, 25,$formatcolumn);
$esheet->set_column(2, 1, 25,$formatcolumn);
$esheet->set_column(2, 2, 25,$formatcolumn);
$esheet->set_column(2, 3, 25,$formatcolumn);
$esheet->set_column(2, 4, 25,$formatcolumn);


my $o = 0;
foreach my $values (@results)
{
$esheet->set_column(3,$o, 25,$format);
$esheet->write($i,0,"$values->{'Branches_ShortName'}",$format);
$esheet->write($i,1,"$values->{'Portfolios_ShortName'}",$format);
$esheet->write($i,2,"$values->{'Portfolios_Name'}",$format);
$esheet->write($i,3,"$values->{'Folders_ShortName'}",$format);
$esheet->write($i,4,"$values->{'Folders_Name'}",$format);
$i++;
$o++;
}

$ebook->close();
 

10 More Discussions You Might Find Interesting

1. Programming

creating more than 2 excel sheets in C

Hi, I have a question about using C to write excel file. There is a way to write into a sheet into a file excel, like this: FILE * File; pMyFile = fopen("test.xls", "w+"); fprintf(File, "\n\n"); /* go to the row 2 of the column A*/ fprintf(File, "%s", "Hi pippo!"); /* write... (7 Replies)
Discussion started by: manceryder
7 Replies

2. Shell Programming and Scripting

Multiple excel work sheets through UNIX

Hi, There is this requirement to create multiple work sheets in an MS Excel file through UNIX. We normally can create one work sheet in unix by either tab or comma delimiting and appending .xls or .csv to the file name, but can we create multiple work sheets. Regards, Puspendu (1 Reply)
Discussion started by: puspendu
1 Replies

3. Shell Programming and Scripting

How to format excel sheets in UNIX??

Hi, I have generated an excel sheet using a shell script. i have converted the output text file to an excel and got the desired output. However, in a particular column in the excel the values of the numbers start with 0. e.g. 078393343, 00342442, etc. But, in the resulting excel I get as... (2 Replies)
Discussion started by: Vijay06
2 Replies

4. Shell Programming and Scripting

Run SQL queries in DB2 and output to file

Hi, I new to Unix and scripting. Following is my requirement. Can someone tell me whether its possible or not. Also please let me know how to proceed further if this is possible. List of queries are stored in a file. For example, I have to run a query like this: Select * from &XYZ where... (0 Replies)
Discussion started by: simhasuri
0 Replies

5. Shell Programming and Scripting

Help to get the Output of PL/SQL procedure In a Excel or Text File

Hi, Could anyone please guide me to get the output of the PL/SQL procedure in a Excel file or Text File... Thanks (1 Reply)
Discussion started by: funonnet
1 Replies

6. Shell Programming and Scripting

create separate files from one excel file with multiple sheets

Hi, I have one requirement, create separate files (".csv") from one excel file(xlsx) with multiple sheets. These ".csv" files are my source files. So anybody please suggest me the process. Thanks in Advance. Regards, Harris (3 Replies)
Discussion started by: harris
3 Replies

7. Shell Programming and Scripting

Write two csv files into one excel with multiple sheets

I have requirement to write two CSV files to one single excel with multiple sheets. Data present in the two files should sit in excel as different sheets. How can we achieve this using shell script? 1.csv 2. csv 1,2,3,4 5,6,7,8 XXXXX YYYYY Res.excel 1.csv data... (1 Reply)
Discussion started by: duplicate
1 Replies

8. Shell Programming and Scripting

Help with storing the output of multiple sql queries to a file

Hi All, I have a file queries.txt as follows : SELECT COLUMN1 FROM SCHEMA2.TABLE1 MINUS SELECT COLUMN1 FROM SCDEMA2.TABLE2; SELECT COLUMN2 FROM SCHEMA2.TABLE1 MINUS SELECT COLUMN2 FROM SCDEMA2.TABLE2; SELECT COLUMN3 FROM SCHEMA2.TABLE1 MINUS SELECT COLUMN3 FROM SCDEMA2.TABLE2; SELECT... (2 Replies)
Discussion started by: SriRamKrish
2 Replies

9. Shell Programming and Scripting

Script to generate Excel file or to SQL output data to Excel format/tabular format

Hi , i am generating some data by firing sql query with connecting to the database by my solaris box. The below one should be the header line of my excel ,here its coming in separate row. TO_CHAR(C. CURR_EMP_NO ---------- --------------- LST_NM... (6 Replies)
Discussion started by: dani1234
6 Replies

10. Shell Programming and Scripting

Storing multiple sql queries output into variable by running sql command only once

Hi All, I want to run multiple sql queries and store the data in variable but i want to use sql command only once. Is there a way without running sql command twice and storing.Please advise. Eg : Select 'Query 1 output' from dual; Select 'Query 2 output' from dual; I want to... (3 Replies)
Discussion started by: Rokkesh
3 Replies
Spreadsheet::ParseExcel::Simple(3pm)			User Contributed Perl Documentation		      Spreadsheet::ParseExcel::Simple(3pm)

NAME
Spreadsheet::ParseExcel::Simple - A simple interface to Excel data SYNOPSIS
my $xls = Spreadsheet::ParseExcel::Simple->read('spreadsheet.xls'); foreach my $sheet ($xls->sheets) { while ($sheet->has_data) { my @data = $sheet->next_row; } } DESCRIPTION
This provides an abstraction to the Spreadsheet::ParseExcel module for simple reading of values. You simply loop over the sheets, and fetch rows to arrays. For anything more complex, you probably want to use Spreadsheet::ParseExcel directly. BOOK METHODS
read my $xls = Spreadsheet::ParseExcel::Simple->read('spreadsheet.xls'); This opens the spreadsheet specified for you. Returns undef if we cannot read the book. sheets @sheets = $xls->sheets; Each spreadsheet can contain one or more worksheets. This fetches them all back. You can then iterate over them, or jump straight to the one you wish to play with. book my $book = $xls->book; The Spreadsheet::ParseExcel object we are working with. You can use this if you need to manipulate it in ways that this interface doesn't allow. SHEET METHODS
These methods can be called on each sheet returned from $xls->sheets: has_data if ($sheet->has_data) { ... } This lets us know if there are more rows in this sheet that we haven't read yet. This allows us to differentiate between an empty row, and the end of the sheet. next_row my @data = $sheet->next_row; Fetch the next row of data back. sheet my $obj = $sheet->sheet; The underlying Spreadsheet::ParseExcel object for the worksheet. You can use this if you need to manipulate it in ways that this interface doesn't allow (e.g. asking it for the sheet's name). AUTHOR
Tony Bowden BUGS and QUERIES Please direct all correspondence regarding this module to: bug-Spreadsheet-ParseExcel-Simple@rt.cpan.org COPYRIGHT AND LICENSE
Copyright (C) 2001-2005 Tony Bowden. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. SEE ALSO
Spreadsheet::ParseExcel. perl v5.8.8 2008-03-12 Spreadsheet::ParseExcel::Simple(3pm)
All times are GMT -4. The time now is 04:24 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy