0

Is there a way to view a microsoft office document in a visualforce page?

The files are Attachments of a custom object and I need to open a viewer for them.

I tried to use the field Body of the Attachment and render it in a visualforce page rendered as PDF. But it didn't work.

Any suggestions?

1

Microsoft Word/Excel/PowerPoint .doc/.xls/.ppt is a pretty awkward binary format and the newer .docx/.xlsx/.pptx is zipped XML but still complicated enough. So platforms like Salesforce do not have viewing or conversion capability for all these formats built in.

A reliable way to view these documents is to get your clients to install the free viewers that Microsoft provides if they don't have an Office license. Then as long as the attachments have the correct content type set (which AFAIK they will if manually uploaded from a correct extension file) a link in your Visualforce like this:

<apex:outputLink value="{!URLFOR($Action.Attachment.Download, attachment.id)}">
    Download/View
</apex:outputLink>

will download the attachment and if their browser is configured to "Always Open Files of this Type" (that is an option in Chrome) the attachment will be automatically opened in the correct viewer.

  • I think the Office license won't be a problem, but I want to open the file within an iframe in the same page. Using the viewer the user still has to open another window. – vanderlindo Nov 10 '14 at 12:15
  • OK - you should add this to your question. (Just my opinion, but as a user scrolling around in an iframe isn't a particularly good experience.) – Keith C Nov 10 '14 at 12:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.