ILIAS  Release_4_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
PHPExcel_Writer_HTML Class Reference
+ Inheritance diagram for PHPExcel_Writer_HTML:
+ Collaboration diagram for PHPExcel_Writer_HTML:

Public Member Functions

 __construct (PHPExcel $phpExcel)
 Create a new PHPExcel_Writer_HTML.
 save ($pFilename=null)
 Save PHPExcel to file.
 getSheetIndex ()
 Get sheet index.
 setSheetIndex ($pValue=0)
 Set sheet index.
 writeAllSheets ()
 Write all sheets (resets sheetIndex to NULL)
 generateHTMLHeader ($pIncludeStyles=false)
 Generate HTML header.
 generateSheetData ()
 Generate sheet data.
 generateStyles ($generateSurroundingHTML=true)
 Generate CSS styles.
 buildCSS ($generateSurroundingHTML=true)
 Build CSS styles.
 generateHTMLFooter ()
 Generate HTML footer.
 getPreCalculateFormulas ()
 Get Pre-Calculate Formulas.
 setPreCalculateFormulas ($pValue=true)
 Set Pre-Calculate Formulas.
 getImagesRoot ()
 Get images root.
 setImagesRoot ($pValue= '.')
 Set images root.
 getUseInlineCss ()
 Get use inline CSS?
 setUseInlineCss ($pValue=false)
 Set use inline CSS?

Protected Attributes

 $_phpExcel
 $_isPdf = false

Private Member Functions

 _mapVAlign ($vAlign)
 Map VAlign.
 _mapHAlign ($hAlign)
 Map HAlign.
 _mapBorderStyle ($borderStyle)
 Map border style.
 _writeImageTagInCell (PHPExcel_Worksheet $pSheet, $coordinates)
 Generate image tag in cell.
 _createCSSStyle (PHPExcel_Style $pStyle)
 Create CSS style.
 _createCSSStyleAlignment (PHPExcel_Style_Alignment $pStyle)
 Create CSS style (PHPExcel_Style_Alignment)
 _createCSSStyleFont (PHPExcel_Style_Font $pStyle)
 Create CSS style (PHPExcel_Style_Font)
 _createCSSStyleBorders (PHPExcel_Style_Borders $pStyle)
 Create CSS style (PHPExcel_Style_Borders)
 _createCSSStyleBorder (PHPExcel_Style_Border $pStyle)
 Create CSS style (PHPExcel_Style_Border)
 _createCSSStyleFill (PHPExcel_Style_Fill $pStyle)
 Create CSS style (PHPExcel_Style_Fill)
 _generateTableHeader ($pSheet)
 Generate table header.
 _generateTableFooter ()
 Generate table footer.
 _generateRow (PHPExcel_Worksheet $pSheet, $pValues=null, $pRow=0)
 Generate row.
 _assembleCSS ($pValue=array())
 Takes array where of CSS properties / values and converts to CSS string.
 _convertNbsp ($pValue= '')
 Converts a string so that spaces occuring at beginning of each new line are replaced by   Example: " Hello\n to the world" is converted to "  Hello\n to the world".

Private Attributes

 $_sheetIndex
 $_preCalculateFormulas = true
 $_imagesRoot = '.'
 $_useInlineCss = false
 $_cssStyles = null
 $_columnWidths = null
 $_defaultFontSize

Detailed Description

Definition at line 63 of file HTML.php.

Constructor & Destructor Documentation

PHPExcel_Writer_HTML::__construct ( PHPExcel  $phpExcel)

Create a new PHPExcel_Writer_HTML.

Parameters
PHPExcel$phpExcelPHPExcel object

Reimplemented in PHPExcel_Writer_PDF.

Definition at line 132 of file HTML.php.

References PHPExcel\getDefaultStyle().

{
$this->_phpExcel = $phpExcel;
$this->_defaultFontSize = $this->_phpExcel->getDefaultStyle()->getFont()->getSize();
$this->_sheetIndex = 0;
$this->_imagesRoot = '.';
}

+ Here is the call graph for this function:

Member Function Documentation

PHPExcel_Writer_HTML::_assembleCSS (   $pValue = array())
private

Takes array where of CSS properties / values and converts to CSS string.

Parameters
array
Returns
string

Definition at line 995 of file HTML.php.

Referenced by _generateRow(), _generateTableHeader(), and generateStyles().

{
$pairs = array();
foreach ($pValue as $property => $value) {
$pairs[] = $property . ':' . $value;
}
$string = implode('; ', $pairs);
return $string;
}

+ Here is the caller graph for this function:

PHPExcel_Writer_HTML::_convertNbsp (   $pValue = '')
private

Converts a string so that spaces occuring at beginning of each new line are replaced by   Example: " Hello\n to the world" is converted to "  Hello\n to the world".

Parameters
string$pValue
Returns
string

Definition at line 1073 of file HTML.php.

Referenced by _generateRow().

