Skip to Main Content

Oracle Forms

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Form records exported to Excel

Wampa88Feb 9 2010 — edited Feb 11 2010
I have a form that shows all the results from a search screen. I created a push button that I want to export the form data to excel. Ive included the trigger and function I wrote. An xls file is created but it is empty. Any ideas.

------------------------------
TRIGGER CODE
-----------------------------

declare
v_dummy number;
v_where_clause varchar2(1000);
v_button number;
n_button number;
v_forms_output varchar2(100) := null;
v_forms_mapping varchar2(100) := null;
file_id number;
mimetype varchar2(255) := '&mimetype=application/vnd.ms-excel';

begin
select seq_program_remarks.nextval
into file_id
from dual;
:global.filename := 'nrhrdata_'||to_char(file_id)||'.xls';
tool_env.getvar('FORMS_OUTPUT',v_forms_output);
tool_env.getvar('FORMS_MAPPING',v_forms_mapping);
:global.virtual_path := v_forms_mapping||'/'||:GLOBAL.FILENAME;
:global.text_output_file := v_forms_output||'\'||:GLOBAL.FILENAME;
--v_where_clause := create_where_clause;
:Global.BUFFER_PART := :SEARCH.NRHR_PART;

--SET_BLOCK_PROPERTY('NRHR',DEFAULT_WHERE,v_where_clause);
SET_BLOCK_PROPERTY( 'NRHR', ONETIME_WHERE, 'NRHR.PART_NUMBER = ''' || :Global.BUFFER_PART ||'''');
go_block('NRHR');
execute_query;
set_application_property(cursor_style,'BUSY');
v_dummy := dump_data('NRHR',:global.text_output_file);
set_application_property(cursor_style,'DEFAULT');

if v_dummy = 0 then
go_item('control.exit_button');
synchronize;

set_alert_property('write_complete_alert',alert_message_text,
'File "' || :global.filename ||
'" was sucessfully written to disk.');

v_button := show_alert('write_complete_alert');

web.show_document(:global.virtual_path, '_BLANK');

else
set_alert_property('write_failed_alert',alert_message_text,
'An error occured while writing file "' ||
:global.filename ||
'" to disk.');
v_button := show_alert('write_failed_alert');
end if;


end;

------------------------------------------------------
FUNCTION CODE
------------------------------------------------------

function dump_data (block_name in varchar2,
output_file in varchar2 := 'data_dump.xls')
return number
is
item_id item;
v_item_name varchar2(80);
item_type varchar2(40);
block_id block;
file_id text_io.file_type;
start_rec number;
stop_rec number;
pad_length number;
item_disp varchar2(20);
item_align varchar2(20);
item_value varchar2(32767);
skip_this_item exception;
item_count number := 0;
column_align boolean := TRUE;
v_field_select varchar2(80);
v_item_label varchar2(50);
begin
block_id := find_block(block_name);
file_id := text_io.fopen(output_file, 'w');

go_block(block_name);
start_rec := 1;
last_record;
stop_rec := get_block_property(block_id, query_hits);

go_record(start_rec);
--
-- Print Column Headings
--
item_count := 0;
v_item_label := get_block_property(block_id, first_item);
v_item_name := block_name||'.'||v_item_label;
item_id := find_item(v_item_name);
while v_item_label is not null loop
v_field_select := 'NRHR.'||get_item_property(item_id,item_name);
if (name_in(v_field_select) = 'Y') then
if item_count > 0 then
text_io.put(file_id, chr(9));
end if;
text_io.put(file_id, v_item_label);
item_count := item_count + 1;
end if;
v_item_label := get_item_property(item_id, nextitem);
if v_item_label is null then
text_io.new_line(file_id, 1);
else
v_item_name := block_name||'.'||v_item_label;
item_id := find_item(v_item_name);
end if;
end loop;
--
-- End Print Column Headings
--
for i in start_rec..stop_rec loop
item_count := 0;
v_item_name := block_name || '.' || get_block_property(block_id, first_item);
item_id := find_item(v_item_name);

while v_item_name is not null loop
pad_length := get_item_property(item_id, max_length);
item_disp := get_item_property(item_id, displayed);
item_type := get_item_property(item_id, datatype);
item_align := get_item_property(item_id, alignment);
v_field_select := 'NRHR.'||get_item_property(item_id,item_name);
if (name_in(v_field_select) = 'Y') then

if not(FALSE and item_disp = 'FALSE') then

if column_align = TRUE then
item_value := nvl(name_in(v_item_name),' ');

if item_align in ('START', 'LEFT', 'CENTER') then
item_value := rpad(item_value,pad_length,' ');
else
item_value := lpad(item_value,pad_length,' ');
end if;
else
item_value := name_in(v_item_name);
end if;

if item_count > 0 then
text_io.put(file_id, chr(9));
end if;

text_io.put(file_id, rtrim(replace(item_value,chr(10),' ')));
item_count := item_count + 1;
end if;
end if;

v_item_name := get_item_property(item_id, nextitem);

if v_item_name is not null then
v_item_name := block_name || '.' || v_item_name;
item_id := find_item(v_item_name);
else
text_io.new_line(file_id, 1);
end if;

end loop;

next_record;
end loop;

first_record;
text_io.fclose(file_id);
return(0);

exception
when others then
return(-1);
end dump_data;

Edited by: Wampa88 on Feb 9, 2010 7:24 AM
This post has been answered by CraigB on Feb 9 2010
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 11 2010
Added on Feb 9 2010
12 comments
2,663 views