No data in cells

Topics: Developer Forum, Project Management Forum, User Forum
Aug 19, 2008 at 1:59 AM
Hi all,
I have a very strange issue. On my development server (Windows Vista - Apache 2.2.9 - PHP 5.2.6) I get exactly what I expect collecting data from a MYSql database and writing it to an Excel workbook with multiple worksheets using PHPExcel_Writer_Excel5. I have inserted graphs of the data as PHPExcel_Worksheet_Drawings using the jpGraph library. It all works beautifully, my client is very impressed.

Here's the big BUT: When I run the code on the production server (Linux - Apache 2.0 - PHP 5.2.1) the workbook is produced with all the worksheets, the graphs are there with the correct data, the cells are all formated as they should be but there is no data?

Any ideas on what I have done wrong?
Aug 21, 2008 at 1:32 AM
This sounds strange... but I don't know much about how the Excel5 writer is built internally.

Can you try to check whether you can create a simple xls file, for example by creating a single sheet with only one non-empty cell A1, and see if that works?
Aug 21, 2008 at 11:20 PM
I created the following simple test script:

$workbook = new PHPExcel();
$worksheet = $workbook->getActiveSheet();
$worksheet->setCellValue('A1','Hello, this is a test cell');
$PHPWriter = new PHPExcel_Writer_Excel5($workbook);
The result was a workbook with one worksheet whose title is set to 'Test', column A is 40 wide, row 1 is 30 high but there is nothing in A1.

Could this be something to do with what was done to fix my tempDir() issue PHPExcel_Writer_Excel5->setTempDir() not passed to all classes involved in writing to a file.
Aug 22, 2008 at 6:39 AM
That is indeed a possibility. Will check!
Aug 22, 2008 at 6:47 AM
Can you test with the latest source?
Aug 22, 2008 at 10:25 AM
Edited Aug 25, 2008 at 10:37 AM
I downloaded Friday's final source and tested it on the local machine and then on the production server. I am still experience the same results, worksheets formated correctly but no data on the production server with that source.
Aug 25, 2008 at 10:30 PM
Good Morning,
Any further ideas?
I have tried yesterday's source (16567) with the same  results. I also tried changing the temp directory - no change, not setting the temp directory - got original open_basedir error messages.

Aug 26, 2008 at 11:27 PM
Unless someone has any more ideas and you don't get this fixed, I would be willing to do some tests in a separate directory on the server if ftp access is provided?
I may not be able to fix this, but hopefully I could narrow down the problem. You can send me private message.
Aug 27, 2008 at 6:47 AM
koyama: I have sent you a private message with FTP details.
Aug 27, 2008 at 12:11 PM
Thanks, I received the FTP details. I did some testing and found the problem.

Setting error_reporting(E_ALL) reveals the problem when one uses the Excel5 writer:

Notice: iconv() [function.iconv]: Wrong charset, conversion from `UTF-8' to `Windows-1252' is not allowed in /home/lo/log/ on line 166

Notice: iconv() [function.iconv]: Wrong charset, conversion from `UTF-8' to `UTF-16LE' is not allowed in /home/lo/log/ on line 1608

Pointing to these lines respectively:

'NumFormat' => iconv("UTF-8", "Windows-1252", $style->getNumberFormat()->getFormatCode()),

$str = iconv($this->_input_encoding, 'UTF-16LE', $str);

Apparently, the iconv function is broken on your platform. Some (most?) conversions are not working such as converting 'UTF-8' to 'UTF-16LE'. iconv() simply returns bool(false) in those cases. That is why you get blank cells.

This seems to be a known issue:

You may try using mb_convert_encoding() instead of iconv(). I tried on your server and it worked:

//'NumFormat' => iconv("UTF-8", "Windows-1252", $style->getNumberFormat()->getFormatCode()),
'NumFormat' => mb_convert_encoding($style->getNumberFormat()->getFormatCode(), "Windows-1252", "UTF-8"),

//$str = iconv($this->_input_encoding, 'UTF-16LE', $str);
$str = mb_convert_encoding($str, 'UTF-16LE', $this->_input_encoding);

I have no idea if this is this PHP issue is a common problem or not. If someone knows if the PHPExcel source needs to be modified please post. Maarten, any opinion on this?
Aug 27, 2008 at 10:24 PM
Koyama: Thank you so much. I really appreciate your help. It works on both platforms. This is a great library!!
Feb 13, 2009 at 7:24 AM
Update: In PHPExcel one will no be affected by this as long as one has mbstring extension enabled. Thus, no manual editing of PHPExcel/Writer/Excel5/Worksheet.php is needed. Per work item #9248 mbstring extension is used as the default encoder.