8 Replies Latest reply on Apr 16, 2017 8:09 AM by fmpdude

    import a Word Doc as text

    ProdMan

      Since FM is still so lousy at formatting text in a field, I am trying to import text from a Word doc into a field. So far I've read in Discussions that (1) Filemaker can't import Word docs; (2) the field needs to be a container; (3) you need a plug in (with a link to 360Works Scribe).

      I have tried the container route and I can import the Word doc but it simply shows up as an icon. I've tried the doc as: docx, txt, rtf, and docm; all show as an icon.

      If anyone knows if (and if "yes", how) this can be done I would love to know.

        • 1. Re: import a Word Doc as text
          Johan Hedman

          If you just follow 360Works Scribe template files you will get a very good step by step on how you should set it up for your database

          360Works Scribe 2.15 User Guide

          • 2. Re: import a Word Doc as text
            fmpdude

            Well, the way I handle importing word text is with Java and a micro-service that connects to the FMP application. It's not difficult and it works with .DOC and DOCX files using a free Apache library.

             

            The advantage of creating a micro-serivce is that it's:

             

            1. FREE

            2. Cross platform (not just FMP). Any app that can do a "GET" could use the service (Terminal, Browser, FMP, etc.)

            3. Extremely F-A-S-T

            4. You're in control of the code, not a third party,

            5. Easy to debug.

            6. No cumbersome license agreements that limit you

            7. Your service can potentially support hundreds of users (or more)

            8. Etc.

             

            -----

             

            FMP is wonderfully "open" and that's extremely cool. Thus, things FMP can't do natively, you can STILL DO!

            • 3. Re: import a Word Doc as text
              wimdecorte

              ProdMan wrote:

               

              Since FM is still so lousy at formatting text in a field, I am trying to import text from a Word doc into a field. So far I've read in Discussions that (1) Filemaker can't import Word docs; (2) the field needs to be a container;

              You only need a container field if you want to store the original Word document.  You want its contents so the container field does not apply.

               

              Plugins are the easiest way to do it because they keep the code in FM, in your comfort zone.

               

              But there are plenty of non-plugin ways to do it.  fmpdude would do it java, I would do it using the native Word APis.  AppleScript on Mac and VBscript/powershell on Windows are easy to integrate and they can make Word save its content to pure text so that you can import it into FM for instance.

               

              If you want the original Word content complete with Word formatting then you are in for a much bigger undertaking.

               

              If all you want is rich text editing in FM, then look at integrating some of the free text editors that can work in a web viewer.

              • 4. Re: import a Word Doc as text
                fmpdude

                +1

                 

                Totally agree -- for importing Word docs, either put the document into a container field or be happy with just the text of the document (however you extract it), but not the formatting too.

                 

                The crazy word formatting varies from .DOC to .DOCX. These formats can be a bit complicated to work with.

                 

                Thus, I try to avoid working with proprietary formats whenever possible.

                 

                Text is easy to work with, non proprietary, etc.

                 

                (I don't believe importing word documents would be any easier in any other environments. FMP's container field makes it about as easy as it gets.)

                • 5. Re: import a Word Doc as text
                  rouelf

                  Often I extract text from a Word.doc file as follows, it is not ideal, not clean, but gets the job done:

                   

                  1) Import file to a Container_Field, embed.

                   

                  2) Use Base64, Encode, Decode:

                         Replace Field Contents [ With dialogs: Off ; Container_Field ; Base64Decode ( Base64Encode ( Container_Field ) ; GetContainerAttribute ( Container_Field ; "FileName" ) ) ]

                   

                  3) Export the file in the Container_Field to the Temp Folder, using a .txt extension (File.txt)

                   

                  4) Insert from URL, from Temp Folder to a Text_Field. Use appropriate paths for Windows, or Mac and iOS. You may also display the Text_Field in a WebViewer.

                   

                  5) The basic text in the Word.doc can be seen in the Text_Field an extracted. Though there will be lots and lots of unreadable characters.

                  • 6. Re: import a Word Doc as text
                    fmpdude

                    I saved your posting to a docx file, loaded my service (only takes THREE lines of code!) and got the text imported from the DOCX right in Terminal in one quick step using CURL.

                     

                    Note: No unreadable characters.

                     

                    No FMP required: Pain-free without lots of steps that give sub-par results.

                     

                    Below is the imported text (right in Terminal using CURL) from your posting above from a DOCX file:

                     

                    Often I extract text from a Word.doc file as follows, it is not ideal, not clean, but gets the job done:

                    1) Import file to a Container_Field, embed.

                    2) Use Base64, Encode, Decode:

                           Replace Field Contents [ With dialogs: Off ; Container_Field ; Base64Decode ( Base64Encode ( Container_Field ) ; GetContainerAttribute ( Container_Field ; "FileName" ) ) ]

                    3) Export the file in the Container_Field to the Temp Folder, using a .txt extension (File.txt)

                    4) Insert from URL, from Temp Folder to a Text_Field. Use appropriate paths for Windows, or Mac and iOS. You may also display the Text_Field in a WebViewer.

                    5) The basic text in the Word.doc can be seen in the Text_Field an extracted. Though there will be lots and lots of unreadable characters.

                     

                    ----

                     

                    That same one-liner to call the service works in FMP (or any application that can do, in this case, a GET) just as easily (again, importing a word docx with your posting text above):

                     

                    -----

                     

                    Using the simple micro-service, you could even import/display your posting above from a word doc right into the browser:

                     

                    http://localhost:4567/docxtext/..../posting.docx

                     

                    Often I extract text from a Word.doc file as follows, it is not ideal, not clean, but gets the job done: 1) Import file to a Container_Field, embed. 2) Use Base64, Encode, Decode: Replace Field Contents [ With dialogs: Off ; Container_Field ; Base64Decode ( Base64Encode ( Container_Field ) ; GetContainerAttribute ( Container_Field ; "FileName" ) ) ] 3) Export the file in the Container_Field to the Temp Folder, using a .txt extension (File.txt) 4) Insert from URL, from Temp Folder to a Text_Field. Use appropriate paths for Windows, or Mac and iOS. You may also display the Text_Field in a WebViewer. 5) The basic text in the Word.doc can be seen in the Text_Field an extracted. Though there will be lots and lots of unreadable characters.

                    • 7. Re: import a Word Doc as text
                      PeterCortiel

                      That sounds interesting

                      Can you expand a bit

                      What is a micro-service?

                      • 8. Re: import a Word Doc as text
                        fmpdude

                        First of all, this word import should be built into FMP!

                         

                        A multi-hundred dollar product without support for arguably one of the most popular formats is ridiculous -- another glaring omission of product functionality at a version 15 product. (let's get search and replace in scripts, a version 1.0 feature, first I guess...).

                         

                        --

                         

                        Now, to answer your question .... A micro-service is basically a "web service" that will listen on a particular port number. For prototyping, I like the "Java Spark" framework which I first learned about from a poster on this forum.   So, you write a little Java code and viola. You're done.

                         

                        I write micro-services for FMP integration for small things like Word imports, or flexible date logic, etc., but also for longer code where the "Script Workspace" would drive me crazy (longer than about 10 lines).

                         

                        --------

                         

                        Now, if you've never done any Java, that first micro-service might take a little time, but not too long I'd guess.

                         

                        The nice thing about a micro-service is that it's self-contained.

                         

                        So, that means all the dependencies (files, libraries, etc.) to make it run are all within a single executable "jar" file (a file that ends with ".jar"). You could email that Jar to someone else and they could run it.  Other than having Java installed, there is no "install" required to run the service.

                         

                        You "run" the jar file at the command line and it loads the service. From that point forward, you can use GET/POST/PATCH, etc., HTTP Verbs, that you've implemented in your service from FMP, Terminal, basically, anything that can do a GET/POST/PATCH, etc.

                         

                        And, the micro-service is FAST, FREE, and as indicated above, totally cross-platform and cross-programs. It will run anywhere you have Java installed.

                         

                        Just another option that FileMaker nicely makes available to use via INSERT FROM URL, for example.

                         

                        Note that a regular Web Service gets installed into an Application Container like Tomcat and although it's not really much different, there's a bit more work to set that up. A micro-service is relatively simple to create and use -- depending on your requirements, naturally.

                         

                        If you decide to take a swing at setting up a microservice, check out Eclipse (FREE) or Intellij (Community version available).

                         

                        Post back with questions, OK?