Weird looking CSV when converting from Excel5 to CSV

Topics: User Forum
Feb 28, 2012 at 8:42 PM

Hello

When I run the code below (trying to convert a .xls to a .csv) everything looks good except all of the number fields.  If a field is supposed to show the number 22 it will instead show [$-1221224229]22  and a 0 shows [$-1010409]0

Any ideas?

Thanks

Alex,

 

My Code: 

#!/usr/bin/php
<?php

$original_name= "kaya_excel";
$loader_name = "KAYA_TEST".".csv";

require('PHPExcel.php');
require('PHPExcel/IOFactory.php');
require_once ('PHPExcel/Shared/String.php');

############

$inputFileName = $original_name.'.xls';

$objReader = new PHPExcel_Reader_Excel5(objPHPExcel); 
$objPHPExcel = $objReader->load($inputFileName);

PHPExcel_Shared_String::setDecimalSeparator('.');
PHPExcel_Shared_String::setThousandsSeparator('');


$objWriter = new PHPExcel_Writer_CSV($objPHPExcel);
$objWriter->setPreCalculateFormulas(false);
$objWriter->save($loader_name);

?>

Coordinator
Feb 29, 2012 at 4:52 PM

Would it be possible to upload the kaya_excel.xls file (or a sanitised version) to the uploaded file link or email it to me via the contact page

Feb 29, 2012 at 8:50 PM

Thanks, I uploaded the file there.  named the same thing.

-Alex

Coordinator
Feb 29, 2012 at 9:22 PM

Not able to replicate the problem at this point: the CSV file is being correctly generated.

Feb 29, 2012 at 9:26 PM

Using my code?

Thanks,

Coordinator
Feb 29, 2012 at 10:08 PM
phazedplasma wrote:

Using my code?

Thanks,


Right down to the

$objReader = new PHPExcel_Reader_Excel5(objPHPExcel);

which generates an error.... fortunately, instantiating a new PHPExcel_Reader_Excel5() object doesn't take any arguments, so this doesn't adversely affect the script execution in any way other than showing a warning. The file is still created successfully using both 1.7.6 and current SVN code.

 

Mar 7, 2012 at 3:29 PM

Actually got this working by putting adding this:

$objReader->setReadDataOnly(true); 

 

Thanks for your help!