本文整理汇总了PHP中PHPExcel_Shared_String::IsUTF8方法的典型用法代码示例。如果您正苦于以下问题:PHP PHPExcel_Shared_String::IsUTF8方法的具体用法?PHP PHPExcel_Shared_String::IsUTF8怎么用?PHP PHPExcel_Shared_String::IsUTF8使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PHPExcel_Shared_String
的用法示例。
在下文中一共展示了PHPExcel_Shared_String::IsUTF8方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _generateRow
/**
* Generate row
*
* @param PHPExcel_Worksheet $pSheet PHPExcel_Worksheet
* @param array $pValues Array containing cells in a row
* @param int $pRow Row number
* @return string
* @throws Exception
*/
private function _generateRow(PHPExcel_Worksheet $pSheet, $pValues = null, $pRow = 0) {
if (is_array($pValues)) {
// Construct HTML
$html = '';
// Write row start
$html .= ' <tr class="row' . $pRow . '">' . "\r\n";
// Write cells
$colNum = 0;
foreach ($pValues as $cell) {
$cellData = ' ';
$cssClass = 'column' . $colNum;
$colSpan = 1;
$rowSpan = 1;
$writeCell = true; // Write cell
// 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="' .
str_replace("\r\n", '',
$this->_createCSSStyleFont($element->getFont())
) . '">';
}
// Decode UTF8 data
$cellText = $element->getText();
if (PHPExcel_Shared_String::IsUTF8($cellText)) {
$cellData .= utf8_decode($cellText);
}
if ($element instanceof PHPExcel_RichText_Run) {
$cellData .= '</span>';
}
}
} else {
if ($this->_preCalculateFormulas) {
$cellData = PHPExcel_Style_NumberFormat::toFormattedString(
$cell->getCalculatedValue(),
$pSheet->getstyle( $cell->getCoordinate() )->getNumberFormat()->getFormatCode()
);
} else {
$cellData = PHPExcel_Style_NumberFormat::ToFormattedString(
$cell->getValue(),
$pSheet->getstyle( $cell->getCoordinate() )->getNumberFormat()->getFormatCode()
);
}
// Decode UTF8 data
if (PHPExcel_Shared_String::IsUTF8($cellData)) {
$cellData = utf8_decode($cellData);
}
}
// Check value
if ($cellData == '') {
$cellData = ' ';
}
// Extend CSS class?
if (array_key_exists($cell->getCoordinate(), $pSheet->getStyles())) {
$cssClass .= ' style' . $pSheet->getStyle($cell->getCoordinate())->getHashCode();
}
} else {
$cell = new PHPExcel_Cell(
PHPExcel_Cell::stringFromColumnIndex($colNum),
($pRow + 1),
'',
null,
null
);
}
// Hyperlink?
if ($cell->hasHyperlink() && !$cell->getHyperlink()->isInternal()) {
$cellData = '<a href="' . $cell->getHyperlink()->getUrl() . '" title="' . $cell->getHyperlink()->getTooltip() . '">' . $cellData . '</a>';
}
// Column/rowspan
foreach ($pSheet->getMergeCells() as $cells) {
if ($cell->isInRange($cells)) {
list($first, ) = PHPExcel_Cell::splitRange($cells);
if ($first == $cell->getCoordinate()) {
//.........这里部分代码省略.........
示例2: _writeLine
/**
* Write line to CSV file
*
* @param mixed $pFileHandle PHP filehandle
* @param array $pValues Array containing values in a row
* @throws Exception
*/
private function _writeLine($pFileHandle = null, $pValues = null)
{
if (!is_null($pFileHandle) && is_array($pValues)) {
// No leading delimiter
$writeDelimiter = false;
// Build the line
$line = '';
foreach ($pValues as $element) {
// Decode UTF8 data
if (PHPExcel_Shared_String::IsUTF8($element)) {
$element = utf8_decode($element);
}
// Escape enclosures
$element = str_replace($this->_enclosure, $this->_enclosure . $this->_enclosure, $element);
// Add delimiter
if ($writeDelimiter) {
$line .= $this->_delimiter;
} else {
$writeDelimiter = true;
}
// Add enclosed string
$line .= $this->_enclosure . $element . $this->_enclosure;
}
// Add line ending
$line .= $this->_lineEnding;
// Write to file
fwrite($pFileHandle, $line);
} else {
throw new Exception("Invalid parameters passed.");
}
}