Accents, umlauts etc. are not exported correctly. This can be helped by defining the character set:
drupal_set_header('Content-Type: application/msword; charset=utf-8');
and by creating a complete HTML document for the download document instead of just the table:
$table = "<html>\r\n<head>\r\n<meta http-equiv=\"Content-Type\" content=\"text/html;charset=utf-8\" />\r\n</head>\r\n<body>\r\n";
$table .= theme('views_view_table', $view, $nodes, null);
// strip 'img', 'a' and 'span' tags & all css classes (U stands for ungreedy search)
$htmlfilters = array('/<\/?(a|span|img) ?.*?>/',
'/ class="(.*)"/U');
$table = preg_replace($htmlfilters, '', $table);
$table .= "</body></html>";
print $table;
Adding the header allows for defining the character set.
The code above also strips out all class attributes (making the downloaded file much smaller), and the image tag (automatically part of the view if you have sortable column headers).
Comments
Comment #1
neclimdulLooks reasonable. Basic test seems to work for OOo anyways. There isn't a patch which would have made things easier.
Why is your preg_replace different from that in the 1.2 alphas? I don't see how that affects the fix.
Comment #2
Gerald Mengisen commentedSorry for the missing patch; at that time in my Drupal life, I didn't know how to create one. That has changed. Do you still need one?
About the preg_replace:
I should have created two issues instead of packing them into one - can still do that and create a patch. The preg_replace adresses the "...and strip class attributes" part (which is NOT related with the UTF-8 issue). When you use the old preg_replace and look at the exported document in the HTML source, you'll see that there is quite a lot of overhead that is no longer useful for an exported Word file (e.g. links to nodes, class attributes for table rows, or image tags for sorting columns). The new preg_replace removes all this which results in a much smaller Word file.
Comment #3
neclimdulI've got something I think I'm about ready to commit so don't think I need a patch.
A separate issue would be nice for tracking things for the second part though. And I wouldn't complain about a patch being on that one. ;)
Comment #4
neclimdulcommitted a fix based on the code in the original issue minus the modified filtering.
Comment #5
Gerald Mengisen commentedSeparate issue and patch created for the filtering as suggested in comment #3: #360562: Word export should strip out class attributes