2

We need to get download functionality where channel entries can be downloaded to an Excel spreadsheet (preferably) or a csv at a push.

Been looking at Export_It and using it which is ok but ran into two problems which apparently are not solvable - at least have never got any results investigating them - so need maybe another solution.

The problems in question were/are:

1) Strange characters in the spreadsheet if the file contains accented foreign characters. I believe integrating PhpExcel with Export_It should fix this but I never got this working and no-one on PhpExcel forums or elsewhere seems to know anything about the error.

2) We need to be able to take data from TWO categories in the download: i.e. category="1&2" in the parameters. Have not been able to find out if Export_It supports this but it seems not as it doesn't work.

So we need another solution. Has anyone successfully implemented PhpExcel as a stand-alone in EE? Are there any other modules or solutions you might recommend?

4
  • 1
    Hey segovius, I think the approach of using EE templates to generate the spreadsheet. There are some good answers in What is the best method for exporting channel entries as a spreadsheet? as well as a helpful comment by Issac
    – Alex Kendrick
    Jan 20 '15 at 16:12
  • 1
    Whoops. Previous comment meant to say ...I think using EE templates would work for you
    – Alex Kendrick
    Jan 20 '15 at 19:47
  • Great, Alex, thanks. That seems to work but there's one issue which is minor but probably should fix: in Safari Mac this method is appending .html to the .xls file. Did you come across this? Anyway to remove it so the end-user doesn't have to?
    – segovius
    Jan 21 '15 at 8:00
  • Good point. Rob Sanchez's HTTP Header plugin can help with that. I added this as an answer.
    – Alex Kendrick
    Jan 21 '15 at 15:55
2

One really flexible and simple shortcut to exporting a .xls spreadsheet of Channel data is to generate an html table using an ExpressionEngine template, save the page as a file, and then open the file with MS Excel.

  1. Create a template (eg export.group/index.html)
  2. Output all the necessary data using a channel:entries loop and any other necessary template tags.
  3. Load this template on the front end in your browser (above example template would load at example.com/export)
  4. Either save the webpage as a file and manually set the file extension to .xls or use the HTTP Header plugin to automatically force download and set the appropriate file extension for you.

Example template code including force download of .xls file:

{exp:http_header 
    content_disposition="attachment" 
    filename="myfile.xls" 
    content_type="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
}
<table>
    <thead>
        <tr>
            <th>Entry ID</th>
            <th>Title</th>
            <th>Author</th>
            <th>Created</th>
            <th>Updated</th>
            <th>Status</th>
            <th>Tool File</th>
            <th>Tool URL</th>
        </tr>
    </thead>
    <tbody>
        {exp:channel:entries
            channel="tools"
            disable="category_fields|member_data|pagination"
            dynamic="no"
            limit="999"
        }
            <tr>
                <td>{entry_id}</td>
                <td>{title}</td>
                <td>{author}</td>
                <td>{entry_date format="%Y-%m-%d-%H:%i"}</td>
                <td>{edit_date format="%Y-%m-%d-%H:%i"}</td>
                <td>{status}</td>
                <td>{tool_file}</td>
                <td>{tool_url}</td>
            </tr>
        {/exp:channel:entries}
    </tbody>
</table>
4
  • Yeah I was essentially doing this but with PHP rather than Rob's plugin - tired both now but seems that Safari still appends the .html in ether case. I think it's a Safari thing as it doesn't happen with other browsers. One other thing re this is that it's not essentially a native .xsl file even when you remove the .html manually. You need .xslx for that but can't get that working at all.
    – segovius
    Jan 21 '15 at 17:25
  • 1
    I see what you mean. I updated my answer and added the content_type parameter to the HTTP Header tag. This seems to satisfy Safari in my test. The Safari-downloaded file has just .xls as the file extension and opens right up in Excel.
    – Alex Kendrick
    Jan 21 '15 at 17:58
  • Great... that did it! I've marked your post as the answer. One thing about the file - though I can probably live with this - is that it seems to have no borders on the cells, basically is the borderless cells and info on a plain white background. No biggie though I guess. I'm also trying to get get the category ID here in the parameters from the url segment so the download can be dynamic but it seems this is not possible. I guess I should open another question for that though unless you know of a quick fix. Thanks for this!
    – segovius
    Jan 21 '15 at 19:41
  • 1
    That's a good point about the borders. I might have to experiment with that. I bet you can get the category bit to work, but I think you are right: a new question with some template code would be best.
    – Alex Kendrick
    Jan 21 '15 at 21:35

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.