Oracle to CSV to XLS


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Oracle to CSV to XLS
# 1  
Old 10-28-2011
Oracle to CSV to XLS

I would like to know if have one way with read table from oracle converter in CSV o TXT and After converter in XLS or spreedsheet

Thanks so much
JAvier
# 2  
Old 10-28-2011
CSV should be fine to open in excel, just create a .csv extension when spooling or such.
There are many choices, from sqlplus with formatting options (it really has alot of options Smilie ) to perl, python (which can actual make xls blobs) etc.
# 3  
Old 10-28-2011
As Peasant commented, Windows associates CSV extension to Excel (by default), so Excel will open it.

To extract the data we have some options:
Code:
# File_1.sql - Using COLSEP
SET LINESIZE 700 -- This may change, depends on your output line size
SET PAGESIZE 0
SET FEEDBACK OFF
SET VERIFY OFF
SET HEADING OFF
SET COLSEP ","
-- Example query
Select 1,
         2
From Dual;

# File_2.sql - Using "CONCAT"
SET LINESIZE 700 -- This may change, depends on your output line size
SET PAGESIZE 0
SET FEEDBACK OFF
SET VERIFY OFF
SET HEADING OFF
-- Example query
Select 1 || ',' ||
         2
From Dual;

Just one more comment, be sure that there are no "," in the fields you are extracting, otherwise you may face problems or, in every field you extract, you can use the Oracle REPLACE function:
Code:
REPLACE(TABLE_COLUMN, ',', ' ')

I hope it helps!
# 4  
Old 10-28-2011
more unix beacuase the files is unix:
Code:
#!/usr/bin/perl -w
###############################################################################
#
# Example of how to use the WriteExcel module
#
# Program to convert a CSV comma-separated value file into an Excel file.
# This is more or less an non-op since Excel can read CSV files.
# The program uses Text::CSV_XS to parse the CSV.
#
# Usage: csv2xls.pl file.csv newfile.xls
#
# reverse(''), March 2001, John McNamara, jmcnamara@cpan.org
#
use strict;
use Spreadsheet::WriteExcel;
use Text::CSV_XS;
# Check for valid number of arguments
if (($#ARGV < 1) || ($#ARGV > 2)) {
   die("Usage: csv2xls csvfile.txt newfile.xls\n");
};
# Open the Comma Separated Variable file
open (CSVFILE, $ARGV[0]) or die "$ARGV[0]: $!";
# Create a new Excel workbook
my $workbook  = Spreadsheet::WriteExcel->new($ARGV[1]);
my $worksheet = $workbook->add_worksheet();
# Create a new CSV parsing object
#my $csv = Text::CSV_XS->new;
#binmode CSV;
#my $csv = Text::CSV_XS->new({
my $csv = Text::CSV_XS->new({
        'quote_char'  => '"',
        'escape_char' => '',
        'sep_char'    => '|',
        'binary'      => 1,
});

# Row and column are zero indexed
my $row = 0;

while (<CSVFILE>) {
    if ($csv->parse($_)) {
        my @Fld = $csv->fields;
        my $col = 0;
        foreach my $token (@Fld) {
            $worksheet->write($row, $col, $token);
            $col++;
        }
        $row++;
    }
    else {
        my $err = $csv->error_input;
        print "Text::CSV_XS parse() failed on argument: ", $err, "\n";
    }
}


Last edited by Scott; 11-23-2011 at 02:18 PM.. Reason: Please use code tags
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Csv to xls

Hello I have a script which converts log to csv. Now I need to have xls. Is there any easy way/command which can convert csv to xls?:confused: preferably just using bash and not perl,... is it possible? (1 Reply)
Discussion started by: frhling
1 Replies

2. Shell Programming and Scripting

csv to xls : missing rows

A unix script generates a file "1.csv". I use the following to email this as an excel sheet. /usr/bin/uuencode /tmp/1.csv 1.csv > $PATH/attachment.txt mailx -r abc@domain.com -s "Subject" myself@domain.com < $PATH/attachment.txtI get the file as CSV in the email and everything is fine except... (9 Replies)
Discussion started by: girish1428
9 Replies

3. Shell Programming and Scripting

CSV to XLS

Ok, every morning at my office we send out excel sheets to Economy people with statistics for yesterdays trading. All the trading run's in Redhat or Solaris environments. We run a script on a Redhat server whitch generates the stats in CSV format. After we download we open it in Excel and... (3 Replies)
Discussion started by: chipmunken
3 Replies

4. Shell Programming and Scripting

how to convert .xls to .csv

Hi, I have problem..How to convert .xls file to .csv.. Plz help me for this problem.. (1 Reply)
Discussion started by: varma457
1 Replies

5. Shell Programming and Scripting

converting xls file to txt file and xls to csv

I need to convert an excel file into a text file and an excel file into a CSV file.. any code to do that is appreciated thanks (6 Replies)
Discussion started by: bandar007
6 Replies

6. Shell Programming and Scripting

xls to csv

how to convert a xls file into .csv file? is tghere any command in unix for that? please help thanks (3 Replies)
Discussion started by: infyanurag
3 Replies

7. UNIX for Dummies Questions & Answers

WINDOWS to UNIX : xls to csv

Hi, I need to ftp a .xls file from WINDOWS to UNIX. When I do it, the file coversion doesn't happen(??) or UNIX doesn't recognixe this format I know not. But there will be junk values in the ftp'd file. Note: The ftp will be done by a script and I don't think we could place a WINDOWS script on... (5 Replies)
Discussion started by: preethgideon
5 Replies

8. Shell Programming and Scripting

.xls to .csv conversion

Hi Please can someone tell me how i can convert .xls file into .csv on both platforms, windows and unix. many thanks, neil (4 Replies)
Discussion started by: neil546
4 Replies

9. Shell Programming and Scripting

From xls to csv file

Can we convert an xls file into csv format in Unix Thanks Suresh (1 Reply)
Discussion started by: sureshg_sampat
1 Replies

10. Shell Programming and Scripting

Converting csv to xls

Hi, Can anyone tell the option to change the file type in unix. i.e. if a file is in csv(Comma Separating Values) format, it should be changed to xls(ordinary MS-Excel) format. But renaming command is not changing to correct file format. Thanks in advance, Milton. (1 Reply)
Discussion started by: miltony
1 Replies
Login or Register to Ask a Question