This patch addresses previous issues to provide an option to Export to Excel.
This is an updated port of the patch in Issue #444412 that has been updated to work with Views Bonus -6.x-1.x-dev as of July 07 2009. This patch only addresses the Excel Export function. See also Issue #262338.
The method for this export is via HTML Table. I believe this is the best method for the following reasons:
- Currencies - If a field value is formatted to show $10.99, Excel will see it as a Currency Field Format with value 10.99. This allows the field to be summed as a number.
- Hyperlinks - Excel will preserve any links in Views Fields. If this link is an Views Argument link, in Excel, you can click on the link and go directly to the web page.
- Text Formats - Bold, Italic, etc. will carry over to Excel.
All of these features make the HTML Table Excel export much more user friendly. Your users can start to use the export, email it and read it immediately. A direct data export like Views_Export _XLS does not persevere all of this info. You have to reformat all of the data in Excel before it's readable and usable.
This patch should be applied to sites/all/modules and will update the folder views_bonus inside of modules. You will need to copy the attached xls.png into the sites/all/modules/views_bonus/export/images.
| Comment | File | Size | Author |
|---|---|---|---|
| #16 | views_bonus.xls.patch | 5.17 KB | bendiy |
| #16 | xls.png | 378 bytes | bendiy |
| #11 | views_phpexcel.zip | 14.79 KB | vivianspencer |
| #7 | views_bonus_xls_patch_2.patch | 2.19 KB | andreiashu |
| #2 | views-bonus-export-csv.tpl_.php.txt | 516 bytes | Anonymous (not verified) |
Comments
Comment #1
neclimdulThanks, initial look at the patch seems pretty good. Will give it a closer look as time permits.
Comment #2
Anonymous (not verified) commentedyour patch is rejected on attached file
Comment #3
bendiy commentedThis patch shouldn't even touch views-bonus-export-csv.tpl. Not sure what problem you are having.
Comment #4
rconstantine commentedSubscribing, and question:
Will this address issues with bullets (for example)?
I'm using WYSIWYG editors all over. Users enter in bulleted lists quite often. I show these in tabular views as one column. When exporting to CSV, the bullets turn into some funky characters and of course lose formatting (carriage returns?). Ideally, exporting to XLS would solve that and keep the bullets intact.
Comment #5
jameshenry commentedExporting automatically to excel without any patch is working fine for me.
Chose style as "doc file", and inside the parameters check "provide as file" and then change the proposed filename from "view-%view.doc" to "view-%view.xls"
It will then open excel instead of word, keeping the format fields.
Comment #6
iNade commentedAny news about this project ?
Can't open any ;XLS file or whatsoever : seems that the export are not that good.
Comment #7
andreiashu commentedAttached is an updated patch against the latest Dev snapshot.
Comment #8
gengel commented+1 vote for this patch or something similar
Export to CSV doesn't work in Excel if you have Unicode characters in your data. I needed to export a View to Excel and ended up going with a solution quite similar to this (before I discovered this patch existed.) For this reason, and those cited above, I think HTML-within-XLS is the best option.
Comment #9
neclimdulThe patch is actually missing the template so it's not very reviewable. Everything else looks fine.
Comment #10
vivianspencer commentedHave any of you seen the following library: http://phpexcel.codeplex.com, it looks like a much better alternative to the library used in http://drupal.org/project/views_export_xls or the HTML table solution used in this patch.
Take a look at the features: http://phpexcel.codeplex.com/wikipage?title=Features&referringTitle=Home
Comment #11
vivianspencer commentedI've created a module which allows you to use PHP Excel with views if anyone is interested.
Comment #12
bendiy commented@vivianspencer
http://phpexcel.codeplex.com has an impressive set of features. I'll have to spend some time paying with it to see if I can make it do what I need.
I installed your module #11 and tried it out. In it's current state, it breaks the most important feature of my original patch. Using your module, when I export a View to Excel, it does not maintain the data formats. It brings in "$99.99" as a General format and not Currency. This means that I cannot SUM a column of dollar amounts or apply formulas to those fields without going through the extra step of changing the format. I'm trying to avoid that step so my users can Export to Excel and begin working on a document immediately without the confusion of extra steps.
I've been using my patch for months and it's working great. I have not had time to port it to the current version of View Bonus Pack. However, I'm approaching a point where I'll need to publish the project I'm using this for. Before I do that, I'll need to upgrade my Development environment to the current release. I'll be porting this patch at that time if no one else does before that.
Comment #13
vivianspencer commented@bendiy
The module isn't perfect, it was created for a project I needed and may still have a few bugs, it actually has a template "views-phpexcel-view-xls.tpl.php" which allows you to format the data using PHPExcel. You should be able to swap the code in the template with any of the following examples:
http://phpexcel.codeplex.com/wikipage?title=Examples&referringTitle=Home
This means that you can create the formulas inside of the template rather than having to adjust the excel file after export
There is also a preprocess function "template_preprocess_views_phpexcel_view_xls(&$vars)" which allows you to alter the data the template receives
Comment #14
neclimdulI'm more interested in keeping Views Bonus about providing building blocks and small self contained extensions of views that don't fit elsewhere. If its going to require an external library then that seems like it might be better off as its own module. As far as the original patch is concerned, I just haven't had time to give a good solid review.
Comment #15
vivianspencer commented@neclimdul: I agree with you actually, I think it would better off in its own module
Comment #16
bendiy commentedAttached is an updated patch that applies to the current Views Bonus - HEAD from today (12-10-2009). This is a port of my original patch to the latest HEAD version.
I did find out that you will have to have a newer version of Views that supports the hook_views_post_render(). Views 6.x-2.8 at the time of this writing is what I'm using.
Please review so we can get this committed and closed.
Thanks!
Comment #17
benkewell commented@ #15:
I've tried the module and it is very good.
The file created by phpexcel is much better than the existing views_export_xls module.
Can the module be made into its own project?
I have a few ideas on the module,
and may try to create a patch on that if it's maintained as a project.
Comment #18
neclimdul@bendiy Thanks this is at the top of my review todo and I'll take a look as soon as I can pull myself away from everything I've got going on. Tis the season to be busy?
@BenKewell and the phpexcel discussion. can we move to a forum thread or something? Thanks.
Comment #19
neclimdulCommitted. I modified a couple things very minimally. Different mime type that seemed to work better with being associated with excel and better docs in the template.
Thanks.
Comment #20
askibinski commentedThis works great, thanks!
Comment #21
bendiy commented@neclimdul thanks for including this. No more need to apply my patch!
Congratulations on the 1.0 final release!