insert header row into .xls


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers insert header row into .xls
# 1  
Old 12-06-2007
insert header row into .xls

Hello,

I am building an .xls file extracting info from a DB to be eventually emailed. All is good except how do I put in a header row.. like date, name of report etc. before the columns with the actual column name and data?
Thanks for any assistance.. the below is after I have signed into sqlplus


set serveroutput on size 1000000
set timing off
set feedback off

WHENEVER sqlerror EXIT failure
WHENEVER oserror EXIT failure
SET termout OFF
SET pagesize 1000
SET linesize 1600
prompt Report
spool Report

set trims on
set feed off markup html on spool on
COLUMN username heading "USERNAME" format a25;
COLUMN account_status heading "ACCT_STATUS" format a25;
COLUMN lock_date heading "LOCK_DT" format a25;
COLUMN expiry_date heading "EXPIRY_DT" format a25;
COLUMN created heading "CREATED" format a25;
COLUMN profile heading "PROFILE" format a25;
COLUMN sidba heading "SIDBA" format a25;
COLUMN remarks heading "REMARKS" format a25;
--NEW USERS

SELECT s.username, s.account_status, s.lock_date, s.expiry_date, s.created,s.profile, s.sidba, 'NEW' REMARKS
FROM sidba_users s
WHERE
s.created >=(trunc(sysdate)-90)
and
s.account_status= 'OPEN';
# 2  
Old 12-06-2007
Quote:
Originally Posted by Tish
I am building an .xls file extracting info from a DB to be eventually emailed.
Are you truely making an Excel .xls file or are you fudging by creating CSV file but calling it an .xls file?

If the latter, then as you know what order the fields are coming out in, so create a single row with those names. Then

Code:
cat header-row data-rows >final_file

# 3  
Old 12-06-2007
Actually creating the .xls.. not .csv...
Thank you for your assistance
# 4  
Old 12-06-2007
What tool do you use to create the XLS?
# 5  
Old 12-06-2007
Hi Porter,

Thank you for your help. Not sure I understand your question.. below is the .ksh. This works fine and produces the email, data in correct column. Just trying now to pretty it up and give the .xls sheet a header.

#!/bin/ksh

REPORT_FILE="QrtlyDBUsers.xls"
sqlplus -s <<eoj >>$LOG 2>&1
${USER}/${PASSWORD}@${SID}
set serveroutput on size 1000000
set timing off
set feedback off

WHENEVER sqlerror EXIT failure
WHENEVER oserror EXIT failure
SET termout OFF
SET pagesize 1000
SET linesize 1600
prompt $REPORT_FILE
spool $REPORT_FILE

set trims on
set feed off markup html on spool on
COLUMN username heading "USERNAME" format a25;
COLUMN account_status heading "ACCT_STATUS" format a25;
COLUMN lock_date heading "LOCK_DT" format a25;
COLUMN expiry_date heading "EXPIRY_DT" format a25;
COLUMN created heading "CREATED" format a25;
COLUMN profile heading "PROFILE" format a25;
COLUMN sidba heading "SIDBA" format a25;
--COLUMN expctd_prof heading "EXPCTD_PROFILE" format a25;
COLUMN remarks heading "REMARKS" format a25;
--NEW USERS
SELECT s.username, s.account_status, s.lock_date, s.expiry_date, s.created,s.profile, s.sidba, 'NEW' REMARKS
FROM sidba_users s
WHERE
s.created >=(trunc(sysdate)-90)
and
s.account_status= 'OPEN';
set markup html off spool off



exit;
eoj

unix2dos $REPORT_FILE | uuencode $REPORT_FILE $REPORT_FILE | mailx -s "Qtrly DB Reports" $Mail_list



Tish
# 6  
Old 12-06-2007
Okay, you are not create an Excel .xls file, you are creating a text file that happens to have a .xls extension.

If you were truely creating an Excel .xls then "unix2dos" would play merry havoc with it.