{
$explodes = explode("\n", $pValue);
foreach ($explodes as $explode) {
$matches = array();
if (preg_match('/^( )+/', $explode, $matches)) {
$explode = str_repeat(' ', strlen($matches[0])) . substr($explode, strlen($matches[0]));
}
$implodes[] = $explode;
}
$string = implode("\n", $implodes);
return $string;
}

+ Here is the caller graph for this function:

PHPExcel_Writer_HTML::_createCSSStyle ( PHPExcel_Style  $pStyle)
private

Create CSS style.

Parameters
PHPExcel_Style$pStylePHPExcel_Style
Returns
array

Definition at line 583 of file HTML.php.

References _createCSSStyleAlignment(), _createCSSStyleBorders(), _createCSSStyleFill(), _createCSSStyleFont(), PHPExcel_Style\getAlignment(), PHPExcel_Style\getBorders(), PHPExcel_Style\getFill(), and PHPExcel_Style\getFont().

Referenced by buildCSS().

{
// Construct CSS
$css = '';
// Create CSS
$css = array_merge(
, $this->_createCSSStyleBorders($pStyle->getBorders())
, $this->_createCSSStyleFont($pStyle->getFont())
, $this->_createCSSStyleFill($pStyle->getFill())
);
// Return
return $css;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

PHPExcel_Writer_HTML::_createCSSStyleAlignment ( PHPExcel_Style_Alignment  $pStyle)
private

Create CSS style (PHPExcel_Style_Alignment)

Parameters
PHPExcel_Style_Alignment$pStylePHPExcel_Style_Alignment
Returns
array

Definition at line 605 of file HTML.php.

References _mapHAlign(), _mapVAlign(), PHPExcel_Style_Alignment\getHorizontal(), and PHPExcel_Style_Alignment\getVertical().

Referenced by _createCSSStyle().

{
// Construct CSS
$css = array();
// Create CSS
$css['vertical-align'] = $this->_mapVAlign($pStyle->getVertical());
if ($textAlign = $this->_mapHAlign($pStyle->getHorizontal())) {
$css['text-align'] = $textAlign;
}
// Return
return $css;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

PHPExcel_Writer_HTML::_createCSSStyleBorder ( PHPExcel_Style_Border  $pStyle)
private

Create CSS style (PHPExcel_Style_Border)

Parameters
PHPExcel_Style_Border$pStylePHPExcel_Style_Border
Returns
string

Definition at line 678 of file HTML.php.

References _mapBorderStyle(), PHPExcel_Style_Border\getBorderStyle(), and PHPExcel_Style_Border\getColor().

Referenced by _createCSSStyleBorders().

{
// Construct HTML
$css = '';
// Create CSS
$css .= $this->_mapBorderStyle($pStyle->getBorderStyle()) . ' #' . $pStyle->getColor()->getRGB();
// Return
return $css;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

PHPExcel_Writer_HTML::_createCSSStyleBorders ( PHPExcel_Style_Borders  $pStyle)
private

Create CSS style (PHPExcel_Style_Borders)

Parameters
PHPExcel_Style_Borders$pStylePHPExcel_Style_Borders
Returns
array

Definition at line 658 of file HTML.php.

References _createCSSStyleBorder(), PHPExcel_Style_Borders\getBottom(), PHPExcel_Style_Borders\getLeft(), PHPExcel_Style_Borders\getRight(), and PHPExcel_Style_Borders\getTop().

Referenced by _createCSSStyle().

{
// Construct CSS
$css = array();
// Create CSS
$css['border-bottom'] = $this->_createCSSStyleBorder($pStyle->getBottom());
$css['border-top'] = $this->_createCSSStyleBorder($pStyle->getTop());
$css['border-left'] = $this->_createCSSStyleBorder($pStyle->getLeft());
$css['border-right'] = $this->_createCSSStyleBorder($pStyle->getRight());
// Return
return $css;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

PHPExcel_Writer_HTML::_createCSSStyleFill ( PHPExcel_Style_Fill  $pStyle)
private

Create CSS style (PHPExcel_Style_Fill)

Parameters
PHPExcel_Style_Fill$pStylePHPExcel_Style_Fill
Returns
array

Definition at line 695 of file HTML.php.

References PHPExcel_Style_Fill\FILL_NONE, PHPExcel_Style_Fill\getFillType(), and PHPExcel_Style_Fill\getStartColor().

Referenced by _createCSSStyle().

{
// Construct HTML
$css = array();
// Create CSS
'white' : '#' . $pStyle->getStartColor()->getRGB();
$css['background-color'] = $value;
// Return
return $css;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

PHPExcel_Writer_HTML::_createCSSStyleFont ( PHPExcel_Style_Font  $pStyle)
private

Create CSS style (PHPExcel_Style_Font)

Parameters
PHPExcel_Style_Font$pStylePHPExcel_Style_Font
Returns
array

Definition at line 625 of file HTML.php.

References PHPExcel_Style_Font\getBold(), PHPExcel_Style_Font\getColor(), PHPExcel_Style_Font\getItalic(), PHPExcel_Style_Font\getName(), PHPExcel_Style_Font\getSize(), PHPExcel_Style_Font\getStrikethrough(), PHPExcel_Style_Font\getUnderline(), and PHPExcel_Style_Font\UNDERLINE_NONE.

Referenced by _createCSSStyle(), and _generateRow().

{
// Construct CSS
$css = array();
// Create CSS
if ($pStyle->getBold()) {
$css['font-weight'] = 'bold';
}
$css['text-decoration'] = 'underline line-through';
$css['text-decoration'] = 'underline';
} else if ($pStyle->getStrikethrough()) {
$css['text-decoration'] = 'line-through';
}
if ($pStyle->getItalic()) {
$css['font-style'] = 'italic';
}
$css['color'] = '#' . $pStyle->getColor()->getRGB();
$css['font-family'] = '\'' . $pStyle->getName() . '\'';
$css['font-size'] = $pStyle->getSize() . 'pt';
// Return
return $css;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

PHPExcel_Writer_HTML::_generateRow ( PHPExcel_Worksheet  $pSheet,
  $pValues = null,
  $pRow = 0 
)
private

Generate row.

Parameters
PHPExcel_Worksheet$pSheetPHPExcel_Worksheet
array$pValuesArray containing cells in a row
int$pRowRow number
Returns
string
Exceptions
Exception

Definition at line 783 of file HTML.php.

References _assembleCSS(), _convertNbsp(), _createCSSStyleFont(), _writeImageTagInCell(), PHPExcel_Cell\columnIndexFromString(), PHPExcel_Worksheet\getMergeCells(), PHPExcel_Worksheet\getParent(), PHPExcel_Style_Alignment\HORIZONTAL_GENERAL, PHPExcel_Cell\rangeDimension(), PHPExcel_Cell\splitRange(), PHPExcel_Cell\stringFromColumnIndex(), PHPExcel_Style_NumberFormat\toFormattedString(), and PHPExcel_Cell_DataType\TYPE_NULL.

Referenced by generateSheetData().

{
if (is_array($pValues)) {
// Construct HTML
$html = '';
// Sheet index
$sheetIndex = $pSheet->getParent()->getIndex($pSheet);
// Write row start
if (!$this->_useInlineCss) {
$html .= ' <tr class="row' . $pRow . '">' . "\r\n";
} else {
$style = isset($this->_cssStyles['table.sheet' . $sheetIndex . ' tr.row' . $pRow])
? $this->_assembleCSS($this->_cssStyles['table.sheet' . $sheetIndex . ' tr.row' . $pRow]) : '';
$html .= ' <tr style="' . $style . '">' . "\r\n";
}
// Write cells
$colNum = 0;
foreach ($pValues as $cell) {
if (!$this->_useInlineCss) {
$cssClass = '';
$cssClass = 'column' . $colNum;
} else {
$cssClass = array();
if (isset($this->_cssStyles['table.sheet' . $sheetIndex . ' td.column' . $colNum])) {
$this->_cssStyles['table.sheet' . $sheetIndex . ' td.column' . $colNum];
}
}
$colSpan = 1;
$rowSpan = 1;
$writeCell = true; // Write cell
// initialize
$cellData = '';
// PHPExcel_Cell
if ($cell instanceof PHPExcel_Cell) {
// Value
if ($cell->getValue() instanceof PHPExcel_RichText) {
// Loop trough rich text elements
$elements = $cell->getValue()->getRichTextElements();
foreach ($elements as $element) {
// Rich text start?
if ($element instanceof PHPExcel_RichText_Run) {
$cellData .= '<span style="' . $this->_assembleCSS($this->_createCSSStyleFont($element->getFont())) . '">';
if ($element->getFont()->getSuperScript()) {
$cellData .= '<sup>';
} else if ($element->getFont()->getSubScript()) {
$cellData .= '<sub>';
}
}
// Convert UTF8 data to PCDATA
$cellText = $element->getText();
$cellData .= htmlspecialchars($cellText);
if ($element instanceof PHPExcel_RichText_Run) {
if ($element->getFont()->getSuperScript()) {
$cellData .= '</sup>';
} else if ($element->getFont()->getSubScript()) {
$cellData .= '</sub>';
}
$cellData .= '</span>';
}
}
} else {
if ($this->_preCalculateFormulas) {
$cell->getCalculatedValue(),
$pSheet->getParent()->getCellXfByIndex( $cell->getXfIndex() )->getNumberFormat()->getFormatCode()
);
} else {
$cellData = PHPExcel_Style_NumberFormat::ToFormattedString(
$cell->getValue(),
$pSheet->getParent()->getCellXfByIndex( $cell->getXfIndex() )->getNumberFormat()->getFormatCode()
);
}
// Convert UTF8 data to PCDATA
$cellData = htmlspecialchars($cellData);
}
// replace leading spaces on each line with &nbsp;
$cellData = $this->_convertNbsp($cellData);
// convert newline "\n" to '<br>'
$cellData = str_replace("\n", '<br/>', $cellData);
// Check value
if ($cellData == '') {
$cellData = '&nbsp;';
}
// Extend CSS class?
if (!$this->_useInlineCss) {
$cssClass .= ' style' . $cell->getXfIndex();
$cssClass .= ' ' . $cell->getDataType();
} else {
if (isset($this->_cssStyles['td.style' . $cell->getXfIndex()])) {
$cssClass = array_merge($cssClass, $this->_cssStyles['td.style' . $cell->getXfIndex()]);
}
// General horizontal alignment: Actual horizontal alignment depends on dataType
$sharedStyle = $pSheet->getParent()->getCellXfByIndex( $cell->getXfIndex() );
if ($sharedStyle->getAlignment()->getHorizontal() == PHPExcel_Style_Alignment::HORIZONTAL_GENERAL
&& isset($this->_cssStyles['.' . $cell->getDataType()]['text-align']))
{
$cssClass['text-align'] = $this->_cssStyles['.' . $cell->getDataType()]['text-align'];
}
}
} else {
$cell = new PHPExcel_Cell(
($pRow + 1),
'',
$pSheet
);
}
// Hyperlink?
if ($cell->hasHyperlink() && !$cell->getHyperlink()->isInternal()) {
$cellData = '<a href="' . htmlspecialchars($cell->getHyperlink()->getUrl()) . '" title="' . htmlspecialchars($cell->getHyperlink()->getTooltip()) . '">' . $cellData . '</a>';
}
// Column/rowspan
foreach ($pSheet->getMergeCells() as $cells) {
if ($cell->isInRange($cells)) {
list($first, ) = PHPExcel_Cell::splitRange($cells);
if ($first[0] == $cell->getCoordinate()) {
list($colSpan, $rowSpan) = PHPExcel_Cell::rangeDimension($cells);
} else {
$writeCell = false;
}
break;
}
}
// Write
if ($writeCell) {
// Column start
$html .= ' <td';
if (!$this->_useInlineCss) {
$html .= ' class="' . $cssClass . '"';
} else {
//** Necessary redundant code for the sake of PHPExcel_Writer_PDF **
// We must explicitly write the width of the <td> element because TCPDF
// does not recognize e.g. <col style="width:42pt">
$width = 0;
$columnIndex = PHPExcel_Cell::columnIndexFromString($cell->getColumn()) - 1;
for ($i = $columnIndex; $i < $columnIndex + $colSpan; ++$i) {
if (isset($this->_columnWidths[$sheetIndex][$i])) {
$width += $this->_columnWidths[$sheetIndex][$i];
}
}
$cssClass['width'] = $width . 'pt';
// We must also explicitly write the height of the <td> element because TCPDF
// does not recognize e.g. <tr style="height:50pt">
if (isset($this->_cssStyles['table.sheet' . $sheetIndex . ' tr.row' . $pRow]['height'])) {
$height = $this->_cssStyles['table.sheet' . $sheetIndex . ' tr.row' . $pRow]['height'];
$cssClass['height'] = $height;
}
//** end of redundant code **
$html .= ' style="' . $this->_assembleCSS($cssClass) . '"';
}
if ($colSpan > 1) {
$html .= ' colspan="' . $colSpan . '"';
}
if ($rowSpan > 1) {
$html .= ' rowspan="' . $rowSpan . '"';
}
$html .= '>';
// Image?
$html .= $this->_writeImageTagInCell($pSheet, $cell->getCoordinate());
// Cell data
$html .= $cellData;
// Column end
$html .= '</td>' . "\r\n";
}
// Next column
++$colNum;
}
// Write row end
$html .= ' </tr>' . "\r\n";
// Return
return $html;
} else {
throw new Exception("Invalid parameters passed.");
}
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

PHPExcel_Writer_HTML::_generateTableFooter ( )
private

Generate table footer.

Exceptions
Exception

Definition at line 765 of file HTML.php.

Referenced by generateSheetData().

{
// Construct HTML
$html = '';
$html .= ' </table>' . "\r\n";
// Return
return $html;
}

+ Here is the caller graph for this function:

PHPExcel_Writer_HTML::_generateTableHeader (   $pSheet)
private

Generate table header.

Parameters
PHPExcel_Worksheet$pSheetThe worksheet for the table we are writing
Returns
string
Exceptions
Exception

Definition at line 728 of file HTML.php.

References _assembleCSS(), and PHPExcel_Cell\columnIndexFromString().

Referenced by generateSheetData().

{
$sheetIndex = $pSheet->getParent()->getIndex($pSheet);
// Construct HTML
$html = '';
if (!$this->_useInlineCss) {
$gridlines = $pSheet->getShowGridLines() ? ' gridlines' : '';
$html .= ' <table border="0" cellpadding="0" cellspacing="0" class="sheet' . $sheetIndex . $gridlines . '">' . "\r\n";
} else {
$style = isset($this->_cssStyles['table']) ?
$this->_assembleCSS($this->_cssStyles['table']) : '';
$html .= ' <table border="0" cellpadding="0" cellspacing="0" style="' . $style . '">' . "\r\n";
}
// Write <col> elements
$highestColumnIndex = PHPExcel_Cell::columnIndexFromString($pSheet->getHighestColumn()) - 1;
for ($i = 0; $i <= $highestColumnIndex; ++$i) {
if (!$this->_useInlineCss) {
$html .= ' <col class="col' . $i . '">' . "\r\n";
} else {
$style = isset($this->_cssStyles['table.sheet' . $sheetIndex . ' col.col' . $i]) ?
$this->_assembleCSS($this->_cssStyles['table.sheet' . $sheetIndex . ' col.col' . $i]) : '';
$html .= ' <col style="' . $style . '">' . "\r\n";
}
}
// Return
return $html;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

PHPExcel_Writer_HTML::_mapBorderStyle (   $borderStyle)
private

Map border style.

Definition at line 208 of file HTML.php.

References PHPExcel_Style_Border\BORDER_DASHED, PHPExcel_Style_Border\BORDER_DOTTED, PHPExcel_Style_Border\BORDER_NONE, and PHPExcel_Style_Border\BORDER_THICK.

Referenced by _createCSSStyleBorder().

{
switch ($borderStyle) {
case PHPExcel_Style_Border::BORDER_DASHED: return '1px dashed';
case PHPExcel_Style_Border::BORDER_DOTTED: return '1px dotted';
case PHPExcel_Style_Border::BORDER_THICK: return '2px solid';
default: return '1px solid'; // map others to thin
}
}

+ Here is the caller graph for this function:

PHPExcel_Writer_HTML::_mapHAlign (   $hAlign)
private

Map HAlign.

Returns
string|false

Definition at line 194 of file HTML.php.

References PHPExcel_Style_Alignment\HORIZONTAL_CENTER, PHPExcel_Style_Alignment\HORIZONTAL_GENERAL, PHPExcel_Style_Alignment\HORIZONTAL_JUSTIFY, PHPExcel_Style_Alignment\HORIZONTAL_LEFT, and PHPExcel_Style_Alignment\HORIZONTAL_RIGHT.

Referenced by _createCSSStyleAlignment().

{
switch ($hAlign) {
default: return false;
}
}

+ Here is the caller graph for this function:

PHPExcel_Writer_HTML::_mapVAlign (   $vAlign)
private

Map VAlign.

Definition at line 179 of file HTML.php.

References PHPExcel_Style_Alignment\VERTICAL_BOTTOM, PHPExcel_Style_Alignment\VERTICAL_CENTER, PHPExcel_Style_Alignment\VERTICAL_JUSTIFY, and PHPExcel_Style_Alignment\VERTICAL_TOP.

Referenced by _createCSSStyleAlignment().

{
switch ($vAlign) {
default: return 'baseline';
}
}

+ Here is the caller graph for this function:

PHPExcel_Writer_HTML::_writeImageTagInCell ( PHPExcel_Worksheet  $pSheet,
  $coordinates 
)
private

Generate image tag in cell.

Parameters
PHPExcel_Worksheet$pSheetPHPExcel_Worksheet
string$coordinatesCell coordinates
Returns
string
Exceptions
Exception

Definition at line 363 of file HTML.php.

References $filename, PHPExcel_Worksheet\getDrawingCollection(), and getImagesRoot().

Referenced by _generateRow().

{
// Construct HTML
$html = '';
// Write images
foreach ($pSheet->getDrawingCollection() as $drawing) {
if ($drawing instanceof PHPExcel_Worksheet_Drawing) {
if ($drawing->getCoordinates() == $coordinates) {
$filename = $drawing->getPath();
// Strip off eventual '.'
if (substr($filename, 0, 1) == '.') {
$filename = substr($filename, 1);
}
// Prepend images root
// Strip off eventual '.'
if (substr($filename, 0, 1) == '.' && substr($filename, 0, 2) != './') {
$filename = substr($filename, 1);
}
// Convert UTF8 data to PCDATA
$filename = htmlspecialchars($filename);
$html .= "\r\n";
$html .= ' <img style="position: relative; left: ' . $drawing->getOffsetX() . 'px; top: ' . $drawing->getOffsetY() . 'px; width: ' . $drawing->getWidth() . 'px; height: ' . $drawing->getHeight() . 'px;" src="' . $filename . '" border="0" width="' . $drawing->getWidth() . '" height="' . $drawing->getHeight() . '" />' . "\r\n";
}
}
}
// Return
return $html;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

PHPExcel_Writer_HTML::buildCSS (   $generateSurroundingHTML = true)

Build CSS styles.

Parameters
boolean$generateSurroundingHTMLGenerate surrounding HTML style? (html { })
Returns
array
Exceptions
Exception

Definition at line 447 of file HTML.php.

References $_cssStyles, $_defaultFontSize, $row, _createCSSStyle(), PHPExcel_Shared_Drawing\cellDimensionToPixels(), PHPExcel_Cell\columnIndexFromString(), and PHPExcel_Shared_Drawing\pixelsToPoints().

Referenced by generateStyles(), PHPExcel_Writer_PDF\save(), and save().

{
// PHPExcel object known?
if (is_null($this->_phpExcel)) {
throw new Exception('Internal PHPExcel object not set to an instance of an object.');
}
// Cached?
if (!is_null($this->_cssStyles)) {
}
// Construct CSS
$css = array();
// Start styles
if ($generateSurroundingHTML) {
// html { }
$css['html']['font-family'] = 'Calibri, Arial, Helvetica, sans-serif';
$css['html']['font-size'] = '11pt';
$css['html']['background-color'] = 'white';
}
// table { }
$css['table']['border-collapse'] = 'collapse';
$css['table']['page-break-after'] = 'always';
// .gridlines td { }
$css['.gridlines td']['border'] = '1px dotted black';
// .b {}
$css['.b']['text-align'] = 'center'; // BOOL
// .e {}
$css['.e']['text-align'] = 'center'; // ERROR
// .f {}
$css['.f']['text-align'] = 'right'; // FORMULA
// .inlineStr {}
$css['.inlineStr']['text-align'] = 'left'; // INLINE
// .n {}
$css['.n']['text-align'] = 'right'; // NUMERIC
// .s {}
$css['.s']['text-align'] = 'left'; // STRING
// Calculate cell style hashes
foreach ($this->_phpExcel->getCellXfCollection() as $index => $style) {
$css['td.style' . $index] = $this->_createCSSStyle( $style );
}
// Fetch sheets
$sheets = array();
if (is_null($this->_sheetIndex)) {
$sheets = $this->_phpExcel->getAllSheets();
} else {
$sheets[] = $this->_phpExcel->getSheet($this->_sheetIndex);
}
// Build styles per sheet
foreach ($sheets as $sheet) {
// Calculate hash code
$sheetIndex = $sheet->getParent()->getIndex($sheet);
// Build styles
// Calculate column widths
$sheet->calculateColumnWidths();
// col elements, initialize
$highestColumnIndex = PHPExcel_Cell::columnIndexFromString($sheet->getHighestColumn()) - 1;
for ($column = 0; $column <= $highestColumnIndex; ++$column) {
$this->_columnWidths[$sheetIndex][$column] = 42; // approximation
$css['table.sheet' . $sheetIndex . ' col.col' . $column]['width'] = '42pt';
}
// col elements, loop through columnDimensions and set width
foreach ($sheet->getColumnDimensions() as $columnDimension) {
if (($width = PHPExcel_Shared_Drawing::cellDimensionToPixels($columnDimension->getWidth(), $this->_defaultFontSize)) >= 0) {
$column = PHPExcel_Cell::columnIndexFromString($columnDimension->getColumnIndex()) - 1;
$this->_columnWidths[$sheetIndex][$column] = $width;
$css['table.sheet' . $sheetIndex . ' col.col' . $column]['width'] = $width . 'pt';
if ($columnDimension->getVisible() === false) {
$css['table.sheet' . $sheetIndex . ' col.col' . $column]['visibility'] = 'collapse';
$css['table.sheet' . $sheetIndex . ' col.col' . $column]['*display'] = 'none'; // target IE6+7
}
}
}
// Default row height
$rowDimension = $sheet->getDefaultRowDimension();
// table.sheetN tr { }
$css['table.sheet' . $sheetIndex . ' tr'] = array();
$pt_height = $rowDimension->getRowHeight();
$css['table.sheet' . $sheetIndex . ' tr']['height'] = $pt_height . 'pt';
if ($rowDimension->getVisible() === false) {
$css['table.sheet' . $sheetIndex . ' tr']['display'] = 'none';
$css['table.sheet' . $sheetIndex . ' tr']['visibility'] = 'hidden';
}
// Calculate row heights
foreach ($sheet->getRowDimensions() as $rowDimension) {
$row = $rowDimension->getRowIndex() - 1;
// table.sheetN tr.rowYYYYYY { }
$css['table.sheet' . $sheetIndex . ' tr.row' . $row] = array();
$pt_height = $rowDimension->getRowHeight();
$css['table.sheet' . $sheetIndex . ' tr.row' . $row]['height'] = $pt_height . 'pt';
if ($rowDimension->getVisible() === false) {
$css['table.sheet' . $sheetIndex . ' tr.row' . $row]['display'] = 'none';
$css['table.sheet' . $sheetIndex . ' tr.row' . $row]['visibility'] = 'hidden';
}
}
}
// Cache
if (is_null($this->_cssStyles)) {
$this->_cssStyles = $css;
}
// Return
return $css;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

PHPExcel_Writer_HTML::generateHTMLFooter ( )

Generate HTML footer.

Definition at line 711 of file HTML.php.

Referenced by save().

{
// Construct HTML
$html = '';
$html .= ' </body>' . "\r\n";
$html .= '</html>' . "\r\n";
// Return
return $html;
}

+ Here is the caller graph for this function:

PHPExcel_Writer_HTML::generateHTMLHeader (   $pIncludeStyles = false)

Generate HTML header.

Parameters
boolean$pIncludeStylesInclude styles?
Returns
string
Exceptions
Exception

Definition at line 252 of file HTML.php.

References generateStyles().

Referenced by save().

{
// PHPExcel object known?
if (is_null($this->_phpExcel)) {
throw new Exception('Internal PHPExcel object not set to an instance of an object.');
}
// Construct HTML
$html = '';
$html .= '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">' . "\r\n";
$html .= '<!-- Generated by PHPExcel - http://www.phpexcel.net -->' . "\r\n";
$html .= '<html>' . "\r\n";
$html .= ' <head>' . "\r\n";
$html .= ' <meta http-equiv="Content-Type" content="text/html; charset=utf-8">' . "\r\n";
$html .= ' <title>' . htmlspecialchars($this->_phpExcel->getProperties()->getTitle()) . '</title>' . "\r\n";
if ($pIncludeStyles) {
$html .= $this->generateStyles(true);
}
$html .= ' </head>' . "\r\n";
$html .= '' . "\r\n";
$html .= ' <body>' . "\r\n";
// Return
return $html;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

PHPExcel_Writer_HTML::generateSheetData ( )

Generate sheet data.

Returns
string
Exceptions
Exception

Definition at line 283 of file HTML.php.

References $row, _generateRow(), _generateTableFooter(), _generateTableHeader(), PHPExcel_Cell\columnIndexFromString(), and PHPExcel_Cell\coordinateFromString().

Referenced by PHPExcel_Writer_PDF\save(), and save().

{
// PHPExcel object known?
if (is_null($this->_phpExcel)) {
throw new Exception('Internal PHPExcel object not set to an instance of an object.');
}
// Fetch sheets
$sheets = array();
if (is_null($this->_sheetIndex)) {
$sheets = $this->_phpExcel->getAllSheets();
} else {
$sheets[] = $this->_phpExcel->getSheet($this->_sheetIndex);
}
// Construct HTML
$html = '';
// Loop all sheets
$sheetId = 0;
foreach ($sheets as $sheet) {
// Get cell collection
$cellCollection = $sheet->getCellCollection();
// Write table header
$html .= $this->_generateTableHeader($sheet);
// Get worksheet dimension
$dimension = explode(':', $sheet->calculateWorksheetDimension());
$dimension[0] = PHPExcel_Cell::coordinateFromString($dimension[0]);
$dimension[0][0] = PHPExcel_Cell::columnIndexFromString($dimension[0][0]) - 1;
$dimension[1] = PHPExcel_Cell::coordinateFromString($dimension[1]);
$dimension[1][0] = PHPExcel_Cell::columnIndexFromString($dimension[1][0]) - 1;
// Loop trough cells
$rowData = null;
for ($row = $dimension[0][1]; $row <= $dimension[1][1]; ++$row) {
// Start a new row
$rowData = array();
// Loop trough columns
for ($column = $dimension[0][0]; $column <= $dimension[1][0]; ++$column) {
// Cell exists?
if ($sheet->cellExistsByColumnAndRow($column, $row)) {
$rowData[$column] = $sheet->getCellByColumnAndRow($column, $row);
} else {
$rowData[$column] = '';
}
}
// Write row
$html .= $this->_generateRow($sheet, $rowData, $row - 1);
}
// Write table footer
$html .= $this->_generateTableFooter();
// Writing PDF?
if ($this->_isPdf)
{
if (is_null($this->_sheetIndex) && $sheetId + 1 < $this->_phpExcel->getSheetCount()) {
$html .= '<tcpdf method="AddPage" />';
}
}
// Next sheet
++$sheetId;
}
// Return
return $html;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

PHPExcel_Writer_HTML::generateStyles (   $generateSurroundingHTML = true)

Generate CSS styles.

Parameters
boolean$generateSurroundingHTMLGenerate surrounding HTML tags? (<style> and </style>)
Returns
string
Exceptions
Exception

Definition at line 406 of file HTML.php.

References _assembleCSS(), and buildCSS().

Referenced by generateHTMLHeader().

{
// PHPExcel object known?
if (is_null($this->_phpExcel)) {
throw new Exception('Internal PHPExcel object not set to an instance of an object.');
}
// Build CSS
$css = $this->buildCSS($generateSurroundingHTML);
// Construct HTML
$html = '';
// Start styles
if ($generateSurroundingHTML) {
$html .= ' <style type="text/css">' . "\r\n";
$html .= ' html { ' . $this->_assembleCSS($css['html']) . ' }' . "\r\n";
}
// Write all other styles
foreach ($css as $styleName => $styleDefinition) {
if ($styleName != 'html') {
$html .= ' ' . $styleName . ' { ' . $this->_assembleCSS($styleDefinition) . ' }' . "\r\n";
}
}
// End styles
if ($generateSurroundingHTML) {
$html .= ' </style>' . "\r\n";
}
// Return
return $html;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

PHPExcel_Writer_HTML::getImagesRoot ( )

Get images root.

Returns
string

Definition at line 1031 of file HTML.php.

References $_imagesRoot.

Referenced by _writeImageTagInCell().

{
}

+ Here is the caller graph for this function:

PHPExcel_Writer_HTML::getPreCalculateFormulas ( )

Get Pre-Calculate Formulas.

Returns
boolean

Definition at line 1011 of file HTML.php.

References $_preCalculateFormulas.

PHPExcel_Writer_HTML::getSheetIndex ( )

Get sheet index.

Returns
int

Definition at line 223 of file HTML.php.

References $_sheetIndex.

Referenced by PHPExcel_Writer_PDF\save().

{
}

+ Here is the caller graph for this function:

PHPExcel_Writer_HTML::getUseInlineCss ( )

Get use inline CSS?

Returns
boolean

Definition at line 1051 of file HTML.php.

References $_useInlineCss.

{
}
PHPExcel_Writer_HTML::save (   $pFilename = null)

Save PHPExcel to file.

Parameters
string$pFileName
Exceptions
Exception

Implements PHPExcel_Writer_IWriter.

Reimplemented in PHPExcel_Writer_PDF.

Definition at line 145 of file HTML.php.

References buildCSS(), generateHTMLFooter(), generateHTMLHeader(), generateSheetData(), PHPExcel_Calculation\getArrayReturnType(), PHPExcel_Calculation\RETURN_ARRAY_AS_VALUE, and PHPExcel_Calculation\setArrayReturnType().

{
// garbage collect
$this->_phpExcel->garbageCollect();
$saveArrayReturnType = PHPExcel_Calculation::getArrayReturnType();
// Build CSS
$this->buildCSS(!$this->_useInlineCss);
// Open file
$fileHandle = fopen($pFilename, 'w');
if ($fileHandle === false) {
throw new Exception("Could not open file $pFilename for writing.");
}
// Write headers
fwrite($fileHandle, $this->generateHTMLHeader(!$this->_useInlineCss));
// Write data
fwrite($fileHandle, $this->generateSheetData());
// Write footer
fwrite($fileHandle, $this->generateHTMLFooter());
// Close file
fclose($fileHandle);
}

+ Here is the call graph for this function:

PHPExcel_Writer_HTML::setImagesRoot (   $pValue = '.')

Set images root.

Parameters
string$pValue
Returns
PHPExcel_Writer_HTML

Definition at line 1041 of file HTML.php.

{
$this->_imagesRoot = $pValue;
return $this;
}
PHPExcel_Writer_HTML::setPreCalculateFormulas (   $pValue = true)

Set Pre-Calculate Formulas.

Parameters
boolean$pValuePre-Calculate Formulas?
Returns
PHPExcel_Writer_HTML

Definition at line 1021 of file HTML.php.

{
$this->_preCalculateFormulas = $pValue;
return $this;
}
PHPExcel_Writer_HTML::setSheetIndex (   $pValue = 0)

Set sheet index.

Parameters
int$pValueSheet index
Returns
PHPExcel_Writer_HTML

Definition at line 233 of file HTML.php.

{
$this->_sheetIndex = $pValue;
return $this;
}
PHPExcel_Writer_HTML::setUseInlineCss (   $pValue = false)

Set use inline CSS?

Parameters
boolean$pValue
Returns
PHPExcel_Writer_HTML

Definition at line 1061 of file HTML.php.

Referenced by PHPExcel_Writer_PDF\__construct().

{
$this->_useInlineCss = $pValue;
return $this;
}

+ Here is the caller graph for this function:

PHPExcel_Writer_HTML::writeAllSheets ( )

Write all sheets (resets sheetIndex to NULL)

Definition at line 241 of file HTML.php.

{
$this->_sheetIndex = null;
}

Field Documentation

PHPExcel_Writer_HTML::$_columnWidths = null
private

Definition at line 111 of file HTML.php.

PHPExcel_Writer_HTML::$_cssStyles = null
private

Definition at line 104 of file HTML.php.

Referenced by buildCSS().

PHPExcel_Writer_HTML::$_defaultFontSize
private

Definition at line 118 of file HTML.php.

Referenced by buildCSS().

PHPExcel_Writer_HTML::$_imagesRoot = '.'
private

Definition at line 90 of file HTML.php.

Referenced by getImagesRoot().

PHPExcel_Writer_HTML::$_isPdf = false
protected

Definition at line 125 of file HTML.php.

PHPExcel_Writer_HTML::$_phpExcel
protected

Definition at line 69 of file HTML.php.

PHPExcel_Writer_HTML::$_preCalculateFormulas = true
private

Definition at line 83 of file HTML.php.

Referenced by getPreCalculateFormulas().

PHPExcel_Writer_HTML::$_sheetIndex
private

Definition at line 76 of file HTML.php.

Referenced by getSheetIndex().

PHPExcel_Writer_HTML::$_useInlineCss = false
private

Definition at line 97 of file HTML.php.

Referenced by getUseInlineCss().


The documentation for this class was generated from the following file: