Attention

This document was written for an unsupported version of Plone, Plone 2.5.x, and was last updated 1604 days ago.

For more information, see the version support policy.

To learn how to upgrade to the current version of Plone, read the upgrade manual.

Making CSV files display in the browser window (inline) using Excel

by Alex Limi last modified Dec 30, 2008 03:03 PM
This how-to explains how to get CSV files to be shown inside the browser window (also known as "inline display") using Excel as the display application.

Important: You need Plone 2.1.4, Plone 2.5.1 or later to get the various Office documents rendered inline in the browser. Earlier versions of Plone will cause them to be downloaded instead of rendering them in the browser window.

The reason we wanted this was for a customer that has most of their data in CSV files, and needed to display them using Excel on their web site and intranet.

Technically speaking, the problem is that instead of displaying the content inline, Plone sends it to the browser with the MIME type text/x-comma-separated-values (which is correct), and Excel does not intercept this request to display it in the browser window, causing a file download instead.

The way to work around this is to do the (slightly evil ;) trick of mapping the CSV file to the Excel MIME type instead. In general, this causes no problems (people without Excel still get to download the file), but isn't 100% clean if you consider the standards. This is also why it is not done by default in Plone.

OK, let's get started:

  • Go to the ZMI in your site
  • Go to mimetypes_registry
  • Search for csv on the page, and check the checkbox next to the entries that match. We are going to delete the existing ones. Strictly speaking, this isn't necessary in the current version of Plone, since the Excel MIME type is declared earlier and takes precedence, but I'm being paranoid about it in case the order changes — you can skip this step if you want. In my instance, the CSV entries were:
    • text/x-comma-separated-values
    • text/csv
  • Click Delete Selected Items at the bottom of the page with all the CSV-related entries selected.

Now there are no entries that handle CSV. Verify this by doing a search for csv on the page again.

Then we modify the MIME type that for the Excel file, so the CSV files are rendered inline in the browser window instead of causing a download:

  • Click the Microsoft Excel spreadsheet entry (search in page to locate it)
  • Under Extensions, add csv on a separate line
  • Under Globs, add *.csv as a separate line
  • Click the Submit button

Uploaded files with the CSV extension should now have the MIME type application/vnd.ms-excel, and open in Excel — inside the browser.


Contribute

Something wrong or out of date? Anybody can edit or create a new article in the knowledge base. Simply create an account on this site, log in, and click the Edit button to contribute.