What does "set ... markup html on ..." do?
# 7  
Old 12-06-2007
I stand corrected, thanks for clarifying. Sure you guessed I am new to Unix.
Your previous suggestion : cat header-row data-rows >final_file
not sure I understand how I can use this.

Tish
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to insert header with underline?

How to insert header with underline AM able to insert only header not underline sed '1i NAME COUNTRY' test.txt input file UK 1234 USA 2354 AUS 2253 IND 4256 Output file NAME COUNTRY_CODE ---- ------------ UK 1234 USA 2354 AUS 2253 IND 4256 (5 Replies)
Discussion started by: Kalia
5 Replies

2. Shell Programming and Scripting

At text to field 1 of header row using awk

I am just trying to insert the word "Index" using awk. The below is close but seems to add the word at the end and I can not get the syntax correct to add from the beginning. Thank you :). awk -F'\t' -v OFS='\t' '{ $-1=$-1 OFS "Index"}$1=$1' file current output Chr Start End ... (3 Replies)
Discussion started by: cmccabe
3 Replies

3. Shell Programming and Scripting

How to display the header of a matched row in a file?

Hi, So I am trying to print the first row(header) first column alongwith the matched value. But I am not sure how do I print the same, by matching a pattern located in the file eg File contents Name Place Jim NY Jill NJ Cathy CA Sam TX Daniel FL And what I want is... (2 Replies)
Discussion started by: sidnow
2 Replies

4. Shell Programming and Scripting

Add column header and row header

Hi, I have an input like this 1 2 3 4 2 3 4 5 4 5 6 7 I would like to count the no. of columns and print a header with a prefix "Col". I would also like to count the no. of rows and print as first column with each line number with a prefix "Row" So, my output would be ... (2 Replies)
Discussion started by: jacobs.smith
2 Replies

5. UNIX for Dummies Questions & Answers

Merge all csv files in one folder considering only 1 header row and ignoring header of all others

Friends, I need help with the following in UNIX. Merge all csv files in one folder considering only 1 header row and ignoring header of all other files. FYI - All files are in same format and contains same headers. Thank you (4 Replies)
Discussion started by: Shiny_Roy
4 Replies

6. Shell Programming and Scripting

Perl array with row header

Here is the csv file file i have: ServerName, IPAddress, Gateway, Notes ServerA, 192.168.1.100, 192.168.1.1, This is some server ServerB, 192.168.1.110, 192.168.1.1, This is some other server ServerC, 192.168.1.120, 192.168.1.1, This is some other other server I would like to have the... (6 Replies)
Discussion started by: Ikon
6 Replies

7. UNIX for Dummies Questions & Answers

split header row into one column

So, I have a massive file with thousands of columns I want a list of the headers in one column in another file. So I need to strip off the top line (can use head-1) But how can I convert from this format: A B C D E F G to A B C D E F G (6 Replies)
Discussion started by: polly_falconer
6 Replies

8. Shell Programming and Scripting

Insert Header Name

Can anyone help. I have sql to CSV showing header with ALIAS names but I want to generate CSV file with user friendly name i.e from AIAN8 to Adress Book Number etc. SELECT AIAN8 || , || F0101.ABALPH || , || AICO || showing following below in CSV output intead of above Address... (4 Replies)
Discussion started by: s1a2m3
4 Replies

9. Shell Programming and Scripting

How to insert data befor some field in a row of data depending up on values in row

Hi I need to do some thing like "find and insert before that " in a file which contains many records. This will be clear with the following example. The original data record should be some thing like this 60119827 RTMS_LOCATION_CDR INSTANT_POSITION_QUERY 1236574686123083rtmssrv7 ... (8 Replies)
Discussion started by: aemunathan
8 Replies

10. Shell Programming and Scripting

unable Insert data from .dat file to .xls can anybody help me

Hi All, I am new to unix Shell scripting Actually i need to write a shell script to insert data from a dat file to ms-Excel file The data in the dat file will be like this Col1 Col2 Col3 Col4 and and Col5 I a new... (1 Reply)
Discussion started by: kreddy2003
1 Replies
Login or Register to Ask a Question