Feature: Support for Extended and User-defined Workbook Properties in Excel2007 Writer

git-svn-id: https://phpexcel.svn.codeplex.com/svn/trunk@61018 2327b42d-5241-43d6-9e2a-de5ac946f064
This commit is contained in:
Mark Baker 2010-09-15 21:55:37 +00:00
parent c6a3679d77
commit 388d2c80d1
6 changed files with 114 additions and 21 deletions

View File

@ -242,6 +242,10 @@ class PHPExcel_Writer_Excel2007 implements PHPExcel_Writer_IWriter
// Add document properties to ZIP file // Add document properties to ZIP file
$objZip->addFromString('docProps/app.xml', $this->getWriterPart('DocProps')->writeDocPropsApp($this->_spreadSheet)); $objZip->addFromString('docProps/app.xml', $this->getWriterPart('DocProps')->writeDocPropsApp($this->_spreadSheet));
$objZip->addFromString('docProps/core.xml', $this->getWriterPart('DocProps')->writeDocPropsCore($this->_spreadSheet)); $objZip->addFromString('docProps/core.xml', $this->getWriterPart('DocProps')->writeDocPropsCore($this->_spreadSheet));
$customPropertiesPart = $this->getWriterPart('DocProps')->writeDocPropsCustom($this->_spreadSheet);
if (!is_null($customPropertiesPart)) {
$objZip->addFromString('docProps/custom.xml', $customPropertiesPart);
}
// Add theme to ZIP file // Add theme to ZIP file
$objZip->addFromString('xl/theme/theme1.xml', $this->getWriterPart('Theme')->writeTheme($this->_spreadSheet)); $objZip->addFromString('xl/theme/theme1.xml', $this->getWriterPart('Theme')->writeTheme($this->_spreadSheet));

View File

@ -98,6 +98,13 @@ class PHPExcel_Writer_Excel2007_ContentTypes extends PHPExcel_Writer_Excel2007_W
$objWriter, '/docProps/core.xml', 'application/vnd.openxmlformats-package.core-properties+xml' $objWriter, '/docProps/core.xml', 'application/vnd.openxmlformats-package.core-properties+xml'
); );
$customPropertyList = $pPHPExcel->getProperties()->getCustomProperties();
if (count($customPropertyList) > 0) {
$this->_writeOverrideContentType(
$objWriter, '/docProps/custom.xml', 'application/vnd.openxmlformats-officedocument.custom-properties+xml'
);
}
// Worksheets // Worksheets
$sheetCount = $pPHPExcel->getSheetCount(); $sheetCount = $pPHPExcel->getSheetCount();
for ($i = 0; $i < $sheetCount; ++$i) { for ($i = 0; $i < $sheetCount; ++$i) {

View File

@ -77,7 +77,6 @@ class PHPExcel_Writer_Excel2007_DocProps extends PHPExcel_Writer_Excel2007_Write
$objWriter->writeAttribute('size', '2'); $objWriter->writeAttribute('size', '2');
$objWriter->writeAttribute('baseType', 'variant'); $objWriter->writeAttribute('baseType', 'variant');
// Variant // Variant
$objWriter->startElement('vt:variant'); $objWriter->startElement('vt:variant');
$objWriter->writeElement('vt:lpstr', 'Worksheets'); $objWriter->writeElement('vt:lpstr', 'Worksheets');
@ -199,4 +198,75 @@ class PHPExcel_Writer_Excel2007_DocProps extends PHPExcel_Writer_Excel2007_Write
// Return // Return
return $objWriter->getData(); return $objWriter->getData();
} }
/**
* Write docProps/custom.xml to XML format
*
* @param PHPExcel $pPHPExcel
* @return string XML Output
* @throws Exception
*/
public function writeDocPropsCustom(PHPExcel $pPHPExcel = null)
{
$customPropertyList = $pPHPExcel->getProperties()->getCustomProperties();
if (count($customPropertyList) == 0) {
return;
}
// Create XML writer
$objWriter = null;
if ($this->getParentWriter()->getUseDiskCaching()) {
$objWriter = new PHPExcel_Shared_XMLWriter(PHPExcel_Shared_XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory());
} else {
$objWriter = new PHPExcel_Shared_XMLWriter(PHPExcel_Shared_XMLWriter::STORAGE_MEMORY);
}
// XML header
$objWriter->startDocument('1.0','UTF-8','yes');
// cp:coreProperties
$objWriter->startElement('Properties');
$objWriter->writeAttribute('xmlns', 'http://schemas.openxmlformats.org/officeDocument/2006/custom-properties');
$objWriter->writeAttribute('xmlns:vt', 'http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes');
foreach($customPropertyList as $key => $customProperty) {
$propertyValue = $pPHPExcel->getProperties()->getCustomPropertyValue($customProperty);
$propertyType = $pPHPExcel->getProperties()->getCustomPropertyType($customProperty);
$objWriter->startElement('property');
$objWriter->writeAttribute('fmtid', '{D5CDD505-2E9C-101B-9397-08002B2CF9AE}');
$objWriter->writeAttribute('pid', $key+2);
$objWriter->writeAttribute('name', $customProperty);
switch($propertyType) {
case 'i' :
$objWriter->writeElement('vt:i4', $propertyValue);
break;
case 'f' :
$objWriter->writeElement('vt:r8', $propertyValue);
break;
case 'b' :
$objWriter->writeElement('vt:bool', ($propertyValue) ? 'true' : 'false');
break;
case 'd' :
$objWriter->startElement('vt:filetime');
$objWriter->writeRaw(date(DATE_W3C, $propertyValue));
$objWriter->endElement();
break;
default :
$objWriter->writeElement('vt:lpwstr', $propertyValue);
break;
}
$objWriter->endElement();
}
$objWriter->endElement();
// Return
return $objWriter->getData();
}
} }

