tags:

views:

446

answers:

1

Hello,

I need to generate a ms-word document from a pl/sql query to export a set of reports through a web browser.

I have been searching for a specific way to modify the content headers using owa_util.mime_header etc etc but could not really get a working proof of concept to get the web page to present the user to download/open/save a ms-word document.

I know it's not much but..

   begin
    OWA_UTIL.MIME_HEADER ( 'application/vnd.ms-word', false);
    htp.print('Content-Disposition:attachment;filename="test.doc"');
    OWA_UTIL.HTTP_HEADER_CLOSE;
        for x in (select first_column, second_column from my_table)
            loop
                htp.p(x.first_column||'<br/>'||x.second_column||'<br/><br/>');
            end loop;
    end;

Could someone please shed some light on how can I create a procedure that generates output to html which intercept the browser headers and prints out the query content to a word document?

By the way, the current environment (restriction) I am running this from: Oracle APEX 3.0.1 (not 3.1, which I believe has an export to word doc feature).

Thanks in advance.

+2  A: 

In Apex you can make a page that is completely generated from a procedure of your making:

  1. Create a blank page.
  2. Under Processes, click Create, and choose PL/SQL.
  3. Give it a name, and leave the default option "On Load - Before Header".
  4. For PL/SQL Page Process, enter the following:

    BEGIN
       myprocedure;
       htmldb_application.g_unrecoverable_error := true;
    END;
    
  5. Create your procedure (the code you have should work ok) and it should work fine.

EDIT: the code in "myprocedure" should emit HTML code, including the HTML and BODY tags.

Jeffrey Kemp
Hi Jeffrey,It worked beautifully and I managed to get the desired output (user was prompted to download the .doc file).However, I seem to get my encoding totally wrong. When I open the word document (or change it to a .rtf file), it seems that it cannot recognize the content and asks me how should I encode it. Once I select the encoding (e.g. UTF-8), the file opens and the content is displayed correctly.This is my code:(cont'd)
N2EE
beginOWA_UTIL.MIME_HEADER ( 'Content-Type:application/vnd.ms-word;charset=utf-8', false); htp.print('Content-Disposition:attachment;filename="test.doc"'); OWA_UTIL.HTTP_HEADER_CLOSE; for x in (select column_one, column_two from my_table) loop htp.p(x.column_one ||chr(10)||x.column_two ||chr(10)||chr(10)); end loop;htmldb_application.g_unrecoverable_error := true;end;....Any idea where I can change the mime_header to open the file seamlessly?Many thanks
N2EE
You'll probably find it will work if you send HTML syntax as the data. e.g. `begin OWA_UTIL.MIME_HEADER ( 'Content-Type:application/vnd.ms-word;charset=utf-8', false); htp.print('Content-Disposition:attachment;filename="test.doc"'); OWA_UTIL.HTTP_HEADER_CLOSE; htp.p('<html><body>'); for x in (select column_one, column_two from my_table) loop htp.p(x.column_one ||'<br>'||x.column_two ||'<br><br>'); end loop; htp.p('</body></html>'); htmldb_application.g_unrecoverable_error := true; end;`
Jeffrey Kemp
That did it.Thank you!
N2EE