Various bugfixes including Excel2007 Writer order of font style elements to conform with Excel2003 using compatibility pack

This commit is contained in:
Mark Baker 2012-08-23 00:16:40 +01:00
parent 8c688358ba
commit 85eabc21aa
5 changed files with 48 additions and 39 deletions

View File

@ -110,13 +110,13 @@ class PHPExcel_Shared_File
if ( !function_exists('sys_get_temp_dir')) { if ( !function_exists('sys_get_temp_dir')) {
if ($temp = getenv('TMP') ) { if ($temp = getenv('TMP') ) {
if (file_exists($temp)) { return realpath($temp); } if ((!empty($temp)) && (file_exists($temp))) { return realpath($temp); }
} }
if ($temp = getenv('TEMP') ) { if ($temp = getenv('TEMP') ) {
if (file_exists($temp)) { return realpath($temp); } if ((!empty($temp)) && (file_exists($temp))) { return realpath($temp); }
} }
if ($temp = getenv('TMPDIR') ) { if ($temp = getenv('TMPDIR') ) {
if (file_exists($temp)) { return realpath($temp); } if ((!empty($temp)) && (file_exists($temp))) { return realpath($temp); }
} }
// trick for creating a file in system's temporary dir // trick for creating a file in system's temporary dir

View File

@ -253,6 +253,7 @@ class PHPExcel_Writer_Excel2007_Style extends PHPExcel_Writer_Excel2007_WriterPa
$objWriter->endElement(); $objWriter->endElement();
} }
if ($pFill->getFillType() !== PHPExcel_Style_Fill::FILL_SOLID) {
// bgColor // bgColor
if ($pFill->getEndColor()->getARGB()) { if ($pFill->getEndColor()->getARGB()) {
$objWriter->startElement('bgColor'); $objWriter->startElement('bgColor');
@ -260,6 +261,7 @@ class PHPExcel_Writer_Excel2007_Style extends PHPExcel_Writer_Excel2007_WriterPa
$objWriter->endElement(); $objWriter->endElement();
} }
} }
}
$objWriter->endElement(); $objWriter->endElement();
@ -277,20 +279,9 @@ class PHPExcel_Writer_Excel2007_Style extends PHPExcel_Writer_Excel2007_WriterPa
{ {
// font // font
$objWriter->startElement('font'); $objWriter->startElement('font');
// Weird! The order of these elements actually makes a difference when opening Excel2007
// Name // files in Excel2003 with the compatibility pack. It's not documented behaviour,
if ($pFont->getName() !== NULL) { // and makes for a real WTF!
$objWriter->startElement('name');
$objWriter->writeAttribute('val', $pFont->getName());
$objWriter->endElement();
}
// Size
if ($pFont->getSize() !== NULL) {
$objWriter->startElement('sz');
$objWriter->writeAttribute('val', $pFont->getSize());
$objWriter->endElement();
}
// Bold. We explicitly write this element also when false (like MS Office Excel 2007 does // Bold. We explicitly write this element also when false (like MS Office Excel 2007 does
// for conditional formatting). Otherwise it will apparently not be picked up in conditional // for conditional formatting). Otherwise it will apparently not be picked up in conditional
@ -308,6 +299,20 @@ class PHPExcel_Writer_Excel2007_Style extends PHPExcel_Writer_Excel2007_WriterPa
$objWriter->endElement(); $objWriter->endElement();
} }
// Strikethrough
if ($pFont->getStrikethrough() !== NULL) {
$objWriter->startElement('strike');
$objWriter->writeAttribute('val', $pFont->getStrikethrough() ? '1' : '0');
$objWriter->endElement();
}
// Underline
if ($pFont->getUnderline() !== NULL) {
$objWriter->startElement('u');
$objWriter->writeAttribute('val', $pFont->getUnderline());
$objWriter->endElement();
}
// Superscript / subscript // Superscript / subscript
if ($pFont->getSuperScript() === TRUE || $pFont->getSubScript() === TRUE) { if ($pFont->getSuperScript() === TRUE || $pFont->getSubScript() === TRUE) {
$objWriter->startElement('vertAlign'); $objWriter->startElement('vertAlign');
@ -319,17 +324,10 @@ class PHPExcel_Writer_Excel2007_Style extends PHPExcel_Writer_Excel2007_WriterPa
$objWriter->endElement(); $objWriter->endElement();
} }
// Underline // Size
if ($pFont->getUnderline() !== NULL) { if ($pFont->getSize() !== NULL) {
$objWriter->startElement('u'); $objWriter->startElement('sz');
$objWriter->writeAttribute('val', $pFont->getUnderline()); $objWriter->writeAttribute('val', $pFont->getSize());
$objWriter->endElement();
}
// Strikethrough
if ($pFont->getStrikethrough() !== NULL) {
$objWriter->startElement('strike');
$objWriter->writeAttribute('val', $pFont->getStrikethrough() ? '1' : '0');
$objWriter->endElement(); $objWriter->endElement();
} }
@ -340,6 +338,13 @@ class PHPExcel_Writer_Excel2007_Style extends PHPExcel_Writer_Excel2007_WriterPa
$objWriter->endElement(); $objWriter->endElement();
} }
// Name
if ($pFont->getName() !== NULL) {
$objWriter->startElement('name');
$objWriter->writeAttribute('val', $pFont->getName());
$objWriter->endElement();
}
$objWriter->endElement(); $objWriter->endElement();
} }

