5 Replies Latest reply on May 20, 2019 11:43 AM by db12345

    Using Webutil to create Word Document in DOCX format.

    db12345

      Hi All,

       

      I use Jacob/Webutil to create Word documents and it works fine for .rtf and .doc extensions, but when trying to use .docx, the SaveAs invokes the following exception: Incompatible file type and file extension.

       

      Is there a file property or format that needs to be set before invoking the save that will allow it to save successfully.

       

      Below is a snippet of the code being used. This is on Forms 12.2.1.3 running on Windows 7.

       

      ole_application := CLIENT_OLE2.create_obj('Word.Application');

      CLIENT_OLE2.set_property( ole_application, 'Visible', 1 );

       

      mydocuments := CLIENT_OLE2.get_obj_property ( ole_application, 'documents' );

       

      mydocument := CLIENT_OLE2.invoke_obj( mydocuments, 'Open', args );

      CLIENT_OLE2.destroy_arglist( args );

       

        ..

       

      args := CLIENT_OLE2.create_arglist;

      CLIENT_OLE2.add_arg( args, v_file_name );

      CLIENT_OLE2.invoke( mydocument, 'SaveAs', args );

      CLIENT_OLE2.destroy_arglist( args );

       

       

      Regards

       

      Daniel

        • 1. Re: Using Webutil to create Word Document in DOCX format.
          Holger.Lehmann

          Does your Office Version support DOCX format ?

           

          Maybe Webutil OLE cannot support it.

          • 2. Re: Using Webutil to create Word Document in DOCX format.
            db12345

            I'm running Word 2010 which does support DOCX, forgot to mention that in the original post.

             

            So the question is does Webutil OLE support DOCX or is there something different required to get it to work.

            • 3. Re: Using Webutil to create Word Document in DOCX format.
              Frank Hoffmann-colognedata

              Why don't you create your Default OLE doc and change it to docx at the end of your operations with your object_handle?

               

              p_filesaveas('db12345.docx');

               

              Procedure p_filesaveas(p_fname   in varchar2) is
                ole2_arglist WEBUTIL_OLE2.list_type;
              begin 
                ppr_meldung.p_put_log('BEGIN ppr_msword.p_filesaveas(fname: '||p_fname||')',-75);

                 ole2_arglist := WEBUTIL_OLE2.create_arglist;
                 WEBUTIL_OLE2.add_arg (ole2_arglist,p_fname);
                 WEBUTIL_OLE2.invoke(word_obj_hnd1,'SaveAs',ole2_arglist);
                 WEBUTIL_OLE2.destroy_arglist (ole2_arglist);

              exception
              when others then
                   p_error_handler('ppr_msword.p_filesaveas');
              end p_filesaveas;

               

              Frank

              • 4. Re: Using Webutil to create Word Document in DOCX format.
                Holger.Lehmann

                I've tried it with the webutil demo form.

                 

                Code is similiar to yours. And it works, even with docx.

                 

                PROCEDURE OLE_WRITE IS

                  app       CLIENT_OLE2.OBJ_TYPE;

                  docs      CLIENT_OLE2.OBJ_TYPE;   

                  doc       CLIENT_OLE2.OBJ_TYPE;

                  selection CLIENT_OLE2.OBJ_TYPE;

                  args      CLIENT_OLE2.LIST_TYPE;

                BEGIN

                  -- create a new document

                  app := CLIENT_OLE2.CREATE_OBJ('Word.Application');

                  if :ole.silent = 'Y'

                  then

                    CLIENT_OLE2.SET_PROPERTY(app,'Visible',0);

                  else

                    CLIENT_OLE2.SET_PROPERTY(app,'Visible',1);

                  end if;

                 

                  docs := CLIENT_OLE2.GET_OBJ_PROPERTY(app, 'Documents');

                  doc  := CLIENT_OLE2.INVOKE_OBJ(docs, 'add');

                 

                  selection := CLIENT_OLE2.GET_OBJ_PROPERTY(app, 'Selection');

                 

                 

                  -- insert data into new document from long item

                  CLIENT_OLE2.SET_PROPERTY(selection, 'Text', :ole.oletext);

                 

                 

                  -- save document as example.tmp

                  args := CLIENT_OLE2.CREATE_ARGLIST;

                  CLIENT_OLE2.ADD_ARG(args, :ole.filename);

                  CLIENT_OLE2.INVOKE(doc, 'SaveAs', args);

                  CLIENT_OLE2.DESTROY_ARGLIST(args);

                 

                 

                  -- close example.tmp

                  args := CLIENT_OLE2.CREATE_ARGLIST;

                  CLIENT_OLE2.ADD_ARG(args, 0);

                  CLIENT_OLE2.INVOKE(doc, 'Close', args);

                  CLIENT_OLE2.DESTROY_ARGLIST(args);

                 

                  CLIENT_OLE2.RELEASE_OBJ(selection);

                  CLIENT_OLE2.RELEASE_OBJ(doc);

                  CLIENT_OLE2.RELEASE_OBJ(docs);

                 

                -- exit MSWord

                  CLIENT_OLE2.INVOKE(app,'Quit');

                 

                END;

                 

                Unbenannt.PNG

                 

                Version is Windows 7 with Forms 12.2.1.2 and Office 2010. Did you follow Webutil Setup Guide with special version of jacob.jar ?

                • 5. Re: Using Webutil to create Word Document in DOCX format.
                  db12345

                  Interesting, yes Jacob is fully setup and working. Its interesting that yours works when changing the extension, I wonder if the content actually switches file format.

                   

                  After reviewing some of the Microsoft OLE documentation, I noticed that there is a SaveAs2 method that accepts the parameter to specific it as DOCX.

                   

                        args := CLIENT_OLE2.create_arglist;

                        CLIENT_OLE2.add_arg( args, v_email_file );

                        CLIENT_OLE2.add_arg( args, 16 );

                        CLIENT_OLE2.invoke( mydocument, 'SaveAs2', args );

                   

                  Sourced from: https://docs.microsoft.com/en-us/office/vba/api/word.saveas2