11 Replies Latest reply: Jan 3, 2013 11:56 PM by Billy~Verreynne RSS

    Write to word document from oracle plsql

    Divs
      Hi,
      Please provide methods to create and write to a word document from ORACLE PLSQL.We tried using UTL FILE package but it writes as ascii text.
        • 1. Re: Write to word document from oracle plsql
          sb92075
          Please provide methods to create and write to a word document from ORACLE PLSQL.
          This request makes no sense.
          Invoke MS Word & compose the document.
          • 2. Re: Write to word document from oracle plsql
            Hoek
            Welcome to the forum.

            Word is a proprietary format.
            But you might want to explore:
            http://download.oracle.com/docs/cd/B19306_01/win.102/b14310/ch5java.htm#COMDG006
            • 3. Re: Write to word document from oracle plsql
              Divs
              How to invoke Ms word and write in to it from plsql
              • 4. Re: Write to word document from oracle plsql
                William Robertson
                If this is an Oracle Forms or Apex question, you might have a chance. Core PL/SQL cannot do this however.

                You might have more luck aiming for .docx XML format, as this can be constructed using tagged ASCI text.
                • 5. Re: Write to word document from oracle plsql
                  Saubhik
                  You can use COM automation to write to Excel/Word document. Provided your database servser's operating System is WIN*. See this example for Excel.
                  SQL and PL/SQL FAQ

                  If you can't make it for MS Word. Let me know, I'll try to produce a package for MS Word. But do not forget to read details about implementation about COM in PL/SQL.
                  • 6. Re: Write to word document from oracle plsql
                    Divs
                    The server m/c operating system is unix.so we need to invoke the procedure from Unix Os.
                    • 7. Re: Write to word document from oracle plsql
                      Billy~Verreynne
                      Divs wrote:
                      The server m/c operating system is unix.so we need to invoke the procedure from Unix Os.
                      In that case - not possible. For Windows COM (Component Object Model) to work, Oracle database need to be able to call and load the COM dynamic link libraries.

                      Not to say that it is not possible. Have never used DCOM (the Distributed COM interface), and not exactly sure what it requires. Assuming that DCOM is not usable from a Linux perspective, you can still provide a manual interface. You create a NT tcp/ip service that exposes the COM interface calls that you need - in a secure fashion (even better - you can provide a higher level abstraction layer for the COM interface that does the specific job you need to be done).

                      From Oracle you can then use PL/SQL's UTL_TCP package to open a connection to it and via this service craft a Word document on that Windows server.

                      Are there web services for MS Office? I know Google is pushing that aspect hard (and embroiled in lawsuits with the US government and Microsoft about tender awards in this aspect). Now if Microsoft has "+office-on-the-web+", then one can create a Word document via a web browser. This means that there is an underlying web service - and that this can be called and used. The Evolution (Open Source Mail Reader) project for example uses the MS Exchange web service interface to provide a seamless interface to Exchange mail accounts (have used this everyday for a number of years now).

                      The real question I would however ask is why Word specifically? Why not a more common format like PDF? You can even consider generating XML instead. Both Microsoft and Open Office and others are supporting XML formatted word processing documents (as oppose to older proprietary and binary formats).

                      And why not use a Report Writer? I'm a big fan of doing as much as possible in Oracle (using PL/SQL most of the time). But certain things, like generating Word-style documents would be better done (and more flexible too) using a Report Writer.
                      • 8. Re: Write to word document from oracle plsql
                        BluShadow
                        Divs wrote:
                        The server m/c operating system is unix.so we need to invoke the procedure from Unix Os.
                        Let's put this simply...

                        Do you have MS Word installed on your Unix server? I very much doubt it.

                        How do you expect a database process (PL/SQL) that is running on the unix server to run MS Word on that Unix server?
                        Or perhaps you are expecting your database server to breach all security measures, break into some users client PC, take control of the Windows operating system, run Word up on that clients computer and be able to write data to that computers hard disk? It's not going to happen.
                        • 9. Re: Write to word document from oracle plsql
                          MichaelS
                          Please provide methods to create and write to a word document from ORACLE PLSQL
                          If its just about formatting you could equally well generate RTF's from within a java stored procedure:
                          You might load the free iText library into the database and generate a rtf as described e.g in Generate RTF Word Documents Using a Java Application.

                          You might even give the document a .doc extension ;- )
                          • 10. Re: Write to word document from oracle plsql
                            Jonathan-P
                            Yo lo hago asi:

                            declare
                            v_archivo utl_file.file_type;
                            begin
                            v_archivo := utl_file.fopen ('DIR_DOCS', 'test_utl_file.doc', 'w');

                            utl_file.put_line (v_archivo, '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
                            <html xmlns="http://www.w3.org/1999/xhtml">
                            <head>
                            <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
                            <title>Documento sin título</title>
                            </head>

                            <body>
                            archivo word
                            </body>
                            </html>');

                            utl_file.fclose(v_archivo);
                            end;
                            /
                            • 11. Re: Write to word document from oracle plsql
                              Billy~Verreynne
                              Sheez... not only is your solution idiotic (it writes HTML and not Microsoft Word format), you are resurrecting a dead thread that was posted and dealt with years ago.

                              Please cease resurrecting dead threads.

                              And consider actually READING AND UNDERSTANDING the questions and issues, before posting a "solution" that is not relevant to the discussion.