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.

Comments

neclimdul’s picture

Status: Active » Needs review

Thanks, initial look at the patch seems pretty good. Will give it a closer look as time permits.

Anonymous’s picture

StatusFileSize
new516 bytes

your patch is rejected on attached file

bendiy’s picture

This patch shouldn't even touch views-bonus-export-csv.tpl. Not sure what problem you are having.

rconstantine’s picture

Subscribing, 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.

jameshenry’s picture

Exporting 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.

iNade’s picture

Any news about this project ?

Can't open any ;XLS file or whatsoever : seems that the export are not that good.

andreiashu’s picture

StatusFileSize
new2.19 KB

Attached is an updated patch against the latest Dev snapshot.

gengel’s picture

+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.

neclimdul’s picture

Status: Needs review » Needs work

The patch is actually missing the template so it's not very reviewable. Everything else looks fine.

vivianspencer’s picture

Have 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

vivianspencer’s picture

StatusFileSize
new14.79 KB

I've created a module which allows you to use PHP Excel with views if anyone is interested.

bendiy’s picture

@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.

vivianspencer’s picture

@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

neclimdul’s picture

I'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.

vivianspencer’s picture

@neclimdul: I agree with you actually, I think it would better off in its own module

bendiy’s picture

Assigned: Unassigned » bendiy
Status: Needs work » Needs review
StatusFileSize
new378 bytes
new5.17 KB

Attached 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!

benkewell’s picture

@ #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.

neclimdul’s picture

@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.

neclimdul’s picture

Status: Needs review » Fixed

Committed. 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.

askibinski’s picture

This works great, thanks!

bendiy’s picture

@neclimdul thanks for including this. No more need to apply my patch!

Congratulations on the 1.0 final release!

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.