Generating Excel file using PL/SQL

Hi,
I wanted to generate the excel file using the below pasted PL/SQL which I have downloaded from one of the tech sites. And as I have very limited knowledge about PL/SQL I really dont know how & where I should compile this below mentioned code and get the desired O/P?
Please reply me ASAP if anybody can help me with this?
Please see the below code and please help me to interpret the same.
CREATE OR REPLACE PACKAGE gen_xl_xml IS
-- Version 0.5
-- Objective : The main objective OF this PACKAGE IS TO CREATE excel files from PL/SQL code
-- Requirement : Excel version 2003 onwards support XML format.
-- The procedures does have TO be called IN specific order at this moment.
-- expected SEQUENCE AS OF now IS
-- At first call create_file -> It creates a FILE WITH NAME that you pass AS parameter. This PROCEDURE writes the
-- excel file header AND some basic requirments like default style.
-- procedures 1. create_style , create_worksheet AND write_cell can be used IN ANY SEQUENCE AS many
-- times AS you need.
-- When done WITH writing TO FILE call the PROCEDURE close_file
-- CLOSE FILE --> This will actually flush the data INTO the worksheet(s) one BY one and then close the file.
-- What colors I can use ?
-- red , blue , green, gray , YELLOW, BROWN , PINK . lightgray ,
debug_flag BOOLEAN := TRUE ;
PROCEDURE create_excel( p_directory IN VARCHAR2 DEFAULT NULL , p_file_name IN VARCHAR2 DEFAULT NULL ) ;
PROCEDURE create_excel_apps ;
PROCEDURE create_style( p_style_name IN VARCHAR2
, p_fontname IN VARCHAR2 DEFAULT NULL
, p_fontcolor IN VARCHAR2 DEFAULT 'Black'
, p_fontsize IN NUMBER DEFAULT null
, p_bold IN BOOLEAN DEFAULT FALSE
, p_italic IN BOOLEAN DEFAULT FALSE
, p_underline IN VARCHAR2 DEFAULT NULL
, p_backcolor IN VARCHAR2 DEFAULT NULL );
PROCEDURE close_file ;
PROCEDURE create_worksheet( p_worksheet_name IN VARCHAR2 ) ;
PROCEDURE write_cell_num(p_row NUMBER , p_column NUMBER, p_worksheet_name IN VARCHAR2, p_value IN NUMBER , p_style IN VARCHAR2 DEFAULT NULL );
PROCEDURE write_cell_char(p_row NUMBER, p_column NUMBER, p_worksheet_name IN VARCHAR2, p_value IN VARCHAR2, p_style IN VARCHAR2 DEFAULT NULL );
PROCEDURE write_cell_null(p_row NUMBER , p_column NUMBER , p_worksheet_name IN VARCHAR2, p_style IN VARCHAR2 );
PROCEDURE set_row_height( p_row IN NUMBER , p_height IN NUMBER, p_worksheet IN VARCHAR2 ) ;
PROCEDURE set_column_width( p_column IN NUMBER , p_width IN NUMBER , p_worksheet IN VARCHAR2 ) ;
END ;
-- Package : gen_xl_sml
-- Version : 0.62
CREATE OR REPLACE PACKAGE Body gen_xl_xml IS
-- worksheets must be created before it could be passed AS parameter TO the write cell procedures
l_file utl_FILE.file_type ;
g_apps_env VARCHAR2(1) := 'U' ; -- unset at the start
TYPE tbl_excel_data IS TABLE OF VARCHAR2(2000) INDEX BY BINARY_INTEGER ;
g_excel_data tbl_excel_data ;
g_null_data tbl_excel_data ;
g_data_count NUMBER ;
TYPE rec_styles IS record ( s VARCHAR2(30) , def VARCHAR2(2000) );
TYPE tbl_style IS TABLE OF rec_styles INDEX BY BINARY_INTEGER ;
g_styles tbl_style ;
g_null_styles tbl_style ;
g_style_count NUMBER := 0;
TYPE rec_worksheets IS record ( w VARCHAR2(30) , whdr VARCHAR2(300), wftr VARCHAR2(2000) );
TYPE tbl_worksheets IS TABLE OF rec_worksheets INDEX BY BINARY_INTEGER ;
g_worksheets tbl_worksheets ;
g_null_worksheets tbl_worksheets ;
g_worksheets_count NUMBER := 0;
TYPE rec_cell_data IS record ( r NUMBER , c NUMBER , v VARCHAR2(2000) ,s VARCHAR2(30) , w VARCHAR2(100), dt VARCHAR2(8) );
TYPE tbl_cell_data IS TABLE OF rec_cell_data INDEX BY binary_INTEGER ;
g_cells tbl_cell_data ;
g_null_cells tbl_cell_data ;
g_cell_count NUMBER := 0 ;
TYPE rec_columns_data IS record( c NUMBER, wd NUMBER, w VARCHAR2(30) ) ;
TYPE tbl_columns_data IS TABLE OF rec_columns_data Index BY BINARY_INTEGER ;
g_columns tbl_columns_data ;
g_null_columns tbl_columns_data ;
g_column_count NUMBER ;
TYPE rec_rows_data IS record( r NUMBER, ht NUMBER , w VARCHAR2(30) ) ;
TYPE tbl_rows_data IS TABLE OF rec_rows_data Index BY BINARY_INTEGER ;
g_rows tbl_ROWS_data ;
g_null_rows tbl_rows_data ;
g_ROW_count NUMBER ;
PROCEDURE p ( p_string IN VARCHAR2) is
begin
IF debug_flag = TRUE THEN
DBMS_OUTPUT.put_line( p_string) ;
END IF;
END ;
FUNCTION style_defined ( p_style IN VARCHAR2 ) RETURN BOOLEAN IS
BEGIN
FOR i IN 1..g_style_count LOOP
IF g_styles(i).s = p_style THEN
RETURN TRUE ;
END IF;
END LOOP ;
RETURN FALSE ;
END ;
-- Function : cell_used returns : BOOLEAN
-- Description : Cell_used FUNCTION returns TRUE IF that cell IS already used
-- Called BY : write_Cell_char, write_cell_num
-- ??? right now it IS NOT called BY write_Cell_null , this needs TO be evaluated
FUNCTION cell_used ( p_r IN NUMBER , p_c IN number , p_w IN VARCHAR2 ) RETURN BOOLEAN IS
BEGIN
FOR i IN 1..g_cell_count LOOP
IF ( g_cells(i).r = p_r AND g_cells(i).c = p_c AND g_cells(i).w = p_w ) THEN
RETURN TRUE ;
END IF;
END LOOP ;
RETURN FALSE ;
END ;
PROCEDURE initialize_collections IS
--- following lines resets the cell data and the cell count as it was
-- observed that the data is retained across the two runs within same seseion.
BEGIN
g_cells := g_null_cells ;
g_Cell_count := 0 ;
g_styles := g_null_styles ;
g_style_count := 0 ;
g_rows := g_null_rows ;
g_ROW_count := 0 ;
g_columns := g_null_columns ;
g_column_count := 0 ;
g_excel_data := g_null_data ;
g_data_count := 0 ;
g_apps_env := 'U';
g_worksheets := g_null_worksheets ;
g_worksheets_count := 0;
END ;
PROCEDURE create_excel_apps is
BEGIN
-- CHECK the env value
IF g_apps_env = 'N' THEN
raise_application_error( -20001 , 'You have already called create_excel ( Non Apps ) procedure, Can not set env to create_excel_apps.');
END IF ;
initialize_collections ;
g_apps_env := 'Y' ;
END ;
PROCEDURE create_excel( p_directory IN VARCHAR2 DEFAULT NULL , p_file_name IN VARCHAR2 DEFAULT NULL )
IS
BEGIN
-- CHECK the env value
IF g_apps_env = 'Y' THEN
raise_application_error( -20001 , 'You have already called procedure create_excel_apps , Can not set env to Non-Apps create_excel.');
END IF ;
initialize_collections ;
g_apps_env := 'N' ;
IF ( p_directory IS NULL OR p_file_name IS NULL ) THEN
raise_application_error( -20001 , 'p_directory and p_file_name must be not null');
END IF ;
BEGIN
-- Open the FILE IN the specified directory
l_file := utl_file.fopen( p_directory, p_file_name , 'w') ;
EXCEPTION
WHEN utl_file.write_error THEN
raise_application_error( -20101 , 'UTL_FILE raised write error, check if file is already open or directory access');
WHEN utl_file.INVALID_OPERATION THEN
raise_application_error( -20101 , 'UTL_FILE could not open file or operate on it, check if file is already open.');
WHEN utl_file.invalid_path THEN
raise_application_error( -20101 , 'UTL_FILE raised invalid path, check the directory passed is correct and you have access to it.');
WHEN others THEN
raise_application_error( -20101 , 'UTL_FILE raised others exception ');
END ;
p( 'File '||p_file_name ||' created successfully');
END ;
PROCEDURE create_style( p_style_name IN VARCHAR2
, p_fontname IN VARCHAR2 DEFAULT NULL
, p_fontcolor IN VARCHAR2 DEFAULT 'Black'
, p_fontsize IN NUMBER DEFAULT null
, p_bold IN BOOLEAN DEFAULT FALSE
, p_italic IN BOOLEAN DEFAULT FALSE
, p_underline IN VARCHAR2 DEFAULT NULL
, p_backcolor IN VARCHAR2 DEFAULT NULL ) is
l_style VARCHAR2(2000) ;
l_font VARCHAR2(1200);
BEGIN
--- CHECK IF this style IS already defined AND RAISE ERROR IF yes
IF style_defined( p_style_name ) THEN
RAISE_application_error( -20001 , 'Style "'||p_style_name ||'" is already defined.');
END IF;
g_style_count := g_style_count + 1;
---- ??? pass ANY value OF underline AND it will only use single underlines
-- ??? pattern IS NOT handleed
IF upper(p_style_name) = 'DEFAULT' THEN
RAISE_application_error( -20001 , 'Style name DEFAULT is not allowed ');
END IF ;
IF upper(p_style_name) IS NULL THEN
RAISE_application_error( -20001 , 'Style name can not be null ');
END IF ;
g_styles(g_style_count).s := p_style_name ;
g_styles(g_style_count).def := ' <Style ss:ID="'|| p_style_name ||'"> ' ;
l_font := ' <Font ' ;
IF p_fontname IS NOT NULL THEN
l_font :=l_font || 'ss:FontName="'|| p_fontname ||'" ';
end if ;
IF p_fontsize is not null then
l_font := l_font ||' ss:Size="'|| p_fontsize ||'" ';
end if ;
IF p_fontcolor is not null then
l_font := l_font ||' ss:Color="'|| p_fontcolor ||'" ';
ELSE
l_font := l_font ||' ss:Color="Black" ';
end if ;
IF p_bold = TRUE THEN
l_font := l_font ||' ss:Bold="1" ' ;
END IF;
IF p_italic = TRUE THEN
l_font := l_font ||' ss:Italic="1" ' ;
END IF;
IF p_underline IS NOT NULL THEN
l_font := l_font ||' ss:Underline="Single" ' ;
END IF ;
-- p( l_font );
g_styles(g_style_count).def := g_styles(g_style_count).def || l_font || '/>' ;
IF p_backcolor IS NOT NULL THEN
g_styles(g_style_count).def := g_styles(g_style_count).def || ' <Interior ss:Color="'||p_backcolor ||'" ss:Pattern="Solid"/>' ;
ELSE
g_styles(g_style_count).def := g_styles(g_style_count).def || ' <Interior/>';
END IF ;
g_styles(g_style_count).def := g_styles(g_style_count).def || ' </Style>' ;
--- ??? IN font there IS SOME family which IS NOT considered
END ;
PROCEDURE close_file IS
l_last_row NUMBER := 0 ;
l_dt CHAR ; -- ??? Variable TO store the datatype ; this IS NOT used at this time but may be needed IF the memory
-- issue IS there FOR example IF there IS big array
l_style VARCHAR2(140) ;
l_row_change VARCHAR2(100) ;
l_file_header VARCHAR2(2000) := '<?xml version="1.0"?>
<?mso-application progid="Excel.Sheet"?>
<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"
xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:x="urn:schemas-microsoft-com:office:excel"
xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"
xmlns:html="http://www.w3.org/TR/REC-html40">
<DocumentProperties xmlns="urn:schemas-microsoft-com:office:office">
<LastAuthor>a</LastAuthor>
<Created>1996-10-14T23:33:28Z</Created>
<LastSaved>2007-05-10T04:00:57Z</LastSaved>
<Version>11.5606</Version>
</DocumentProperties>
<ExcelWorkbook xmlns="urn:schemas-microsoft-com:office:excel">
<WindowHeight>9300</WindowHeight>
<WindowWidth>15135</WindowWidth>
<WindowTopX>120</WindowTopX>
<WindowTopY>120</WindowTopY>
<AcceptLabelsInFormulas/>
<ProtectStructure>False</ProtectStructure>
<ProtectWindows>False</ProtectWindows>
</ExcelWorkbook>
<Styles>
<Style ss:ID="Default" ss:Name="Normal">
<Alignment ss:Vertical="Bottom"/>
<Borders/>
<Font/>
<Interior/>
<NumberFormat/>
<Protection/>
</Style>'
BEGIN
IF gen_xl_xml.g_Cell_count = 0 THEN
raise_application_error( -20007 , 'No cells have been written, this version of gen_xl_xml needs at least one cell to be written');
END IF;
IF gen_xl_xml.g_worksheets_count = 0 THEN
raise_application_error( -20008 , 'No worksheets have been created, this version does not support automatic worksheet creation');
END IF;
p( gen_xl_xml.g_Cell_count) ;
-- Write the header xml part IN the FILE.
g_data_count := g_data_count + 1 ;
g_excel_data( g_data_count ) := l_file_header ;
p( 'Headers written');
FOR i IN 1..g_style_count LOOP
p( ' writing style number : '||i);
g_data_count := g_data_count + 1 ;
g_excel_data( g_data_count ) := g_styles(i).def ;
END LOOP ;
-- CLOSE the styles tag
g_data_count := g_data_count + 1 ;
g_excel_data( g_data_count ) := ' </Styles>' ;
p( 'worksheet count '|| g_worksheets_count );
FOR j IN 1..g_worksheets_count LOOP
l_last_row := 0 ; --- FOR every worksheet we need TO CREATE START OF the row
p( '()()------------------------------------------------------------ last row '||l_last_row );
--- write the header first
-- write the COLUMN widhts first
-- write the cells
-- write the worksheet footer
l_row_change := NULL ;
g_data_count := g_data_count + 1 ;
g_excel_data( g_data_count ) := ' <Worksheet ss:Name="'|| g_worksheets( j).w ||'"> ' ;
p( '-------------------------------------------------------------');
p( '****************.Generated sheet '|| g_worksheets( j).w);
p( '-------------------------------------------------------------');
-- write the TABLE structure ??? change the LINE here TO include tha maxrow AND cell
g_data_count := g_data_count + 1 ;
g_excel_data( g_data_count ) := '<Table ss:ExpandedColumnCount="16" ss:ExpandedRowCount="44315" x:FullColumns="1" x:FullRows="1">' ;
FOR i IN 1..g_column_count LOOP
IF g_columns(i).w = g_worksheets( j).w THEN
g_data_count := g_data_count + 1 ;
g_excel_data( g_data_count ) := ' <Column ss:Index="'||g_columns(i).c||'" ss:AutoFitWidth="0" ss:Width="'||g_columns(i).wd ||'"/> ' ;
END IF;
END LOOP ;
-- write the cells data
FOR i IN 1..g_cell_count LOOP ------ LOOP OF g_cell_count
p( '()()()()()()()()()()()() '|| i);
--- we will write only IF the cells belongs TO the worksheet that we are writing.
IF g_cells(i).w <> g_worksheets(j).w THEN
p( '........................Cell : W :'|| g_worksheets( j).w ||'=> r='|| g_cells(i).r ||',c ='|| g_cells(i).c||',w='|| g_cells(i).w );
p( '...Not in this worksheet ');
-- l_last_row := l_last_row -1 ;
ELSE
p( '........................Cell : W :'|| g_worksheets( j).w ||'=> r='|| g_cells(i).r ||',c ='|| g_cells(i).c||',w='|| g_cells(i).w );
IF g_cells(i).s IS NOT NULL AND NOT style_defined( g_cells(i).s ) THEN
-- p(g_cells(i).s) ;
raise_application_error( -20001 , 'Style "'||g_cells(i).s ||'" is not defined, Note : Styles are case sensative and check spaces used while passing style');
END IF;
p( '()()------------------------------------------------------------ last row '||l_last_row );
IF l_last_row = 0 THEN
FOR t IN 1..g_row_count LOOP
p( '...Height check => Row =' ||g_rows(t).r ||', w='||g_rows(t).w);
IF g_rows(t).r = g_cells(i).r AND g_rows(t).w = g_worksheets(j).w THEN
p( '...Changing height') ;
l_row_change := ' ss:AutoFitHeight="0" ss:Height="'|| g_rows(t).ht||'" ' ;
g_data_count := g_data_count + 1 ;
g_excel_data( g_data_count ) := ' <Row ss:Index="'||g_cells(i).r||'"'|| l_row_change ||'>' ;
l_last_row := g_cells(i).r ;
EXIT ;
ELSE
p( '...NO change height') ;
l_row_change := NULL ;
END IF ;
END loop ;
IF l_ROW_CHANGE IS NULL THEN
g_data_count := g_data_count + 1 ;
p( '...Creating new row ');
g_excel_data( g_data_count ) := ' <Row ss:Index="'||g_cells(i).r||'"'|| l_row_change ||'>' ;
l_last_row := g_cells(i).r ;
END IF;
END IF;
IF g_cells(i).s IS NOT NULL THEN
p( '...Adding style ');
l_style := ' ss:StyleID="'||g_cells(i).s||'"' ;
ELSE
p( '...No style for this cell ');
l_style := NULL ;
END IF;
p( '()()------------------------------------------------------------ last row '||l_last_row );
IF g_cells(i).r <> l_last_row THEN
p('...closing the row.'||g_cells(i).r);
g_data_count := g_data_count + 1 ;
g_excel_data( g_data_count ) := ' </Row>' ;
p( 'ROWCOUNT : '||g_row_count );
FOR t IN 1..g_ROW_count LOOP
p( '.....Height check => Row =' ||g_rows(t).r ||', w='||g_rows(t).w);
IF g_rows(t).r = g_cells(i).r AND g_rows(t).w = g_worksheets(j).w THEN
p( '.....Changing height') ;
l_row_change := ' ss:AutoFitHeight="0" ss:Height="'|| g_rows(t).ht||'" ' ;
g_data_count := g_data_count + 1 ;
g_excel_data( g_data_count ) := ' <Row ss:Index="'||g_cells(i).r||'"'|| l_row_change ||'>' ;
EXIT ;
ELSE
p( '.....NO change height') ;
l_row_change := NULL ;
END IF ;
END loop ;
-- P( 'Row :'||g_cells(i).r ||'->'|| l_ROW_CHANGE);
IF l_row_change IS NULL THEN
g_data_count := g_data_count + 1 ;
g_excel_data( g_data_count ) := ' <Row ss:Index="'||g_cells(i).r||'"'|| l_row_change ||'>' ;
END IF;
IF g_cells(i).v IS NULL THEN
g_data_count := g_data_count + 1 ;
g_excel_data( g_data_count ) := '<Cell ss:Index="'||g_cells(i).c||'"' || l_style ||' ></Cell>';
ELSE
g_data_count := g_data_count + 1 ;
g_excel_data( g_data_count ) := '<Cell ss:Index="'||g_cells(i).c||'"' || l_style ||' ><Data ss:Type="'||g_cells(i).dt ||'">'||g_cells(i).v||'</Data></Cell>';
END IF ;
l_last_row :=g_cells(i).r ;
ELSE
IF g_cells(i).v IS NULL THEN
g_data_count := g_data_count + 1 ;
g_excel_data( g_data_count ) := '<Cell ss:Index="'||g_cells(i).c||'"' || l_style ||' > </Cell>';
ELSE
g_data_count := g_data_count + 1 ;
g_excel_data( g_data_count ) := '<Cell ss:Index="'||g_cells(i).c||'"' || l_style ||' ><Data ss:Type="'||g_cells(i).dt ||'">'||g_cells(i).v||'</Data></Cell>';
END IF ;
END IF ;
END IF ;
NULL ;
END LOOP ; -- LOOP OF g_cells_count
p('...closing the row.');
g_data_count := g_data_count + 1 ;
g_excel_data( g_data_count ) := ' </Row>' ;
-- ??? does following COMMENT will have sheet NAME FOR debugging
p( '-------------------------------------------------------------');
p( '....End of writing cell data, closing table tag');
g_data_count := g_data_count + 1 ;
g_excel_data( g_data_count ) := ' </Table>' ;
g_data_count := g_data_count + 1 ;
g_excel_data( g_data_count ) := g_worksheets(j).wftr ;
p( '..Closed the worksheet '|| g_worksheets( j).w );
END LOOP ;
g_data_count := g_data_count + 1 ;
g_excel_data( g_data_count ) := '</Workbook>' ;
p( 'Closed the workbook tag');
IF g_apps_env = 'N' THEN
FOR i IN 1..g_data_count LOOP
utl_FILE.put_line( l_file, g_excel_data(i ));
END LOOP ;
utl_file.fclose( l_file );
p( 'File closed ');
ELSIF g_apps_env = 'Y' THEN
FOR i IN 1..g_data_count LOOP
fnd_file.put_line( fnd_file.output , g_excel_data(i));
fnd_file.put_line( fnd_file.log , g_excel_data(i));
END LOOP ;
ELSE
raise_application_error( -20001 , 'Env not set, ( Apps or not Apps ) Contact Support.' );
END IF;
END ;
PROCEDURE create_worksheet ( p_worksheet_name IN VARCHAR2 ) IS
BEGIN
g_worksheets_count := g_worksheets_count + 1 ;
g_worksheets(g_worksheets_count).w := p_worksheet_name ;
g_worksheets(g_worksheets_count).whdr := '<Worksheet ss:Name=" ' || p_worksheet_name ||' ">' ;
g_worksheets(g_worksheets_count).wftr := '<WorksheetOptions xmlns="urn:schemas-microsoft-com:office:excel">
<ProtectObjects>False</ProtectObjects>
<ProtectScenarios>False</ProtectScenarios>
</WorksheetOptions>
</Worksheet>' ;
END ;
PROCEDURE write_cell_char(p_row NUMBER, p_column NUMBER, p_worksheet_name IN VARCHAR2, p_value IN VARCHAR2, p_style IN VARCHAR2 DEFAULT NULL ) IS
l_ws_exist BOOLEAN ;
l_worksheet VARCHAR2(2000) ;
BEGIN
-- CHECK IF this cell has been used previously.
IF cell_used( p_row , p_column , p_worksheet_name ) THEN
RAISE_application_error( -20001 , 'The cell ( Row: '||p_row ||' Column:'||p_column ||' Worksheet:'||p_worksheet_name ||') is already used.Check if you have missed to increment row number in your code. ');
END IF;
-- IF worksheet NAME IS NOT passed THEN use first USER created sheet ELSE use DEFAULT sheet
-- this PROCEDURE just adds the data INTO the g_cells TABLE
g_cell_count := g_cell_count + 1 ;
g_cells( g_cell_count ).r := p_row ;
g_cells( g_cell_count ).c := p_column ;
g_cells( g_cell_count ).v := p_value ;
g_cells( g_cell_count ).w := p_worksheet_name ;
g_cells( g_cell_count ).s := p_style ;
g_cells( g_cell_count ).dt := 'String' ;
END ;
PROCEDURE write_cell_num(p_row NUMBER , p_column NUMBER, p_worksheet_name IN VARCHAR2, p_value IN NUMBER , p_style IN VARCHAR2 DEFAULT NULL ) IS
l_ws_exist BOOLEAN ;
l_worksheet VARCHAR2(2000) ;
BEGIN
-- ??? IF worksheet NAME IS NOT passed THEN use first USER created sheet ELSE use DEFAULT sheet
-- this PROCEDURE just adds the data INTO the g_cells TABLE
-- CHECK IF this cell has been used previously.
IF cell_used( p_row , p_column , p_worksheet_name ) THEN
RAISE_application_error( -20001 , 'The cell ( Row: '||p_row ||' Column:'||p_column ||' Worksheet:'||p_worksheet_name ||') is already used. Check if you have missed to increment row number in your code.');
END IF;
g_cell_count := g_cell_count + 1 ;
g_cells( g_cell_count ).r := p_row ;
g_cells( g_cell_count ).c := p_column ;
g_cells( g_cell_count ).v := p_value ;
g_cells( g_cell_count ).w := p_worksheet_name ;
g_cells( g_cell_count ).s := p_style ;
g_cells( g_cell_count ).dt := 'Number' ;
END ;
PROCEDURE write_cell_null(p_row NUMBER , p_column NUMBER , p_worksheet_name IN VARCHAR2, p_style IN VARCHAR2 ) IS
BEGIN
-- ???? NULL IS allowed here FOR time being. one OPTION IS TO warn USER that NULL IS passed but otherwise
-- the excel generates without error
g_cell_count := g_cell_count + 1 ;
g_cells( g_cell_count ).r := p_row ;
g_cells( g_cell_count ).c := p_column ;
g_cells( g_cell_count ).v := null ;
g_cells( g_cell_count ).w := p_worksheet_name ;
g_cells( g_cell_count ).s := p_style ;
g_cells( g_cell_count ).dt := NULL ;
END ;
PROCEDURE set_row_height( p_row IN NUMBER , p_height IN NUMBER, p_worksheet IN VARCHAR2 ) IS
BEGIN
g_ROW_count := g_ROW_count + 1 ;
g_rows( g_row_count ).r := p_row ;
g_rows( g_row_count ).ht := p_height ;
g_rows( g_row_count ).w := p_worksheet ;
END ;
PROCEDURE set_column_width( p_column IN NUMBER , p_width IN NUMBER, p_worksheet IN VARCHAR2 ) IS
BEGIN
g_column_count := g_column_count + 1 ;
g_columns( g_column_count ).c := p_column ;
g_columns( g_column_count ).wd := p_width ;
g_columns( g_column_count ).w := p_worksheet ;
END ;
END ;
SHOW errors ;
Thanks,
Maddy B