View File

@ -59,6 +59,18 @@ class PHPExcel_Writer_Excel2007_Rels extends PHPExcel_Writer_Excel2007_WriterPar
$objWriter->startElement('Relationships'); $objWriter->startElement('Relationships');
$objWriter->writeAttribute('xmlns', 'http://schemas.openxmlformats.org/package/2006/relationships'); $objWriter->writeAttribute('xmlns', 'http://schemas.openxmlformats.org/package/2006/relationships');
$customPropertyList = $pPHPExcel->getProperties()->getCustomProperties();
if (count($customPropertyList) > 0) {
// Relationship docProps/app.xml
$this->_writeRelationship(
$objWriter,
4,
'http://schemas.openxmlformats.org/officeDocument/2006/relationships/custom-properties',
'docProps/custom.xml'
);
}
// Relationship docProps/app.xml // Relationship docProps/app.xml
$this->_writeRelationship( $this->_writeRelationship(
$objWriter, $objWriter,

View File

@ -28,7 +28,7 @@ Fixed in SVN:
- Feature: (MBaker) Work item 8769 - Implement Gnumeric File Format - Feature: (MBaker) Work item 8769 - Implement Gnumeric File Format
Initial work on Gnumeric Reader (Worksheet Data, Document Properties and basic Formatting) Initial work on Gnumeric Reader (Worksheet Data, Document Properties and basic Formatting)
- Feature: (MBaker) Support for Extended Workbook Properties in Excel2007, Excel5 and OOCalc Readers; support for User-defined Workbook Properties in Excel2007 and OOCalc Readers - Feature: (MBaker) Support for Extended Workbook Properties in Excel2007, Excel5 and OOCalc Readers; support for User-defined Workbook Properties in Excel2007 and OOCalc Readers
- Feature: (MBaker) Support for Extended Workbook Properties in Excel2007 Writer - Feature: (MBaker) Support for Extended and User-defined Workbook Properties in Excel2007 Writer
- Feature: (MBaker) Provided a setGenerateSheetNavigationBlock(false); option to suppress generation of the sheet navigation block when writing multiple worksheets to HTML - Feature: (MBaker) Provided a setGenerateSheetNavigationBlock(false); option to suppress generation of the sheet navigation block when writing multiple worksheets to HTML
- Bugfix: (Progi1984) Workitem 7895 - Excel5 : Formula : Percent - Bugfix: (Progi1984) Workitem 7895 - Excel5 : Formula : Percent
- Bugfix: (MB) Work item 14143 - NA() doesn't propagate in matrix calc - quick fix in JAMA/Matrix.php - Bugfix: (MB) Work item 14143 - NA() doesn't propagate in matrix calc - quick fix in JAMA/Matrix.php