1

Well the excel 2003 can open the csv files and if the the delimiter is tab it can automatically transform data into correct columns.

Well the problem is with the characters which aren't the ascii ones. The libreoffice opens the dialog for selecting charset but the excel 2003 does not and imports the characters into wrong charset.

<?php
$filename ="excelreport.xls";

$contents1 = "Name \t Location (where from) \t Age \t \n";
$contents = "testdata1 \t testdata2 \t testdata3 \t \n";
$problematicData = array('ä', 'ö', 'õ', 'ü');

header('Content-type: application/ms-excel');
header('Content-Disposition: attachment; filename='.$filename);

echo $contents1;
echo $contents;
echo implode(" \t ", $problematicData);

// EDIT Probably i found a fix added this header('Content-type: application/ms-excel; charset=utf-8; encoding=utf-8'); But i haven't tested it with the excel 2003.

Risto Novik
  • 8,199
  • 9
  • 50
  • 66

1 Answers1

0

Tried using commas instead? PHP has a fputcsv function that can handle that easily

Eli
  • 5,500
  • 1
  • 29
  • 27
  • The older excel 2003 parses the columns automatically with \t, but seems the encode problem remains, as it does not know which encoding to use. OO provides the CSV import dialog where you can specify encode to UTF-8, but MS excel 2003 does not have this. If someone could try how this works with newer versions of MS products ? – Risto Novik Apr 15 '12 at 07:51
  • @jurka - Well, another option is to try creating an XLS or XSLX instead. There are some tools: http://stackoverflow.com/a/3931142/5958 including one I wrote. But I'm honestly not sure any one solution will work perfectly with no dialogs on Excel 2003 and later and also OO. – Eli Apr 26 '12 at 13:04