Apostrophes and underscores

Topics: Developer Forum
Apr 13, 2010 at 7:52 AM

Hi! I'm working to include PHPExcel in our CMS. I'm stumped by what seems a minor quirk. Whenever I try to export a text that contains an apostrophe (like "I'm here") I get an underscore instead (like "I_m here"). This happens no matter which writer I use (e.g. both xls and csv files).

I'm using PHP 5.2.6 and the latest PHPExcel under Linux.

I don't see anything in my code that might provoke such a replacing of text. I would be grateful for any hints. Here's my code:

	// Create new PHPExcel object
	$objPHPExcel = new PHPExcel();
	// Set properties
	$objPHPExcel->getProperties()->setCreator("Sar-At ".SarelVersioneCompleta(true, $xls->versioneSarel));
	$objPHPExcel->getProperties()->setLastModifiedBy("Sar-At ".SarelVersioneCompleta(true, $xls->versioneSarel));
	$objPHPExcel->getProperties()->setSubject($xls->Database.' - '.$tabella);
	$objPHPExcel->getProperties()->setDescription($xls->Database.' - '.$tabella);
	// Add some data
	$xls->query ('SET NAMES utf8');
	// Export column names
	while ($xls->next_record()) {
		inc($row);// Empty to A, A to B, B to C, Z to AA etc.
		$colonne[] = $xls->f('fieldName');
		$objPHPExcel->getActiveSheet()->SetCellValue($row.'1',  $xls->f('fieldName'));
		array('fill' 	=> array(
									'type'		=> PHPExcel_Style_Fill::FILL_SOLID,
									'color'		=> array('argb' => 'FFD7D7E7')
	$xls->query ("SELECT * FROM `$tabella` ORDER BY id");
	$column = 2;
	while ($xls->next_record()) {
		reset ($colonne);
		while (list($key,$value) = each($colonne)) {
			$theField = $xls->f($value);
			$objPHPExcel->getActiveSheet()->SetCellValue($row.$column, $theField);
	// Rename sheet
Apr 17, 2010 at 3:17 PM

Nobody? I'll even accept and appreciate answers such as "not happening to me, recheck your own code" and non-definitive hints... Thanks in advance!

Apr 19, 2010 at 10:31 PM

Strange. I cannot reproduce this. Can you try to run this:

$excel = new PHPExcel();

$worksheet = $excel->getActiveSheet();
$worksheet->getCell('A1')->setValue("I'm here");

$writer = PHPExcel_IOFactory::createWriter($excel, 'Excel5');