View File

@ -100,7 +100,7 @@ $objConditional2->setConditionType(PHPExcel_Style_Conditional::CONDITION_CELLIS)
->setOperatorType(PHPExcel_Style_Conditional::OPERATOR_LESSTHAN) ->setOperatorType(PHPExcel_Style_Conditional::OPERATOR_LESSTHAN)
->addCondition('0'); ->addCondition('0');
$objConditional2->getStyle()->getFont()->getColor()->setARGB(PHPExcel_Style_Color::COLOR_RED); $objConditional2->getStyle()->getFont()->getColor()->setARGB(PHPExcel_Style_Color::COLOR_RED);
$objConditional2->getStyle()->getFont()->setBold(true); $objConditional2->getStyle()->getFont()->setItalic(true);
$objConditional2->getStyle()->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_CURRENCY_EUR_SIMPLE); $objConditional2->getStyle()->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_CURRENCY_EUR_SIMPLE);
$objConditional3 = new PHPExcel_Style_Conditional(); $objConditional3 = new PHPExcel_Style_Conditional();
@ -108,7 +108,7 @@ $objConditional3->setConditionType(PHPExcel_Style_Conditional::CONDITION_CELLIS)
->setOperatorType(PHPExcel_Style_Conditional::OPERATOR_GREATERTHANOREQUAL) ->setOperatorType(PHPExcel_Style_Conditional::OPERATOR_GREATERTHANOREQUAL)
->addCondition('0'); ->addCondition('0');
$objConditional3->getStyle()->getFont()->getColor()->setARGB(PHPExcel_Style_Color::COLOR_GREEN); $objConditional3->getStyle()->getFont()->getColor()->setARGB(PHPExcel_Style_Color::COLOR_GREEN);
$objConditional3->getStyle()->getFont()->setBold(true); $objConditional3->getStyle()->getFont()->setItalic(true);
$objConditional3->getStyle()->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_CURRENCY_EUR_SIMPLE); $objConditional3->getStyle()->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_CURRENCY_EUR_SIMPLE);
$conditionalStyles = $objPHPExcel->getActiveSheet()->getStyle('B2')->getConditionalStyles(); $conditionalStyles = $objPHPExcel->getActiveSheet()->getStyle('B2')->getConditionalStyles();
@ -128,10 +128,10 @@ $objPHPExcel->getActiveSheet()->duplicateConditionalStyle(
// Set fonts // Set fonts
echo date('H:i:s') , " Set fonts" , EOL; echo date('H:i:s') , " Set fonts" , EOL;
$objPHPExcel->getActiveSheet()->getStyle('A1')->getFont()->setBold(true); $objPHPExcel->getActiveSheet()->getStyle('A1:B1')->getFont()->setBold(true);
$objPHPExcel->getActiveSheet()->getStyle('B1')->getFont()->setBold(true); //$objPHPExcel->getActiveSheet()->getStyle('B1')->getFont()->setBold(true);
$objPHPExcel->getActiveSheet()->getStyle('A7')->getFont()->setBold(true); $objPHPExcel->getActiveSheet()->getStyle('A7:B7')->getFont()->setBold(true);
$objPHPExcel->getActiveSheet()->getStyle('B7')->getFont()->setBold(true); //$objPHPExcel->getActiveSheet()->getStyle('B7')->getFont()->setBold(true);
// Set header and footer. When no different headers for odd/even are used, odd header is assumed. // Set header and footer. When no different headers for odd/even are used, odd header is assumed.

View File

@ -66,6 +66,8 @@ $aTests = array(
, '31docproperties_write.php' , '31docproperties_write.php'
, '31docproperties_write-xls.php' , '31docproperties_write-xls.php'
, '32chartreadwrite.php' , '32chartreadwrite.php'
, '33chartcreate.php'
, '34chartupdate.php'
, 'OOCalcReader.php' , 'OOCalcReader.php'
, 'SylkReader.php' , 'SylkReader.php'
, 'Excel2003XMLReader.php' , 'Excel2003XMLReader.php'

View File

@ -106,6 +106,8 @@ Fixed in develop branch:
- Bugfix: (MBaker) Work item 18145 - Autoshape being identified in twoCellAnchor when includeCharts is TRUE triggering load error - Bugfix: (MBaker) Work item 18145 - Autoshape being identified in twoCellAnchor when includeCharts is TRUE triggering load error
- Bugfix: (MBaker) Work item 18325 - v-type texts for series labels now recognised and parsed correctly - Bugfix: (MBaker) Work item 18325 - v-type texts for series labels now recognised and parsed correctly
- Bugfix: (wolf5x) Work item 18492 - load file failed if the file has no extensionType - Bugfix: (wolf5x) Work item 18492 - load file failed if the file has no extensionType
- Bugfix: (dverspui) Pattern fill colours in Excel2007 Style Writer
- Bugfix: (MBaker) Excel2007 Writer order of font style elements to conform with Excel2003 using compatibility pack
2012-05-19 (v1.7.7): 2012-05-19 (v1.7.7):