本文整理汇总了PHP中PHPExcel_Shared_XMLWriter::writeElement方法的典型用法代码示例。如果您正苦于以下问题:PHP PHPExcel_Shared_XMLWriter::writeElement方法的具体用法?PHP PHPExcel_Shared_XMLWriter::writeElement怎么用?PHP PHPExcel_Shared_XMLWriter::writeElement使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PHPExcel_Shared_XMLWriter
的用法示例。
在下文中一共展示了PHPExcel_Shared_XMLWriter::writeElement方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _writeCell
/**
* Write Cell
*
* @param PHPExcel_Shared_XMLWriter $objWriter XML Writer
* @param PHPExcel_Worksheet $pSheet Worksheet
* @param PHPExcel_Cell $pCell Cell
* @param string[] $pStringTable String table
* @param string[] $pFlippedStringTable String table (flipped), for faster index searching
* @throws Exception
*/
private function _writeCell(PHPExcel_Shared_XMLWriter $objWriter = null, PHPExcel_Worksheet $pSheet = null, PHPExcel_Cell $pCell = null, $pStringTable = null, $pFlippedStringTable = null)
{
if (is_array($pStringTable) && is_array($pFlippedStringTable)) {
// Cell
$objWriter->startElement('c');
$objWriter->writeAttribute('r', $pCell->getCoordinate());
// Sheet styles
$aStyles = $pSheet->getStyles();
if (isset($aStyles[$pCell->getCoordinate()])) {
$styleIndex = $this->getParentWriter()->getStylesHashTable()->getIndexForHashCode($aStyles[$pCell->getCoordinate()]->getHashCode());
if ($styleIndex != '') {
$objWriter->writeAttribute('s', $styleIndex);
}
}
// If cell value is supplied, write cell value
if (is_object($pCell->getValue()) || $pCell->getValue() !== '') {
// Map type
$mappedType = $pCell->getDataType();
// Write data type depending on its type
switch (strtolower($mappedType)) {
case 'inlinestr':
// Inline string
$objWriter->writeAttribute('t', $mappedType);
break;
case 's':
// String
$objWriter->writeAttribute('t', $mappedType);
break;
case 'b':
// Boolean
$objWriter->writeAttribute('t', $mappedType);
break;
case 'f':
// Formula
$calculatedValue = null;
if ($this->getParentWriter()->getPreCalculateFormulas()) {
$calculatedValue = $pCell->getCalculatedValue();
} else {
$calculatedValue = $pCell->getValue();
}
if (is_string($calculatedValue)) {
$objWriter->writeAttribute('t', 'str');
}
break;
}
// Write data depending on its type
switch (strtolower($mappedType)) {
case 'inlinestr':
// Inline string
if (!$pCell->getValue() instanceof PHPExcel_RichText) {
$objWriter->writeElement('t', PHPExcel_Shared_String::ControlCharacterPHP2OOXML($pCell->getValue()));
} else {
if ($pCell->getValue() instanceof PHPExcel_RichText) {
$objWriter->startElement('is');
$this->getParentWriter()->getWriterPart('stringtable')->writeRichText($objWriter, $pCell->getValue());
$objWriter->endElement();
}
}
break;
case 's':
// String
if (!$pCell->getValue() instanceof PHPExcel_RichText) {
if (isset($pFlippedStringTable[$pCell->getValue()])) {
$objWriter->writeElement('v', $pFlippedStringTable[$pCell->getValue()]);
}
} else {
if ($pCell->getValue() instanceof PHPExcel_RichText) {
$objWriter->writeElement('v', $pFlippedStringTable[$pCell->getValue()->getHashCode()]);
}
}
break;
case 'f':
// Formula
$objWriter->writeElement('f', substr($pCell->getValue(), 1));
if ($this->getParentWriter()->getOffice2003Compatibility() === false) {
if ($this->getParentWriter()->getPreCalculateFormulas()) {
$calculatedValue = $pCell->getCalculatedValue();
if (substr($calculatedValue, 0, 1) != '#') {
$objWriter->writeElement('v', $calculatedValue);
} else {
$objWriter->writeElement('v', '0');
}
} else {
$objWriter->writeElement('v', '0');
}
}
break;
case 'n':
// Numeric
if (PHPExcel_Shared_Date::isDateTime($pCell)) {
//.........这里部分代码省略.........
示例2: write
public static function write(PHPExcel_Shared_XMLWriter $objWriter, PHPExcel_Cell $cell)
{
$comments = $cell->getWorksheet()->getComments();
if (! isset($comments[$cell->getCoordinate()])) {
return;
}
$comment = $comments[$cell->getCoordinate()];
$objWriter->startElement('office:annotation');
// $objWriter->writeAttribute('draw:style-name', 'gr1');
// $objWriter->writeAttribute('draw:text-style-name', 'P1');
$objWriter->writeAttribute('svg:width', $comment->getWidth());
$objWriter->writeAttribute('svg:height', $comment->getHeight());
$objWriter->writeAttribute('svg:x', $comment->getMarginLeft());
$objWriter->writeAttribute('svg:y', $comment->getMarginTop());
// $objWriter->writeAttribute('draw:caption-point-x', $comment->getMarginLeft());
// $objWriter->writeAttribute('draw:caption-point-y', $comment->getMarginTop());
$objWriter->writeElement('dc:creator', $comment->getAuthor());
// TODO: Not realized in PHPExcel_Comment yet.
// $objWriter->writeElement('dc:date', $comment->getDate());
$objWriter->writeElement('text:p', $comment->getText()
->getPlainText());
// $objWriter->writeAttribute('draw:text-style-name', 'P1');
$objWriter->endElement();
}
示例3: write
/**
* Write styles.xml to XML format
*
* @param PHPExcel $pPHPExcel
* @return string XML Output
* @throws PHPExcel_Writer_Exception
*/
public function write(PHPExcel $pPHPExcel = null)
{
if (!$pPHPExcel) {
$pPHPExcel = $this->getParentWriter()->getPHPExcel();
}
$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');
// Content
$objWriter->startElement('office:document-styles');
$objWriter->writeAttribute('xmlns:office', 'urn:oasis:names:tc:opendocument:xmlns:office:1.0');
$objWriter->writeAttribute('xmlns:style', 'urn:oasis:names:tc:opendocument:xmlns:style:1.0');
$objWriter->writeAttribute('xmlns:text', 'urn:oasis:names:tc:opendocument:xmlns:text:1.0');
$objWriter->writeAttribute('xmlns:table', 'urn:oasis:names:tc:opendocument:xmlns:table:1.0');
$objWriter->writeAttribute('xmlns:draw', 'urn:oasis:names:tc:opendocument:xmlns:drawing:1.0');
$objWriter->writeAttribute('xmlns:fo', 'urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0');
$objWriter->writeAttribute('xmlns:xlink', 'http://www.w3.org/1999/xlink');
$objWriter->writeAttribute('xmlns:dc', 'http://purl.org/dc/elements/1.1/');
$objWriter->writeAttribute('xmlns:meta', 'urn:oasis:names:tc:opendocument:xmlns:meta:1.0');
$objWriter->writeAttribute('xmlns:number', 'urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0');
$objWriter->writeAttribute('xmlns:presentation', 'urn:oasis:names:tc:opendocument:xmlns:presentation:1.0');
$objWriter->writeAttribute('xmlns:svg', 'urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0');
$objWriter->writeAttribute('xmlns:chart', 'urn:oasis:names:tc:opendocument:xmlns:chart:1.0');
$objWriter->writeAttribute('xmlns:dr3d', 'urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0');
$objWriter->writeAttribute('xmlns:math', 'http://www.w3.org/1998/Math/MathML');
$objWriter->writeAttribute('xmlns:form', 'urn:oasis:names:tc:opendocument:xmlns:form:1.0');
$objWriter->writeAttribute('xmlns:script', 'urn:oasis:names:tc:opendocument:xmlns:script:1.0');
$objWriter->writeAttribute('xmlns:ooo', 'http://openoffice.org/2004/office');
$objWriter->writeAttribute('xmlns:ooow', 'http://openoffice.org/2004/writer');
$objWriter->writeAttribute('xmlns:oooc', 'http://openoffice.org/2004/calc');
$objWriter->writeAttribute('xmlns:dom', 'http://www.w3.org/2001/xml-events');
$objWriter->writeAttribute('xmlns:rpt', 'http://openoffice.org/2005/report');
$objWriter->writeAttribute('xmlns:of', 'urn:oasis:names:tc:opendocument:xmlns:of:1.2');
$objWriter->writeAttribute('xmlns:xhtml', 'http://www.w3.org/1999/xhtml');
$objWriter->writeAttribute('xmlns:grddl', 'http://www.w3.org/2003/g/data-view#');
$objWriter->writeAttribute('xmlns:tableooo', 'http://openoffice.org/2009/table');
$objWriter->writeAttribute('xmlns:css3t', 'http://www.w3.org/TR/css3-text/');
$objWriter->writeAttribute('office:version', '1.2');
$objWriter->writeElement('office:font-face-decls');
$objWriter->writeElement('office:styles');
$objWriter->writeElement('office:automatic-styles');
$objWriter->writeElement('office:master-styles');
$objWriter->endElement();
return $objWriter->getData();
}
示例4: write
/**
* Write meta.xml to XML format
*
* @param PHPExcel $pPHPExcel
* @return string XML Output
* @throws PHPExcel_Writer_Exception
*/
public function write(PHPExcel $pPHPExcel = null)
{
if (!$pPHPExcel) {
$pPHPExcel = $this->getParentWriter()->getPHPExcel();
}
$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');
// Meta
$objWriter->startElement('office:document-meta');
$objWriter->writeAttribute('xmlns:office', 'urn:oasis:names:tc:opendocument:xmlns:office:1.0');
$objWriter->writeAttribute('xmlns:xlink', 'http://www.w3.org/1999/xlink');
$objWriter->writeAttribute('xmlns:dc', 'http://purl.org/dc/elements/1.1/');
$objWriter->writeAttribute('xmlns:meta', 'urn:oasis:names:tc:opendocument:xmlns:meta:1.0');
$objWriter->writeAttribute('xmlns:ooo', 'http://openoffice.org/2004/office');
$objWriter->writeAttribute('xmlns:grddl', 'http://www.w3.org/2003/g/data-view#');
$objWriter->writeAttribute('office:version', '1.2');
$objWriter->startElement('office:meta');
$objWriter->writeElement('meta:initial-creator', $pPHPExcel->getProperties()->getCreator());
$objWriter->writeElement('dc:creator', $pPHPExcel->getProperties()->getCreator());
$objWriter->writeElement('meta:creation-date', date(DATE_W3C, $pPHPExcel->getProperties()->getCreated()));
$objWriter->writeElement('dc:date', date(DATE_W3C, $pPHPExcel->getProperties()->getCreated()));
$objWriter->writeElement('dc:title', $pPHPExcel->getProperties()->getTitle());
$objWriter->writeElement('dc:description', $pPHPExcel->getProperties()->getDescription());
$objWriter->writeElement('dc:subject', $pPHPExcel->getProperties()->getSubject());
$keywords = explode(' ', $pPHPExcel->getProperties()->getKeywords());
foreach ($keywords as $keyword) {
$objWriter->writeElement('meta:keyword', $keyword);
}
//<meta:document-statistic meta:table-count="XXX" meta:cell-count="XXX" meta:object-count="XXX"/>
$objWriter->startElement('meta:user-defined');
$objWriter->writeAttribute('meta:name', 'Company');
$objWriter->writeRaw($pPHPExcel->getProperties()->getCompany());
$objWriter->endElement();
$objWriter->startElement('meta:user-defined');
$objWriter->writeAttribute('meta:name', 'category');
$objWriter->writeRaw($pPHPExcel->getProperties()->getCategory());
$objWriter->endElement();
$objWriter->endElement();
$objWriter->endElement();
return $objWriter->getData();
}
示例5: writeTheme
//.........这里部分代码省略.........
// a:shade
$objWriter->startElement('a:shade');
$objWriter->writeAttribute('val', '99000');
$objWriter->endElement();
// a:satMod
$objWriter->startElement('a:satMod');
$objWriter->writeAttribute('val', '350000');
$objWriter->endElement();
$objWriter->endElement();
$objWriter->endElement();
// a:gs
$objWriter->startElement('a:gs');
$objWriter->writeAttribute('pos', '100000');
// a:schemeClr
$objWriter->startElement('a:schemeClr');
$objWriter->writeAttribute('val', 'phClr');
// a:shade
$objWriter->startElement('a:shade');
$objWriter->writeAttribute('val', '20000');
$objWriter->endElement();
// a:satMod
$objWriter->startElement('a:satMod');
$objWriter->writeAttribute('val', '255000');
$objWriter->endElement();
$objWriter->endElement();
$objWriter->endElement();
$objWriter->endElement();
// a:path
$objWriter->startElement('a:path');
$objWriter->writeAttribute('path', 'circle');
// a:fillToRect
$objWriter->startElement('a:fillToRect');
$objWriter->writeAttribute('l', '50000');
$objWriter->writeAttribute('t', '-80000');
$objWriter->writeAttribute('r', '50000');
$objWriter->writeAttribute('b', '180000');
$objWriter->endElement();
$objWriter->endElement();
$objWriter->endElement();
// a:gradFill
$objWriter->startElement('a:gradFill');
$objWriter->writeAttribute('rotWithShape', '1');
// a:gsLst
$objWriter->startElement('a:gsLst');
// a:gs
$objWriter->startElement('a:gs');
$objWriter->writeAttribute('pos', '0');
// a:schemeClr
$objWriter->startElement('a:schemeClr');
$objWriter->writeAttribute('val', 'phClr');
// a:tint
$objWriter->startElement('a:tint');
$objWriter->writeAttribute('val', '80000');
$objWriter->endElement();
// a:satMod
$objWriter->startElement('a:satMod');
$objWriter->writeAttribute('val', '300000');
$objWriter->endElement();
$objWriter->endElement();
$objWriter->endElement();
// a:gs
$objWriter->startElement('a:gs');
$objWriter->writeAttribute('pos', '100000');
// a:schemeClr
$objWriter->startElement('a:schemeClr');
$objWriter->writeAttribute('val', 'phClr');
// a:shade
$objWriter->startElement('a:shade');
$objWriter->writeAttribute('val', '30000');
$objWriter->endElement();
// a:satMod
$objWriter->startElement('a:satMod');
$objWriter->writeAttribute('val', '200000');
$objWriter->endElement();
$objWriter->endElement();
$objWriter->endElement();
$objWriter->endElement();
// a:path
$objWriter->startElement('a:path');
$objWriter->writeAttribute('path', 'circle');
// a:fillToRect
$objWriter->startElement('a:fillToRect');
$objWriter->writeAttribute('l', '50000');
$objWriter->writeAttribute('t', '50000');
$objWriter->writeAttribute('r', '50000');
$objWriter->writeAttribute('b', '50000');
$objWriter->endElement();
$objWriter->endElement();
$objWriter->endElement();
$objWriter->endElement();
$objWriter->endElement();
$objWriter->endElement();
// a:objectDefaults
$objWriter->writeElement('a:objectDefaults', null);
// a:extraClrSchemeLst
$objWriter->writeElement('a:extraClrSchemeLst', null);
$objWriter->endElement();
// Return
return $objWriter->getData();
}
示例6: writeDocPropsCore
/**
* Write docProps/core.xml to XML format
*
* @param PHPExcel $pPHPExcel
* @return string XML Output
* @throws Exception
*/
public function writeDocPropsCore(PHPExcel $pPHPExcel = null)
{
// 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('cp:coreProperties');
$objWriter->writeAttribute('xmlns:cp', 'http://schemas.openxmlformats.org/package/2006/metadata/core-properties');
$objWriter->writeAttribute('xmlns:dc', 'http://purl.org/dc/elements/1.1/');
$objWriter->writeAttribute('xmlns:dcterms', 'http://purl.org/dc/terms/');
$objWriter->writeAttribute('xmlns:dcmitype', 'http://purl.org/dc/dcmitype/');
$objWriter->writeAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance');
// dc:creator
$objWriter->writeElement('dc:creator', $pPHPExcel->getProperties()->getCreator());
// cp:lastModifiedBy
$objWriter->writeElement('cp:lastModifiedBy', $pPHPExcel->getProperties()->getLastModifiedBy());
// dcterms:created
$objWriter->startElement('dcterms:created');
$objWriter->writeAttribute('xsi:type', 'dcterms:W3CDTF');
$objWriter->writeRaw(date(DATE_W3C, $pPHPExcel->getProperties()->getCreated()));
$objWriter->endElement();
// dcterms:modified
$objWriter->startElement('dcterms:modified');
$objWriter->writeAttribute('xsi:type', 'dcterms:W3CDTF');
$objWriter->writeRaw(date(DATE_W3C, $pPHPExcel->getProperties()->getModified()));
$objWriter->endElement();
// dc:title
$objWriter->writeElement('dc:title', $pPHPExcel->getProperties()->getTitle());
// dc:description
$objWriter->writeElement('dc:description', $pPHPExcel->getProperties()->getDescription());
// dc:subject
$objWriter->writeElement('dc:subject', $pPHPExcel->getProperties()->getSubject());
// cp:keywords
$objWriter->writeElement('cp:keywords', $pPHPExcel->getProperties()->getKeywords());
// cp:category
$objWriter->writeElement('cp:category', $pPHPExcel->getProperties()->getCategory());
$objWriter->endElement();
// Return
return $objWriter->getData();
}
示例7: _writeCell
/**
* Write Cell
*
* @param PHPExcel_Shared_XMLWriter $objWriter XML Writer
* @param PHPExcel_Worksheet $pSheet Worksheet
* @param PHPExcel_Cell $pCell Cell
* @param string[] $pStringTable String table
* @param string[] $pFlippedStringTable String table (flipped), for faster index searching
* @throws Exception
*/
private function _writeCell(PHPExcel_Shared_XMLWriter $objWriter = null, PHPExcel_Worksheet $pSheet = null, PHPExcel_Cell $pCell = null, $pStringTable = null, $pFlippedStringTable = null)
{
if (is_array($pStringTable) && is_array($pFlippedStringTable)) {
// Cell
$objWriter->startElement('c');
$objWriter->writeAttribute('r', $pCell->getCoordinate());
// Sheet styles
if ($pCell->getXfIndex() != '') {
$objWriter->writeAttribute('s', $pCell->getXfIndex());
}
// If cell value is supplied, write cell value
if (is_object($pCell->getValue()) || $pCell->getValue() !== '') {
// Map type
$mappedType = $pCell->getDataType();
// Write data type depending on its type
switch (strtolower($mappedType)) {
case 'inlinestr':
// Inline string
$objWriter->writeAttribute('t', $mappedType);
break;
case 's':
// String
$objWriter->writeAttribute('t', $mappedType);
break;
case 'b':
// Boolean
$objWriter->writeAttribute('t', $mappedType);
break;
case 'f':
// Formula
$calculatedValue = null;
if ($this->getParentWriter()->getPreCalculateFormulas()) {
$calculatedValue = $pCell->getCalculatedValue();
} else {
$calculatedValue = $pCell->getValue();
}
if (is_string($calculatedValue)) {
$objWriter->writeAttribute('t', 'str');
}
break;
case 'e':
// Error
$objWriter->writeAttribute('t', $mappedType);
}
// Write data depending on its type
switch (strtolower($mappedType)) {
case 'inlinestr':
// Inline string
if (!$pCell->getValue() instanceof PHPExcel_RichText) {
$objWriter->writeElement('t', PHPExcel_Shared_String::ControlCharacterPHP2OOXML(htmlspecialchars($pCell->getValue())));
} else {
if ($pCell->getValue() instanceof PHPExcel_RichText) {
$objWriter->startElement('is');
$this->getParentWriter()->getWriterPart('stringtable')->writeRichText($objWriter, $pCell->getValue());
$objWriter->endElement();
}
}
break;
case 's':
// String
if (!$pCell->getValue() instanceof PHPExcel_RichText) {
if (isset($pFlippedStringTable[$pCell->getValue()])) {
$objWriter->writeElement('v', $pFlippedStringTable[$pCell->getValue()]);
}
} else {
if ($pCell->getValue() instanceof PHPExcel_RichText) {
$objWriter->writeElement('v', $pFlippedStringTable[$pCell->getValue()->getHashCode()]);
}
}
break;
case 'f':
// Formula
$objWriter->writeElement('f', substr($pCell->getValue(), 1));
if ($this->getParentWriter()->getOffice2003Compatibility() === false) {
if ($this->getParentWriter()->getPreCalculateFormulas()) {
$calculatedValue = $pCell->getCalculatedValue();
if (!is_array($calculatedValue) && substr($calculatedValue, 0, 1) != '#') {
$v = PHPExcel_Shared_String::FormatNumber($calculatedValue);
$objWriter->writeElement('v', $v);
} else {
$objWriter->writeElement('v', '0');
}
} else {
$objWriter->writeElement('v', '0');
}
}
break;
case 'n':
// Numeric
// force point as decimal separator in case current locale uses comma
//.........这里部分代码省略.........
示例8: writeStringTable
/**
* Write string table to XML format
*
* @param string[] $pStringTable
* @return string XML Output
* @throws Exception
*/
public function writeStringTable($pStringTable = null)
{
if (!is_null($pStringTable)) {
// Create XML writer
$objWriter = null;
if ($this->getParentWriter()->getUseDiskCaching()) {
$objWriter = new PHPExcel_Shared_XMLWriter(PHPExcel_Shared_XMLWriter::STORAGE_DISK);
} else {
$objWriter = new PHPExcel_Shared_XMLWriter(PHPExcel_Shared_XMLWriter::STORAGE_MEMORY);
}
// XML header
$objWriter->startDocument('1.0', 'UTF-8', 'yes');
// String table
$objWriter->startElement('sst');
$objWriter->writeAttribute('xmlns', 'http://schemas.openxmlformats.org/spreadsheetml/2006/main');
$objWriter->writeAttribute('uniqueCount', count($pStringTable));
// Loop trough string table
foreach ($pStringTable as $textElement) {
$objWriter->startElement('si');
if (!$textElement instanceof PHPExcel_RichText) {
$objWriter->writeElement('t', PHPExcel_Shared_String::ControlCharacterPHP2OOXML($textElement));
} else {
if ($textElement instanceof PHPExcel_RichText) {
$this->writeRichText($objWriter, $textElement);
}
}
$objWriter->endElement();
}
$objWriter->endElement();
// Return
return $objWriter->getData();
} else {
throw new Exception("Invalid string table array passed.");
}
}
示例9: _writeVMLComment
/**
* Write VML comment to XML format
*
* @param PHPExcel_Shared_XMLWriter $objWriter XML Writer
* @param string $pCellReference Cell reference
* @param PHPExcel_Comment $pComment Comment
* @throws Exception
*/
public function _writeVMLComment(PHPExcel_Shared_XMLWriter $objWriter = null, $pCellReference = 'A1', PHPExcel_Comment $pComment = null)
{
// Metadata
list($column, $row) = PHPExcel_Cell::coordinateFromString($pCellReference);
$column = PHPExcel_Cell::columnIndexFromString($column);
$id = 1024 + $column + $row;
$id = substr($id, 0, 4);
// v:shape
$objWriter->startElement('v:shape');
$objWriter->writeAttribute('id', '_x0000_s' . $id);
$objWriter->writeAttribute('type', '#_x0000_t202');
$objWriter->writeAttribute('style', 'position:absolute;margin-left:' . $pComment->getMarginLeft() . ';margin-top:' . $pComment->getMarginTop() . ';width:' . $pComment->getWidth() . ';height:' . $pComment->getHeight() . ';z-index:1;visibility:' . ($pComment->getVisible() ? 'visible' : 'hidden'));
$objWriter->writeAttribute('fillcolor', '#' . $pComment->getFillColor()->getRGB());
$objWriter->writeAttribute('o:insetmode', 'auto');
// v:fill
$objWriter->startElement('v:fill');
$objWriter->writeAttribute('color2', '#' . $pComment->getFillColor()->getRGB());
$objWriter->endElement();
// v:shadow
$objWriter->startElement('v:shadow');
$objWriter->writeAttribute('on', 't');
$objWriter->writeAttribute('color', 'black');
$objWriter->writeAttribute('obscured', 't');
$objWriter->endElement();
// v:path
$objWriter->startElement('v:path');
$objWriter->writeAttribute('o:connecttype', 'none');
$objWriter->endElement();
// v:textbox
$objWriter->startElement('v:textbox');
$objWriter->writeAttribute('style', 'mso-direction-alt:auto');
// div
$objWriter->startElement('div');
$objWriter->writeAttribute('style', 'text-align:left');
$objWriter->endElement();
$objWriter->endElement();
// x:ClientData
$objWriter->startElement('x:ClientData');
$objWriter->writeAttribute('ObjectType', 'Note');
// x:MoveWithCells
$objWriter->writeElement('x:MoveWithCells', '');
// x:SizeWithCells
$objWriter->writeElement('x:SizeWithCells', '');
// x:Anchor
//$objWriter->writeElement('x:Anchor', $column . ', 15, ' . ($row - 2) . ', 10, ' . ($column + 4) . ', 15, ' . ($row + 5) . ', 18');
// x:AutoFill
$objWriter->writeElement('x:AutoFill', 'False');
// x:Row
$objWriter->writeElement('x:Row', $row - 1);
// x:Column
$objWriter->writeElement('x:Column', $column - 1);
$objWriter->endElement();
$objWriter->endElement();
}
示例10: _writeDrawing
/**
* Write drawings to XML format
*
* @param PHPExcel_Shared_XMLWriter $objWriter XML Writer
* @param PHPExcel_Worksheet_BaseDrawing $pDrawing
* @param int $pRelationId
* @throws PHPExcel_Writer_Exception
*/
public function _writeDrawing(PHPExcel_Shared_XMLWriter $objWriter = null, PHPExcel_Worksheet_BaseDrawing $pDrawing = null, $pRelationId = -1)
{
if ($pRelationId >= 0) {
// xdr:oneCellAnchor
$objWriter->startElement('xdr:oneCellAnchor');
// Image location
$aCoordinates = PHPExcel_Cell::coordinateFromString($pDrawing->getCoordinates());
$aCoordinates[0] = PHPExcel_Cell::columnIndexFromString($aCoordinates[0]);
// xdr:from
$objWriter->startElement('xdr:from');
$objWriter->writeElement('xdr:col', $aCoordinates[0] - 1);
$objWriter->writeElement('xdr:colOff', PHPExcel_Shared_Drawing::pixelsToEMU($pDrawing->getOffsetX()));
$objWriter->writeElement('xdr:row', $aCoordinates[1] - 1);
$objWriter->writeElement('xdr:rowOff', PHPExcel_Shared_Drawing::pixelsToEMU($pDrawing->getOffsetY()));
$objWriter->endElement();
// xdr:ext
$objWriter->startElement('xdr:ext');
$objWriter->writeAttribute('cx', PHPExcel_Shared_Drawing::pixelsToEMU($pDrawing->getWidth()));
$objWriter->writeAttribute('cy', PHPExcel_Shared_Drawing::pixelsToEMU($pDrawing->getHeight()));
$objWriter->endElement();
// xdr:pic
$objWriter->startElement('xdr:pic');
// xdr:nvPicPr
$objWriter->startElement('xdr:nvPicPr');
// xdr:cNvPr
$objWriter->startElement('xdr:cNvPr');
$objWriter->writeAttribute('id', $pRelationId);
$objWriter->writeAttribute('name', $pDrawing->getName());
$objWriter->writeAttribute('descr', $pDrawing->getDescription());
$objWriter->endElement();
// xdr:cNvPicPr
$objWriter->startElement('xdr:cNvPicPr');
// a:picLocks
$objWriter->startElement('a:picLocks');
$objWriter->writeAttribute('noChangeAspect', '1');
$objWriter->endElement();
$objWriter->endElement();
$objWriter->endElement();
// xdr:blipFill
$objWriter->startElement('xdr:blipFill');
// a:blip
$objWriter->startElement('a:blip');
$objWriter->writeAttribute('xmlns:r', 'http://schemas.openxmlformats.org/officeDocument/2006/relationships');
$objWriter->writeAttribute('r:embed', 'rId' . $pRelationId);
$objWriter->endElement();
// a:stretch
$objWriter->startElement('a:stretch');
$objWriter->writeElement('a:fillRect', null);
$objWriter->endElement();
$objWriter->endElement();
// xdr:spPr
$objWriter->startElement('xdr:spPr');
// a:xfrm
$objWriter->startElement('a:xfrm');
$objWriter->writeAttribute('rot', PHPExcel_Shared_Drawing::degreesToAngle($pDrawing->getRotation()));
$objWriter->endElement();
// a:prstGeom
$objWriter->startElement('a:prstGeom');
$objWriter->writeAttribute('prst', 'rect');
// a:avLst
$objWriter->writeElement('a:avLst', null);
$objWriter->endElement();
// // a:solidFill
// $objWriter->startElement('a:solidFill');
// // a:srgbClr
// $objWriter->startElement('a:srgbClr');
// $objWriter->writeAttribute('val', 'FFFFFF');
///* SHADE
// // a:shade
// $objWriter->startElement('a:shade');
// $objWriter->writeAttribute('val', '85000');
// $objWriter->endElement();
//*/
// $objWriter->endElement();
// $objWriter->endElement();
/*
// a:ln
$objWriter->startElement('a:ln');
$objWriter->writeAttribute('w', '88900');
$objWriter->writeAttribute('cap', 'sq');
// a:solidFill
$objWriter->startElement('a:solidFill');
// a:srgbClr
$objWriter->startElement('a:srgbClr');
$objWriter->writeAttribute('val', 'FFFFFF');
$objWriter->endElement();
$objWriter->endElement();
// a:miter
//.........这里部分代码省略.........
示例11: writeDocPropsCustom
/**
* Write docProps/custom.xml to XML format
*
* @param PHPExcel $pPHPExcel
*
* @return string XML Output
* @throws PHPExcel_Writer_Exception
*/
public function writeDocPropsCustom(PHPExcel $pPHPExcel = null)
{
$customPropertyList = $pPHPExcel->getProperties()->getCustomProperties();
if (empty($customPropertyList)) {
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->writeRawData(date(DATE_W3C, $propertyValue));
$objWriter->endElement();
break;
default:
$objWriter->writeElement('vt:lpwstr', $propertyValue);
break;
}
$objWriter->endElement();
}
$objWriter->endElement();
// Return
return $objWriter->getData();
}
示例12: _writeChart
/**
* Write drawings to XML format
*
* @param PHPExcel_Shared_XMLWriter $objWriter XML Writer
* @param PHPExcel_Chart $pChart
* @param int $pRelationId
*
* @throws PHPExcel_Writer_Exception
*/
public function _writeChart(PHPExcel_Shared_XMLWriter $objWriter = null, PHPExcel_Chart $pChart = null, $pRelationId = -1)
{
$tl = $pChart->getTopLeftPosition();
$tl['colRow'] = PHPExcel_Cell::coordinateFromString($tl['cell']);
$br = $pChart->getBottomRightPosition();
$br['colRow'] = PHPExcel_Cell::coordinateFromString($br['cell']);
$objWriter->startElement('xdr:twoCellAnchor');
$objWriter->startElement('xdr:from');
$objWriter->writeElement('xdr:col', PHPExcel_Cell::columnIndexFromString($tl['colRow'][0]) - 1);
$objWriter->writeElement('xdr:colOff', PHPExcel_Shared_Drawing::pixelsToEMU($tl['xOffset']));
$objWriter->writeElement('xdr:row', $tl['colRow'][1] - 1);
$objWriter->writeElement('xdr:rowOff', PHPExcel_Shared_Drawing::pixelsToEMU($tl['yOffset']));
$objWriter->endElement();
$objWriter->startElement('xdr:to');
$objWriter->writeElement('xdr:col', PHPExcel_Cell::columnIndexFromString($br['colRow'][0]) - 1);
$objWriter->writeElement('xdr:colOff', PHPExcel_Shared_Drawing::pixelsToEMU($br['xOffset']));
$objWriter->writeElement('xdr:row', $br['colRow'][1] - 1);
$objWriter->writeElement('xdr:rowOff', PHPExcel_Shared_Drawing::pixelsToEMU($br['yOffset']));
$objWriter->endElement();
$objWriter->startElement('xdr:graphicFrame');
$objWriter->writeAttribute('macro', '');
$objWriter->startElement('xdr:nvGraphicFramePr');
$objWriter->startElement('xdr:cNvPr');
$objWriter->writeAttribute('name', 'Chart ' . $pRelationId);
$objWriter->writeAttribute('id', 1025 * $pRelationId);
$objWriter->endElement();
$objWriter->startElement('xdr:cNvGraphicFramePr');
$objWriter->startElement('a:graphicFrameLocks');
$objWriter->endElement();
$objWriter->endElement();
$objWriter->endElement();
$objWriter->startElement('xdr:xfrm');
$objWriter->startElement('a:off');
$objWriter->writeAttribute('x', '0');
$objWriter->writeAttribute('y', '0');
$objWriter->endElement();
$objWriter->startElement('a:ext');
$objWriter->writeAttribute('cx', '0');
$objWriter->writeAttribute('cy', '0');
$objWriter->endElement();
$objWriter->endElement();
$objWriter->startElement('a:graphic');
$objWriter->startElement('a:graphicData');
$objWriter->writeAttribute('uri', 'http://schemas.openxmlformats.org/drawingml/2006/chart');
$objWriter->startElement('c:chart');
$objWriter->writeAttribute('xmlns:c', 'http://schemas.openxmlformats.org/drawingml/2006/chart');
$objWriter->writeAttribute('xmlns:r', 'http://schemas.openxmlformats.org/officeDocument/2006/relationships');
$objWriter->writeAttribute('r:id', 'rId' . $pRelationId);
$objWriter->endElement();
$objWriter->endElement();
$objWriter->endElement();
$objWriter->endElement();
$objWriter->startElement('xdr:clientData');
$objWriter->endElement();
$objWriter->endElement();
}
示例13: _writeCellSpan
/**
* Write span
*
* @param PHPExcel_Shared_XMLWriter $objWriter
* @param integer $curColumn
* @param integer $prevColumn
*/
private function _writeCellSpan(PHPExcel_Shared_XMLWriter $objWriter, $curColumn, $prevColumn)
{
$diff = $curColumn - $prevColumn - 1;
if (1 === $diff) {
$objWriter->writeElement('table:table-cell');
} elseif ($diff > 1) {
$objWriter->startElement('table:table-cell');
$objWriter->writeAttribute('table:number-columns-repeated', $diff);
$objWriter->endElement();
}
}
示例14: _writeVMLComment
/**
* Write VML comment to XML format
*
* @param PHPExcel_Worksheet $pWorksheet
* @param PHPExcel_Shared_XMLWriter $objWriter XML Writer
* @param string $pCellReference Cell reference
* @param PHPExcel_Comment $pComment Comment
* @throws PHPExcel_Writer_Exception
*/
public function _writeVMLComment(PHPExcel_Worksheet $pWorksheet = null, PHPExcel_Shared_XMLWriter $objWriter = null, $pCellReference = 'A1', PHPExcel_Comment $pComment = null)
{
// Metadata
list($column, $row) = PHPExcel_Cell::coordinateFromString($pCellReference);
$column = PHPExcel_Cell::columnIndexFromString($column);
$id = 1024 + $column + $row;
$id = substr($id, 0, 4);
$cssWidth = $pComment->getWidth();
$cssHeight = $pComment->getHeight();
// v:shape
$objWriter->startElement('v:shape');
$objWriter->writeAttribute('id', '_x0000_s' . $id);
$objWriter->writeAttribute('type', '#_x0000_t202');
$objWriter->writeAttribute('style', 'position:absolute;margin-left:' . $pComment->getMarginLeft() . ';margin-top:' . $pComment->getMarginTop() . ';width:' . $cssWidth . ';height:' . $cssHeight . ';z-index:1;visibility:' . ($pComment->getVisible() ? 'visible' : 'hidden'));
$objWriter->writeAttribute('fillcolor', '#' . $pComment->getFillColor()->getRGB());
$objWriter->writeAttribute('o:insetmode', 'auto');
// v:fill
$objWriter->startElement('v:fill');
$objWriter->writeAttribute('color2', '#' . $pComment->getFillColor()->getRGB());
$objWriter->endElement();
// v:shadow
$objWriter->startElement('v:shadow');
$objWriter->writeAttribute('on', 't');
$objWriter->writeAttribute('color', 'black');
$objWriter->writeAttribute('obscured', 't');
$objWriter->endElement();
// v:path
$objWriter->startElement('v:path');
$objWriter->writeAttribute('o:connecttype', 'none');
$objWriter->endElement();
// v:textbox
$objWriter->startElement('v:textbox');
$objWriter->writeAttribute('style', 'mso-direction-alt:auto');
// div
$objWriter->startElement('div');
$objWriter->writeAttribute('style', 'text-align:left');
$objWriter->endElement();
$objWriter->endElement();
// x:ClientData
$objWriter->startElement('x:ClientData');
$objWriter->writeAttribute('ObjectType', 'Note');
// x:MoveWithCells
$objWriter->writeElement('x:MoveWithCells', '');
// x:SizeWithCells
$objWriter->writeElement('x:SizeWithCells', '');
// x:Anchor
// anchor is a nice way to locate the comment sensibly with respect to the sheet's rows/columns, but
// in order to do so, need to be able to convert roughly to point dimensions from the comments
// width/height, which are optimized for css
if (preg_match('/\\s*pt\\s*$/', $cssWidth) && preg_match('/\\s*pt\\s*$/', $cssHeight)) {
// compute CSS height to an integer # pts
$width = intval(preg_replace('/\\s*pt\\s*$/', '', $cssWidth));
$height = intval(preg_replace('/\\s*pt\\s*$/', '', $cssHeight));
// starting from the row/column this is being placed in try
// to figure out the row column that should anchor the lower-right
// corner of the comment
$clearedWidth = 0;
$clearedHeight = 0;
$maxColumns = 2;
$maxRows = 10;
// loop incremenets, so decrement both to start
$curColumn = $column - 1;
$curRow = $row - 1;
while ($clearedWidth < $width && $curColumn - $column < $maxColumns) {
++$curColumn;
$dim = $pWorksheet->getColumnDimensionByColumn($curColumn, false);
$clearedWidth += $dim && $dim->getWidth() > 0 ? $dim->getWidth() : 96;
}
while ($clearedHeight < $height && $curRow - $row < $maxRows) {
++$curRow;
$dim = $pWorksheet->getRowDimension($curRow, false);
$clearedHeight += $dim && $dim->getRowHeight() > 0 ? $dim->getRowHeight() : 14;
}
$colBump = 15;
$rowBump = 10;
$anchor = $column . ', ' . $colBump . ', ' . ($row - 1) . ', ' . $rowBump . ', ' . $curColumn . ', ' . max($clearedWidth - $width, 0) . ', ' . $curRow . ', ' . max($clearedHeight - $height, 0);
// lower-right row offset
$objWriter->writeElement('x:Anchor', $anchor);
}
// x:AutoFill
$objWriter->writeElement('x:AutoFill', 'False');
// x:Row
$objWriter->writeElement('x:Row', $row - 1);
// x:Column
$objWriter->writeElement('x:Column', $column - 1);
$objWriter->endElement();
$objWriter->endElement();
}
示例15: _writeHeaderFooter
/**
* Write Header / Footer
*
* @param PHPExcel_Shared_XMLWriter $objWriter XML Writer
* @param PHPExcel_Worksheet $pSheet Worksheet
*
* @throws PHPExcel_Writer_Exception
*/
private function _writeHeaderFooter(PHPExcel_Shared_XMLWriter $objWriter = null, PHPExcel_Worksheet $pSheet = null)
{
// headerFooter
$objWriter->startElement('headerFooter');
$objWriter->writeAttribute('differentOddEven', $pSheet->getHeaderFooter()->getDifferentOddEven() ? 'true' : 'false');
$objWriter->writeAttribute('differentFirst', $pSheet->getHeaderFooter()->getDifferentFirst() ? 'true' : 'false');
$objWriter->writeAttribute('scaleWithDoc', $pSheet->getHeaderFooter()->getScaleWithDocument() ? 'true' : 'false');
$objWriter->writeAttribute('alignWithMargins', $pSheet->getHeaderFooter()->getAlignWithMargins() ? 'true' : 'false');
$objWriter->writeElement('oddHeader', $pSheet->getHeaderFooter()->getOddHeader());
$objWriter->writeElement('oddFooter', $pSheet->getHeaderFooter()->getOddFooter());
$objWriter->writeElement('evenHeader', $pSheet->getHeaderFooter()->getEvenHeader());
$objWriter->writeElement('evenFooter', $pSheet->getHeaderFooter()->getEvenFooter());
$objWriter->writeElement('firstHeader', $pSheet->getHeaderFooter()->getFirstHeader());
$objWriter->writeElement('firstFooter', $pSheet->getHeaderFooter()->getFirstFooter());
$objWriter->endElement();
}