none
Using Word Document Templates from Oracle database RRS feed

  • Question

  • I have received a school project; where I get a lot of 2003 - 2007 word template documents. 1. I need to upload these templates to database. 2. Allow user to either view a word document created using the template mergefields filled with information extracted from database or print the document directly to printer without viewing. My target platform is C# framework 4.0; can install word on the server.

    I can upload to Oracle CLOB but facing challange when trying to parse the template back; Can I process the template in memory or is it required to save the data as template again and then perform merge fields; create/save final document. Can i just print document from memory if user does not want to view.

    New to this aspect of programming, see a lot of comments about word automation and open XML. Any comments are appreciated

    Friday, July 27, 2012 8:01 PM

Answers

  • HI Atima

    If Word 2003 files are involved, and these are *.doc files, then you cannot use OpenXML, although that would be ideal for your task.

    It's unlikely that anyone here will be able to help you with the ORacle side of the equation, but on the Word side we may be able to provide some information.

    <<Can I process the template in memory or is it required to save the data as template again and then perform merge fields; create/save final document. Can i just print document from memory if user does not want to view.>>

    If you cannot work with the Open XML file format, then you have absolutely no option to do anything in memory - it would all have to be over the "Interop", meaning Word has to be run. In order to create a merge document result from the templates, the template must first be saved to disk, a new document created from it (using the Word.Interop Documents.Add method), this linked to the desired data source (OpenDataSource method), the merge executed and the document printed.

    The only way around this I can see would be IF your project environment would include a version of SharePoint that supports Word Automation Services. With Word Automation Services you can process a set of documents and have them "Save As" to a new location and/or file format. In essence, what I'm saying is that you can use it to convert *.doc to *.docx. Then you have the option of working with Open XML and being able to do the merge in memory.

    Another option, although I suspect your school project might not allow it, would be to purchase a third-party tool that can convert *.doc to *.docx.


    Cindy Meister, VSTO/Word MVP

    Saturday, July 28, 2012 1:27 PM
    Moderator

All replies

  • HI Atima

    If Word 2003 files are involved, and these are *.doc files, then you cannot use OpenXML, although that would be ideal for your task.

    It's unlikely that anyone here will be able to help you with the ORacle side of the equation, but on the Word side we may be able to provide some information.

    <<Can I process the template in memory or is it required to save the data as template again and then perform merge fields; create/save final document. Can i just print document from memory if user does not want to view.>>

    If you cannot work with the Open XML file format, then you have absolutely no option to do anything in memory - it would all have to be over the "Interop", meaning Word has to be run. In order to create a merge document result from the templates, the template must first be saved to disk, a new document created from it (using the Word.Interop Documents.Add method), this linked to the desired data source (OpenDataSource method), the merge executed and the document printed.

    The only way around this I can see would be IF your project environment would include a version of SharePoint that supports Word Automation Services. With Word Automation Services you can process a set of documents and have them "Save As" to a new location and/or file format. In essence, what I'm saying is that you can use it to convert *.doc to *.docx. Then you have the option of working with Open XML and being able to do the merge in memory.

    Another option, although I suspect your school project might not allow it, would be to purchase a third-party tool that can convert *.doc to *.docx.


    Cindy Meister, VSTO/Word MVP

    Saturday, July 28, 2012 1:27 PM
    Moderator
  • Thanks. Your explanations were very helpful in outlining my options.

     I found aspose components. How does it work even without having word on the server or openXML.. for now interop may be my choice.

    Monday, July 30, 2012 8:58 PM
  • Hi, you can do this using Invantive Composition to upload templates and merge database info (but requires I think framework 4.5 nowadays). It just requires the SQL or objects in C# on an IIS server. The rest is done through specifying what you need instead of coding. Note that I work there at this moment.

    If you manually create coding for it (which can be cheaper when there are only a few template documents), please note that you must upload to a BLOB or BFILE. CLOB is charactersonly. You can use CLOB when you store the XML or RTF, but please check that your database character set handles all characters found and with the correct conversion. For instance, I have had once a sleepless night after loading Hungarian names as binary data into a text column only to find out that from other parts of Europe the names now looked totally wrong.

    If you want to code it manually, please choose an application development platform that Microsoft supports in the long run. At this time, I would go for Microsoft .NET and add-ins. But that leaves out Office 2003 users (I don't know whether it are only Word 2003 template documents you need to fill or whether there are still Office 2003 installations floating around).

    To help you better, please put the number of templates in your reply as well as the software versions in use (Microsoft Word, Oracle, ODP.NET or ODBC driver). Good luck!

     


    • Edited by Guido Leenders Thursday, October 24, 2013 8:58 AM forgot disclaimer
    Thursday, October 24, 2013 8:57 AM