10 Replies Latest reply on Feb 5, 2007 7:33 PM by 50108

    Writing MS Word Document from PL/SQL


      I have an application which writes the data into EXCEL from PL/SQL. I am using follwong code to write the data.
      Owa_Util.Mime_Header ( 'application/vnd.ms-excel', False);

      I want to know if there is any option to write the data into MS Word. If i am changing the Mime type to ms-word its generating a word document with the HTML equivalent of data. Looking forward for a quicked response.

        • 1. Re: Writing MS Word Document from PL/SQL
          I assume you send data to client in the CSV Format and associate with MS Excel.

          Same way, dump your data as XML or RTF and associate with MS Word.
          • 2. Re: Writing MS Word Document from PL/SQL
            Well whatever code i have written is used to dump the data into Excel. But when i change the mime type to ms-word and try to dump that data it gives me the Html code of the page instead of the layout and the data. If i tries to download it into PDF file by changing the MIME type it downloads the file but when opened there is an error message like "File is corrupted". Plz let me know how i can either download into Word or PDF.

            • 3. Re: Writing MS Word Document from PL/SQL
              I won't advice you lots of readings, although you definatelly need to learn/understand HTTP headers, file types, file formats, Oracle Web Utilities ... etc. And your question has nothing do with PL/SQL. I do not have enough time to explain in detail, however this is workaround;
              change <html> tag of the page that you associate with MS Word with;

              <html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns="http://www.w3.org/TR/REC-html40">

              and add

              <meta name=ProgId content=Word.Document>

              to head section of the HTML

              This will help. Good luck.
              • 4. Re: Writing MS Word Document from PL/SQL
                Well the problem is rectified. We can change the Mime_Header itself to MS-Word.

                Owa_Util.Mime_Header ( 'application/vnd.ms-word', False);

                Now the problem is i dont want the user to see the Save dialog box for the file. Instead the application should be able to write the file to C:\Temp folder. Is there anyway to save files to the hard-disk without prompting. Have tried lots of options but its not working. Please help.
                • 5. Re: Writing MS Word Document from PL/SQL
                  A Signed Applet can do it.
                  • 6. Re: Writing MS Word Document from PL/SQL
                    Yeah i know it can be done by a signed applet or an servlet. But Kivanc i want to know if there is anyway to do this with PL/SQL Cartridges or any other Oracle Utilities like (OWA_UTIL, UTL_FILE etc.. ) or with JS.
                    • 7. Re: Writing MS Word Document from PL/SQL
                      Due to security restrictions on the browsers, you cannot do it with any kind of server side codes (including servlets). Although you use signed applet, you may need to change security policies on client side and overwrite some methods in Java sandbox.

                      Imagine that if it would be that easy, you couldn't even surf on the net; all bad minded people could write codes which write malicious executables to your OS.
                      • 8. Re: Writing MS Word Document from PL/SQL
                        Well Kivanc i agree with your words. But ultimately that does not solve my problem man. In my application i dont think i can use signed applet. Thats why i would like to know if there is any other alternatives to dump the data in OS.
                        • 9. Re: Writing MS Word Document from PL/SQL
                          I think I answered your question; there is no other alternative way; you can whether use Signed Applet or ActiveX component...

                          If you can find another way, do not post here and do not tell anyone. I hope you understand what i mean ;-)
                          • 10. Re: Writing MS Word Document from PL/SQL
                            I am not sure if you ever got your problem resolved, but I just wanted to share my experience that is is possible to have "server" side code which will get document in Oracle or another Doc. management syste, stream it back to the client and open it (I am talking about MS Office documents) in Office application or actually inside the browser (there is a little trick with the client Windows Explorer settings to enable this, otherwise it will open as an application).

                            It works perfectly also for TXT files, .TIFF, .jpg , .PDF etc.

                            You have to be correctly setting the MIME type depending on type of the application the files was created by (I can see you are doing that);

                            BUT your following line :
                            ==> is telling the client's browser that the file is coming over as attachment and therefore it will always prompt the user with OPEN, SAVE, CANCEL.

                            Here is a snippet of my code example [ writting the file into local temp dir]:
                            Response.AppendHeader("ContentEncoding", ctype);

                            // set the final Content Type
                            Response.ContentType = ctype;
                            // stream and write the file out