Hi,
Peter Gjelstrup wrote:
Next thing is how to use it:
declare
k_file constant varchar2(30) := 'YourFile.xls'
begin
create_file(k_file);
-- Call other procedures
close_file;
end;
Don't forget: these procedures are all part of the gen_xl_xml package.
To call them from outside the package, you have to prefix each procedure name with the package name, like this:
declare
k_file constant varchar2(30) := 'YourFile.xls'
begin
gen_xl_xml.create_file(k_file);
-- Call other procedures
gen_xl_xml.close_file;
end;

Similar Messages

  • How can I create an csv/excel file using pl/sql and then sending that file

    How can I create an csv/excel file using pl/sql and then sending that file to a clients site using pl/sql?
    I know how to create the csv/excel file but I can't figure out how I would get it to the clients site.

    968776 wrote:
    How can I create an csv/excel file using pl/sql and then sending that file to a clients site using pl/sql?
    I know how to create the csv/excel file but I can't figure out how I would get it to the clients site.You are trying to do it at a wrong place..
    Whay do you want database (pl/sql) code to do these things?
    Anyhow, you may be interested in :
    {message:id=9360007}
    {message:id=9984244}

  • Writing into Excel file using PL/SQL and formatting the excel file

    Hi,
    I am writing into a excel file using PL/SQL and I want to make the first line bold on the excel. Also let me know if there are any other formatting options when writing into excel.
    Regards,
    -Anand

    I am writing into a excel file using PL/SQL
    Re: CSV into Oracle and Oracle into CSV
    check that thread or search in this forum...

  • Generating text file using PL/SQL

    can any body send sample program how to generate text file using PL/SQL program.I want to store table data into that text file.

    Hi,
    try this.
    Thanks
    CREATE OR REPLACE procedure write_index (TABLE_NAME_ACCEPT VARCHAR2) IS
    id UTL_FILE.FILE_TYPE;
    name VARCHAR2(20) := 'e:\db_coca\input';      
    err VARCHAR2(100);      
    ColNameLength Integer;
    NumberoFColumns Integer;
    num NUMBER;           
    i integer;
    loc_query VARCHAR2(2000);
    cursor_name INTEGER;
    ret INTEGER;
    l_const_name VARCHAR2(30);
    CURSOR c_columns(i_Constraint_name VARCHAR2) IS
         SELECT *
         FROM     all_cons_columns
         WHERE     CONSTRAINT_NAME = i_Constraint_name
         order by table_name;
    BEGIN
    DBMS_OUTPUT.PUT_LINE('BEFORe OPEN');
    --id := UTL_FILE.FOPEN('e:\db_coca\input',name,'w');          
         --IF UTL_FILE.IS_OPEN(id) THEN
         --     DBMS_OUTPUT.PUT_LINE('Opened');
         --ELSE
         --     DBMS_OUTPUT.PUT_LINE('Still Closed');           
         --END IF;          
    DBMS_OUTPUT.PUT_LINE('AFTER OPEN');
    --The table generation script
         loc_query := 'Select CONSTRAINT_NAME from user_constraints ';
         loc_query := loc_query || ' where owner = ' || '''CPS''';
         loc_query := loc_query || ' AND CONSTRAINT_TYPE = ' || '''P''';
         dbms_output.put_line('TABLE_NAME_ACCEPT = ' || TABLE_NAME_ACCEPT);
         IF NOT (TABLE_NAME_ACCEPT IS NULL ) THEN
              loc_query := loc_query || ' AND TABLE_NAME like ''';
              loc_query := loc_query || TABLE_NAME_ACCEPT ;
              loc_query := loc_query || '''';
         END IF;
         cursor_name := DBMS_SQL.OPEN_CURSOR;
    dbms_output.put_line('Query = ' || loc_query);
         DBMS_SQL.PARSE(cursor_name, loc_query, DBMS_SQL.v7);
    dbms_output.put_line('After parse');
         dbms_sql.DEFINE_COLUMN(cursor_name, 1,l_const_name, 30);
         ret := DBMS_SQL.EXECUTE(cursor_name);
    --     IF ret > 0 THEN
         LOOP
         dbms_output.put_line('return = ' || ret);
              IF DBMS_SQL.FETCH_ROWS(cursor_name) > 0 THEN
                   dbms_sql.COLUMN_VALUE(cursor_name, 1,l_const_name);
              --     dbms_sql.BIND_VARIABLE(cursor_name,
    l_const_name,CONSTRAINT_NAME);
              --     FOR C10 in Table_Loop Loop          --The cursor
    for the table name
                   Select COunt(*) INTO NumberoFColumns from
                   all_cons_columns
                   Where CONSTRAINT_NAME = l_const_name;
         --          FOR C11 IN c_columns(l_const_name) LOOP
         --          End loop;
         --          UTL_FILE.PUT(id, ');');
              ELSE EXIT;
              END if;     --THe 1 st cursor if is closed
         End Loop;     --The table loop ends here
              DBMS_SQL.CLOSE_CURSOR(cursor_name);
    --     END IF;     
    --     UTL_FILE.PUT_LINE(id,name);
    --     UTL_FILE.PUT(id,'It worked and wrote to this file');
         UTL_FILE.FCLOSE(id);
         DBMS_OUTPUT.PUT_LINE('Successful write to file');          
    EXCEPTION     
    WHEN OTHERS THEN               
         err := SQLERRM;          
         num := SQLCODE;
         DBMS_OUTPUT.PUT_LINE(err);          
         DBMS_OUTPUT.PUT_LINE(num);
         DBMS_OUTPUT.PUT_LINE('Error in writing to file');     
    END write_index;

  • Generate Excel File using Java

    Hi,
    could any one tell me how can I create an Excel file using java. I can create the file using PrintWriter and other IO classes. But how do I insert the data in to different cells and rows.
    Any help would be greatly appreciated. Thanks in advance for your help,
    -MS

    Dear All,
    There are three ways for achiving excel operations using java including excel to xml etc.
    1. There is a very effective tool available for this operation is "jexcel". You can find it at http://www.andykhan.com/jexcelapi/index.html
    2. Jakarta site has provided a very good tool by name jakarta poifs. one can find at jakarta site.
    3. One can develop a very effective tool by combining these above tools togather.
    The operations that can be performed are read, write, convert etc for excel. The major attraction of Jexcel is excel to xml conversion.
    Regards,
    Nishant Kulkarni
    Software Engineer
    [email protected]

  • Generating excel files using XSLT mapping

    Hi All,
    I am working on a proxy to file scenario and we have a requirement of generating .xls file in a spreadsheet format at FTP server.I have done xslt mappping for creating the excel file in spreadsheet.But getting following error in channel monitoring.
    Message processing failed. Cause: com.sap.engine.interfaces.messaging.api.exception.MessagingException: Error occurred while connecting to the FTP server "phmysa-s3006.ap.novartis.net:21": java.lang.Exception: Exception in XML Parser (format problem?):'java.lang.Exception: Message processing failed in XML parser: 'Conversion configuration error: Unknown structure 'Workbook' found in document', probably configuration error in file adapter (XML parser error)'
    XSLT Code Used:
    <?xml version='1.0' ?>
    <?mso-application progid="Excel.Sheet"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns="urn:schemas-microsoft-com:office:spreadsheet"
    xmlns:o="urn:schemas-microsoft-com:office:office"
    xmlns:x="urn:schemas-microsoft-com:office:excel"
    xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"
    xmlns:html="http://www.w3.org/TR/REC-html40">
    <xsl:template match="DT_StockReports/*">
    <Row>
    <Cell>
    <Data ss:Type="String">
    <xsl:apply-templates/>
    </Data>
    </Cell>
    </Row>                               
    </xsl:template>
    <xsl:template match="/">
    <Workbook>
    <DocumentProperties xmlns="urn:schemas-microsoft-com:office:office">
    </DocumentProperties>
    <ExcelWorkbook xmlns="urn:schemas-microsoft-com:office:excel">
      <WindowHeight>10365</WindowHeight>
      <WindowWidth>13260</WindowWidth>
      <WindowTopX>120</WindowTopX>
      <WindowTopY>60</WindowTopY>
      <ProtectStructure>False</ProtectStructure>
      <ProtectWindows>False</ProtectWindows>
    </ExcelWorkbook>
    <Styles>
      <Style ss:ID="Default" ss:Name="Normal">
       <Alignment ss:Vertical="Bottom"/>
       <Borders/>
       <Font x:CharSet="512"/>
       <Interior/>
       <NumberFormat/>
       <Protection/>
      </Style>
    </Styles>
    <Worksheet ss:Name="">
      <Table ss:ExpandedColumnCount="40" ss:ExpandedRowCount="15000" x:FullColumns="40"
       x:FullRows="15000">
    <xsl:apply-templates/>
      </Table>
      <WorksheetOptions xmlns="urn:schemas-microsoft-com:office:excel">
       <PageSetup>
        <PageMargins x:Bottom="0.984251969" x:Left="0.78740157499999996"
         x:Right="0.78740157499999996" x:Top="0.984251969"/>
       </PageSetup>
       <Selected/>
       <Panes>
        <Pane>
         <Number>40</Number>
         <ActiveRow>40</ActiveRow>
         <ActiveCol>15000</ActiveCol>
        </Pane>
       </Panes>
       <ProtectObjects>False</ProtectObjects>
       <ProtectScenarios>False</ProtectScenarios>
      </WorksheetOptions>
    </Worksheet>
    </Workbook>
    </xsl:template>
    </xsl:stylesheet>
    Thanks
    Ayura

    Input xml:
    <?xml version="1.0" encoding="utf-8"?><n0:MT_StockReports xmlns:n0="urn:novartis.com:pi:ph:sp:LM_DD_501_LSP_L0X:StockReports" xmlns:prx="urn:sap.com:proxy:Q75:/1SAI/TASEF7C5F005BC07ECC0997:700:2008/06/25"><Header><Material></Material><MaterialDescription></MaterialDescription><MType></MType><Bin></Bin><Unit></Unit><MS></MS><LS></LS><Type></Type><PGr></PGr><ABC></ABC><Crcy></Crcy><Prc></Prc><Vendor></Vendor><VendorName></VendorName><VendMat></VendMat><ManufacturingPartN></ManufacturingPartN><Batch></Batch><BatchExpiryDate></BatchExpiryDate><Unrestr></Unrestr><SafetyStk></SafetyStk><MinSafStck></MinSafStck><MinLotSize></MinLotSize><MaxLotSize></MaxLotSize><MaxLevel></MaxLevel><ReorderPt></ReorderPt><TotalStock></TotalStock><TotalVal></TotalVal></Header><Records><Material>20001</Material><MaterialDescription>SIEVED NATEGLINIDE / DS.01 / DR</MaterialDescription><MType>ZPI</MType><Bin></Bin><Unit>KG</Unit><MS>40</MS><LS>HB</LS><Type>M0</Type><PGr>S01</PGr><ABC></ABC><Crcy>SGD</Crcy><Prc>S</Prc><Vendor>          </Vendor><VendorName></VendorName><VendMat></VendMat><ManufacturingPartN></ManufacturingPartN><Batch>SD0026</Batch><BatchExpiryDate>01.12.2011</BatchExpiryDate><Unrestr>49.803 </Unrestr><SafetyStk>0.000 </SafetyStk><MinSafStck>0.000 </MinSafStck><MinLotSize>110.000 </MinLotSize><MaxLotSize>550.000 </MaxLotSize><MaxLevel>1.000 </MaxLevel><ReorderPt>0.000 </ReorderPt><TotalStock>49.803 </TotalStock><TotalVal>1723.18 </TotalVal></Records></n0:MT_StockReports>
    Edited by: Ayura Kanungo on Dec 28, 2011 7:11 AM

  • How to generate excel file in oracle forms 10g on client machine

    dear Sir,
    I am using just file server(installed 10g dev suite) not a oracle application server,
    I am running my application from another machine ,it running fine i want to generate excel report on client machine
    presently i m using OLE2 for fetching the data in excel , it is working fine but it generates the excel file on file server machine and i want get the output excel on the client machine. aftre OLE2 i m using CLIENT_OLE2 with webutil (instead of OLE2) its get compile successfully but during runtime it give error "oracle.forms.webutil.ole.OleFunctions bean not "found.CLIENT_OLE2.create_obj will not work"
    *so please tell me without oracle application server is this possible or not .*

    your webutil on server side is not configured
    you need to re install the webutil jacob.dll files etc. then it will work fine..
    you can also generate excel file using reports to change the destination format in SPREADSHEET

  • How to generate excel file as output using OWB

    Hi,
    I have a requirement to generate an excel file as output using OWB.
    I am trying for a direct approach to create excel files.
    Though I know that excel can be created from a .csv file, I am looking for a direct approach to generate excel file without involving any .csv to excel conversion externally.
    Regards,
    Sri

    so, we are trying to do it by the help of oracle heterogeneous services. In my opinion it is possible (it depends on feature of ODCB Excel driver)
    For more details look at thread (it is about MS SQL Server but maybe it helps)
    Oracle to SQL SERVER
    Regards,
    Oleg

  • Uses the library to get UTL_FILE to read a excel file in PL SQL?

    Good day.
    Someone can give me some code that uses the library to get UTL_FILE to read a excel file in PL SQL?
    I intend to use this library because I want to run a script on my machine to treat an excel file without having to make changes on the server.
    Thank you.

    163d6dc5-fa66-4eb1-b7d5-653dea63bbc8 wrote:
    Good day.
    Someone can give me some code that uses the library to get UTL_FILE to read a excel file in PL SQL?
    I intend to use this library because I want to run a script on my machine to treat an excel file without having to make changes on the server.
    Thank you.
    Ranit's links are useful, you should read them.
    Also check out the FAQ on this forum:Re: 5. How do I read or write an Excel file?
    UTL_FILE is not the best choice for reading data from Excel files.
    It also will not be able to read an Excel file located on your client computer.  As with any PL/SQL code on the database, it can only access things that the server itself can see, so that doesn't include hacking across the network, bypassing network security, and hacking into the client computers operating system to read files directly from it's hard disk.  This isn't how client server architecture is intended to work.

  • Generating Excell Sheet using Reports 9i

    Hello,
    I wanna know how can I do to generate one excell sheet using reports, without
    use the option that4s generate text file using tab. I wanna know if someone have
    example codes, or library4s.
    Thanks,
    Paulo Sergio

    Here are some notes we created from the demo below. This works great for generating true formated excel output in 9i Reports using 9ias Rel2.
    Notes from
    http://otn.oracle.com/products/reports/htdocs/getstart/demonstrations/index.html
    Output to Excel with Oracle9i Report
    1.     Create an Excel template for the report. It should contain generic information such as title, logo and column headers
    2.     Cretae a sample line of data in the spreadsheet
    3.     Save the Excel spreadsheet as a Web page. File | Save As Web Page
    4.     Open the Web page you just created in Reports Builder
    5.     Double-click on Web Source node to display the HTML code for the Excel spreadsheet
    6.     Note how Excel generated HTML and XML code for the spreadsheet you created. Reports Builder also adds its own JSP tags
    7.     Add the Data Source An SQL Query
    8.     Modify the Web Source. Now that youve written the query, you can modify the Web source to tell Reports Builder to display your report in Excel.
    9.     Click on the Web Source icon in the toolbar.
    10.     To force the browser to open MS Excel it is necessary to change the HTTP Content Type to a specific MIME Type:
    application/vnd.ms-excel
         Insert the following line immediately before the <rw:report id=report> tag
              <%@ page contentType=application/vnd.ms-excel %>
         (This is a standard JSP directive to set a MIME Type (Content Type) )
    11.     To respect Excel format, you should delete the blank lines above the <html> tag.
    12.     Now, use Oracle 9i Reports JSP tags to add the data retrieved by your SQL Query to the report.
    13.     Search for the sample line of data you added to your Excel spreadsheet
    14.     Each line is saved as an HTML Table Row tag ( <tr> ).
    15.     Each column is mapped as an HTML Table Data tag ( <td> ).
    16.     Using Reports JSP Tags, add a Reports repeating frame tag to loop around the Data Model group.
    17.     To help, show the Object navigator next to the Web Source Window. All group information is now visible in the Object Navigator
    18.     Enclose the sample line of code in the Web source with the Reports9i JSP repeating tag.
    Use from menu Insert | Repeating Frame at beginning of sample
    Move the closing repeating tag after the </tr> tag.
    Start of the repeating tag would be
    <rw:foreach id=foreach src=>
    Ending of the repeating frame would be
    </rw:foreach>
    19.     In the opening of the repeating tag (<for each>), add the name of the group the tags enclose. JSP custom tags require a unique identifier.
    For example: <rw:foreach id=gEmpNoId src=G_EMPNO>
    20.     Now, map the cells of the Excel spreadsheet to the corresponding field from your data model.
    Select on the data value. From menu select Insert | Field. The source of the tag is the name of the field in the query.
    21.     Repeat the operation for each field of the report. Note: do not forget to specify a unique identifier for each field.
    22.     The code now contains a repeating frame. You have also mapped each cell in the Excel spreadsheet to the corresponding field in the data model
    23.     Save the report as a Reports JSP. You can test the report using the Run Web Layout icon in the toolbar
    24.     The execution of a Web Layout report from Reports Builder creates a temporary HTML file and launches the browser. The browser does not launch Excel because the document is saved as an HTML file. To launch Excel from the browser you need to test it from Reports Server.
    25.     In order to have the report appear inside Excel, you need to execute it with the Reports Server under OC4J. To do this you need to:
    First, start an OC4J instance from Oracle 9iDS see How to Execute Reports Services from Oracle 9iDS on OTN. Then, copy the JSP to a directory. For example: $IDS_HOME/reports/j2ee/reports_ids/web/test
    26.     Enter the URL to execute the jsp. The JSP is executed from an OC4J instance.
    http://reports9iTestServer:8888/reports/test/ListOfEmployees.jsp?userid=scott/tiger@ora901
    27. The browser launches Microsoft Excel and displays the data from your report.

  • Creation of Excel files using XSLT

    Hi frnds,
    From the blog provided by the Michal
    /people/michal.krawczyk2/blog/2005/12/10/xi-generating-excel-files-without-the-java-nor-the-conversion-agent-not-possible
    I came to know that we can create excel files using XSLT mapping but here inthis blog the example provides creation of only one column but I have a scenario where in I want 3 columns ex:Name,Age,***
    Shiva 26 Male
    Ravi   25 Male
    Rani   24 Female
    but using the code provided in Michal blog Im getting the output as
    Shiva
    26
    Male
    Ravi
    25
    Male
    Rani
    24
    Female
    Can anyone help me in modifying the code given in Michal blog to get the output as required.
    Please share your ideas or suggestion onthis...
    Thanks in advance,
    Shiva.

    Please change the code as
    <xsl:template match="file_SDN/recordset/data/*">
    <Row>
    <Cell>
    <Name ss:Type="String">
    <xsl:apply-templates/>
    </Name>
    <Age ss:Type="Integer">
    <xsl:apply-templates/>
    </Age>
    <*** ss:Type="String">
    <xsl:apply-templates/>
    </***>
    </Cell>
    </Row>          
    </xsl:template>

  • How to Downlaod a Excel file using FTP- -JSP

    Hi..i am dynamically generating excel file(i.e...writing into the excel file from Acees databse after executing the queries on it)...i have set the content-type to vnd-msexcel ....now i want that file to be downlaoded using FTP...FTP is new to me...any help could be greatly appreciated...
    Thanks in advance....

    JavaWorld published an article about this topic. It is called "Java FTP client libraries reviewed" and it can be found here :
    http://www.javaworld.com/javaworld/jw-04-2003/jw-0404-ftp.html
    Best regards
    Jean-Pierre Norguet
    Jean-Pierre Norguet
    JavaWorld Press
    http://wasa.ulb.ac.be/jp.html

  • Generating Text files from PL/SQL

    To generate Text files from PL/SQL on SERVER, i can use UTL_FILE
    package, but how do i create text files on client ( i.e., on the
    C: drive ) by executing anonymous PL/SQL blocks.
    Thanks in advance.

    You can use DBMS_OUTPUT to display stuff to the screen and the
    SQL*Plus SPOOL command to write screen output to a file on your
    local drive.
    magic!
    APC

  • Not able to generate excel file locally

    Hi guys,
    My web server & database server are on 2 different systems. I am trying to generate excel file locally but the excel is getting generated on server. Output path is
        c:\\" + output + ".xls
       There is no problem anywhere else in code. If a user on any system is trying to generate excel file it's getting
    generated on server in C drive. But the excel should generate on local system of that particular user.
    Is this code fine?
    \\c:\\" + output + ".xls

    wickedrahul9 wrote:
    It's on intranet, so security is not an issue.Yes, it is. Because of the inherent security problems, servers just plain can't do that. Do you think there's an "I'm running in an intranet" flag in your server? If there was, then bad guys would just set that flag on and write malware to any client that connected. Intranets aren't an excuse for sloppy security.
    Do I need to download the file from server?That's what I said.

  • Loading the data from a packed decimal format file using a sql*loader.

    Hi ,
    In one of the project i'm working here i have to load the data into oracle table from a file using a Sql*loader but the problem is the data file is in the packed decimal format so please let me know if there is any way to do this....I search a lot regarding this ..If anybody faced such type of problem ,then let me the steps to solve this.
    Thanks in advance ,
    Narasingarao.

    declare
    f utl_file.file_type;
    s1 varchar2(200);
    s2 varchar2(200);
    s3 varchar2(200);
    c number := 0;
    begin
    f := utl_file.fopen('TRY','sample1.txt','R');
    utl_file.get_line(f,s1);
    utl_file.get_line(f,s2);
    utl_file.get_line(f,s3);
    insert into sampletable (a,b,c) values (s1,s2,s3);
    c := c + 1;
    utl_file.fclose(f);
    exception
    when NO_DATA_FOUND then
    if utl_file.is_open(f) then utl_file.fclose(f); ens if;
    dbms_output.put_line('No. of rows inserted : ' || c);
    end;SY.

Maybe you are looking for

  • Intrastat reporting

    Hi, We have a issue in intrastat reporting for GB. we have 1 PO for which we did the following 1. GR in month of July , 101 movement 2.  reversal in month of sep ; 101 Movement 3. GR in month of Sep ; 101 movement 4. Invoice posted in month of Sep .

  • Web Filtering, Anti-Spyware and Email Filtering in one?

    We have 4 Cisco ASA firewalls in place and currently use iMail and ISA server to filter web traffic and mail. I'm investigating any solutions that would interoperate well with Cisco ASAs and provide a central solution for the above needs. Has anyone

  • I'm not able to access the thumbnails of my open web pages. Why?

    I'm not able to access the thumbnails of my open web pages. Why?

  • How to reveal vectors in PDF file.

    I've got a PDF file composed entirely of vector paths. Since the image was too large for the screen the document was saved as an 8.5x11" file, even though the remaining parts of the image are there. However, I can't seem to reveal them by deleting th

  • End user migration

    I am moving from a be5k to a be6k I am also going from non LDAP to LDAP integration The end users IDs in the current Be5k environment match the userId as defined on on LDAP My question is what is the best way to accomplish this with the least amount