By Daniel Wood, 28 February 2019
When it comes to viewing Microsoft Office files within FileMaker, this has always been quite a sore point for developers. Unlike images, video files, audio files, and PDF files, we cannot directly view these file formats within container fields. Developers tend to resort to exporting the files to disk and auto-opening them locally on the users machine. This however requires that the user have a copy of Microsoft Word, Office, or PowerPoint installed in order to view the file they wish to see. This is not always the case.
In this article we're going to show how you can add Excel, Word or PowerPoint document viewing to any existing FileMaker solution in about 10 minutes, the setup couldn't be simpler!
Microsoft has a range of apps within its office 365 offering. Examples like Word, Excel, Powerpoint are so commonplace in industry today that almost everyone at some stage needs to view a doc file, or open a spreadsheet in Excel. Microsoft also makes these apps available online in the cloud via their 365 service. Users can keep their documents online in their MS OneDrive, and use online tools to view documents entirely within the browser.
But did you know that they also have an online file viewer, which is freely available for anyone to use, no account required? This will render any Word, Excel or PowerPoint presentation providing that file is hosted online and the URL is accessible to the file viewer tool.
Using this fact we can utilise the viewer in order to view documents stored directly in our own solutions. We just need to get the file online so that the viewer can render it for us. No more viewing of a document in FileMaker and just seeing this:
The first obstacle to overcome is getting your container data online so that the office viewer can render it. Now there are obviously numerous ways you can do this, such as:
For this example we're going to use a really simple online file hosting service called file.io. The goal here is to upload container fields to this service, and use the resulting hosted URL to pass to the office viewer for display.
File.io is a great little service for hosting files. One of its key benefits is that it is a single-view only service. When a file is hosted there, the URL is only valid to be viewed once only. After that single viewing occurs the file is deleted and the URL is removed. This is perfect for our use because we don't want that file to hang around on a server somewhere, nor do we require the URL after we view it.
While that all sounds good, you have to be very careful when dealing with any third party service especially when they will be hosting your files. You may have sensitive information in your files you do not wish to put in the public domain. While secure, the files will still reside temporarily on someone else's server, and while the URL is a one-time view, you can never fully trust that.
We are using this service for the demo but you should consider a more secure method of hosting your container data online if you intend to use this service. A good method would be to host them on your own server, and only allow the office viewer URL access.
The file.io api is really simple, no keys are required, it's a simple CURL post of your file to their server, and in return you are given some simple JSON. Included in that result is the URL to your file.
You can find this script in the example file included at the bottom of this article. It is recommended you download it and have a look through as you read.
Here's the code above. What we do is first put the container data into a variable $file. This makes the subsequent steps a bit easier and clearer.
Next, We calculate a local variable name, which we store in $VariableName. Why do we do this? Well this comes down to how posting of a file works using CURL, in conjunction with what the file.io api is expecting us to give them. This will be more apparent in the next step:
Evaluate ( "Let ( " & $VariableName & " = $file ; 1 ) " )
We are evaluating a calculation string here where we are setting our variable to the file contents that is stored in $file. As an example if our file name was "test_file.doc" , then the name of the variable we are setting would be $test_file.doc , and the value of this would be that of the file itself. We use a LET statement to do this as it allows us the ability to soft-code the variable name without having to explicitly define it.
Why must we do this? Because in the following POST to file.io, we send the file using the "-F" command:
When we use a FileMaker variable in a CURL request, the name of the variable is important. File.io is using the variable name as the name of the file itself, and FileMaker in turn is passing the actual content of that variable to file.io - the file itself. If we were to use some other variable name e.g. "test" then the resulting file uploaded would be called "test". The Microsoft office viewer would not recognise this as a valid file format and so fail to display it. This is why variable name is important to be given the same name as the actual file we want to view.
Once our request is posted off to file.io, we simply parse out the "link" key value from the JSON response.
Once we have the URL to our file, the rest is easy. The office viewer simply follows a simple url format which accepts the files URL as a parameter:
http://view.officeapps.live.com/op/view.aspx?src=[OFFICE_FILE_URL]
We just replace [OFFICE_FILE_URL] with the one returned from file.io. We then display this in a web viewer.
This is what the viewer looks like for our 3 main file formats. Firstly a Word document:
Not too shabby! The document is strictly read-only so no editing is allowed. Some of the options listed in the toolbar and menus are not available but others are, things that work include:
There are buttons to "Download" and "Download as PDF" but these do not seem to work in the web viewer. However, the Print option does. The print option should open a new tab in your browser (so outside of FileMaker) and give you a PDF version that is printable. From here you can print or save as PDF.
Here is a simple Excel spreadsheet:
Again, pretty good all things considered. Once again read only, but you can clearly see cells/columns and it looks very much like excel. Again options you can make use of include:
Same again as the document, download buttons don't work.
Lastly we have a PowerPoint presentation:
Features include:
Google has its own similar offering based on its Google Docs service. Again it works in the same way office viewer does - it's just a URL that accepts another file URL to render.
Google actually has quite a bit of benefit over Microsoft when it comes to viewing other file types. Google offers a far wider range of file types to preview. This is really handy for some industries such as graphic design, because Google allows viewing of things like Adobe Illustrator, CAD, and other graphical formats. Google also allows preview of CSS, JavaScript and HTML files which would come in handy for some.
There is however a big drawback to Google, and why we haven't sung its praises in this article to this point. Unfortunately it doesn't work very well with our file.io service we are using.
When Google Docs is rendering a file URL, it must be accessing that URL more than once. File.io only allows access one time, and so Google Docs fails to render most file formats for this reason. Now, this is purely a limitation of file.io so if you host files using any other method you are likely to be able to use Google perfectly fine, in which case this may be the better option for you.
Google renders its previews as a PDF in almost all instances (exception being audio/video)..
As of writing this article it would appear only the Word Document format reliably works with file.io and so that has been included in the Demo.
File formats that Google accepts includes the following:
We've shown a really quick and easy way to view office based files from FileMaker. We have however shown you must think carefully about how you use this because both google and Microsoft require a publicly available URL that it can access in order to render the file, so think long and hard about how you handle this requirement.
Good luck!
While searching for a way to view spreadsheets in FileMaker for a client, it was this following site I came across which gave the answer:
https://gist.github.com/tzmartin/1cf85dc3d975f94cfddc04bc0dd399be
Many thanks to that sites publisher tzmartin for providing this invaluable information. You will also find on his site information about how you can do this within an iframe, and how you can use both Google and Microsoft to view files stored directly on their respective cloud offerings - Google Docs, and OneDrive.
As with all of our articles we produce we like to provide a detailed example file to go along with it. It’s not enough to just read how something is done, you should be able to see it in action and explore how it works yourself. Please find attached the example file below. This article is based on the example file. As always, this is a free download, and we won't make you sign up to download :)
Click here to download the example file!
Something to say? Post a comment...
Comments
Richard Malmsten 05/01/2024 5:08am (11 months ago)
Any workaround for office view?
"The URL of the original file is not valid or the document is not publicly accessible. Verify the URL is correct, then contact the document owner."
Scott Henderson 04/04/2023 3:54am (2 years ago)
Hello - Just wondering if there is an update to this great example. I uploaded the file to our server to play around with it and I can get the Google sample viewer to work, but the Office examples do not. I get the following error in FM "The URL of the original file is not valid or the document is not publicly accessible. Verify the URL is correct, then contact the document owner." and when I click the "Learn More" button, I get "This site can’t be reachedThe webpage at https://www.office.com/redir.aspx?assetid=HA102724036 might be temporarily down or it may have moved permanently to a new web address."
jack miller 20/10/2020 1:25am (4 years ago)
SWF is an Adobe Flash file format used for multimedia, vector graphics it is small web format SWF is used for adobe flash player to play videos Gifts etc Programmers can generate SWF files from within several Adobe products, including Flash ,flash builder you can click here.<a href="/openfileextension.com/open-swf-file/"">open-swf-file</a>.
walter noia 22/05/2020 12:36am (5 years ago)
Great Job as always !
Daniel Farnan 04/03/2019 5:35pm (6 years ago)
Thanks Daniel for the tip and thanks John for the additional work. This is a _magnificent_ piece of functionality that once again extends the stuff that a FileMaker solution can do.
Top work, both of you!
Daniel Wood 02/03/2019 8:43am (6 years ago)
hi John, that's awesome stuff thank you ! I'm going to digest this and have a play and see how it all works, and will update the article accordingly with your new information, cheers again!
john renfrew 01/03/2019 10:25pm (6 years ago)
Update..
You dont need to do that shortening stuff, you just need to URL encode the S3 link as the parameter - work with Google viewer
https://www.bitesite.ca/blog/17
john renfrew 01/03/2019 10:18pm (6 years ago)
Daniel,
So this method works with the Google viewer..
If this is an ephemeral thing then uploading the file, creating a link, viewing and then deleting would be a workflow. It means if someone manages to break your code and get the file URL it can still be accessed until the link has expired or the file is deleted - but it is otherwise hidden away can't be accessed..
But something interesting is that the new bit.ly API allows you to CHANGE the long url associated with a short one... so you could create a link for each user, or persitent ID or something and then change the associated bit.ly link. So after viewing the file, change the link to a dummy 404 page so that the link only has content after the S3 file link is created and while it is being viewed.. You can't just use one for a solution to remove the risk of collision and people seeing the contents of another request..
Daniel Wood 01/03/2019 11:10am (6 years ago)
hi John, that's really interesting. So I would presume that should sort the google issue because the problem there is the one view life span of the url. We've tested it with just a file hosted on our server and google works fine when the URL can be accessed more than once. I like the idea of explicitly deleting the file on window close.
It would be great also to set a life span of something less than day which is the minimum about file.io offers - that 1 day lifespan is not valid for a day it simply means you can view it once within a day, but if there is a service that allows unlimited views within say 5 minutes that would be ideal.
john renfrew 01/03/2019 9:05am (6 years ago)
This will work with an S3 type link IF you process the link through a URL shortening service first...
Just tested it with Wasabi - which charges nothing for data egress, so you could create a signed link with a very short life span, and then run a cURL to delete the file when you close the window, so miniscule storgage cost..
Just need to see if this sorts the Google issue
No one has commented on this page yet.
RSS feed for comments on this page | RSS feed for all comments