本文整理汇总了PHP中PHPExcel::getIndex方法的典型用法代码示例。如果您正苦于以下问题:PHP PHPExcel::getIndex方法的具体用法?PHP PHPExcel::getIndex怎么用?PHP PHPExcel::getIndex使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PHPExcel
的用法示例。
在下文中一共展示了PHPExcel::getIndex方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _buildWorkbookEscher
/**
* Build the Escher object corresponding to the MSODRAWINGGROUP record
*/
private function _buildWorkbookEscher()
{
$escher = null;
// any drawings in this workbook?
$found = false;
foreach ($this->_phpExcel->getAllSheets() as $sheet) {
if (count($sheet->getDrawingCollection()) > 0) {
$found = true;
break;
}
}
// nothing to do if there are no drawings
if (!$found) {
return;
}
// if we reach here, then there are drawings in the workbook
$escher = new PHPExcel_Shared_Escher();
// dggContainer
$dggContainer = new PHPExcel_Shared_Escher_DggContainer();
$escher->setDggContainer($dggContainer);
// set IDCLs (identifier clusters)
$dggContainer->setIDCLs($this->_IDCLs);
// this loop is for determining maximum shape identifier of all drawing
$spIdMax = 0;
$totalCountShapes = 0;
$countDrawings = 0;
foreach ($this->_phpExcel->getAllsheets() as $sheet) {
$sheetCountShapes = 0;
// count number of shapes (minus group shape), in sheet
if (count($sheet->getDrawingCollection()) > 0) {
++$countDrawings;
foreach ($sheet->getDrawingCollection() as $drawing) {
++$sheetCountShapes;
++$totalCountShapes;
$spId = $sheetCountShapes | $this->_phpExcel->getIndex($sheet) + 1 << 10;
$spIdMax = max($spId, $spIdMax);
}
}
}
$dggContainer->setSpIdMax($spIdMax + 1);
$dggContainer->setCDgSaved($countDrawings);
$dggContainer->setCSpSaved($totalCountShapes + $countDrawings);
// total number of shapes incl. one group shapes per drawing
// bstoreContainer
$bstoreContainer = new PHPExcel_Shared_Escher_DggContainer_BstoreContainer();
$dggContainer->setBstoreContainer($bstoreContainer);
// the BSE's (all the images)
foreach ($this->_phpExcel->getAllsheets() as $sheet) {
foreach ($sheet->getDrawingCollection() as $drawing) {
if ($drawing instanceof PHPExcel_Worksheet_Drawing) {
$filename = $drawing->getPath();
list($imagesx, $imagesy, $imageFormat) = getimagesize($filename);
switch ($imageFormat) {
case 1:
// GIF, not supported by BIFF8, we convert to PNG
$blipType = PHPExcel_Shared_Escher_DggContainer_BstoreContainer_BSE::BLIPTYPE_PNG;
ob_start();
imagepng(imagecreatefromgif($filename));
$blipData = ob_get_contents();
ob_end_clean();
break;
case 2:
// JPEG
$blipType = PHPExcel_Shared_Escher_DggContainer_BstoreContainer_BSE::BLIPTYPE_JPEG;
$blipData = file_get_contents($filename);
break;
case 3:
// PNG
$blipType = PHPExcel_Shared_Escher_DggContainer_BstoreContainer_BSE::BLIPTYPE_PNG;
$blipData = file_get_contents($filename);
break;
case 6:
// Windows DIB (BMP), we convert to PNG
$blipType = PHPExcel_Shared_Escher_DggContainer_BstoreContainer_BSE::BLIPTYPE_PNG;
ob_start();
imagepng(PHPExcel_Shared_Drawing::imagecreatefrombmp($filename));
$blipData = ob_get_contents();
ob_end_clean();
break;
default:
continue 2;
}
$blip = new PHPExcel_Shared_Escher_DggContainer_BstoreContainer_BSE_Blip();
$blip->setData($blipData);
$BSE = new PHPExcel_Shared_Escher_DggContainer_BstoreContainer_BSE();
$BSE->setBlipType($blipType);
$BSE->setBlip($blip);
$bstoreContainer->addBSE($BSE);
} else {
if ($drawing instanceof PHPExcel_Worksheet_MemoryDrawing) {
switch ($drawing->getRenderingFunction()) {
case PHPExcel_Worksheet_MemoryDrawing::RENDERING_JPEG:
$blipType = PHPExcel_Shared_Escher_DggContainer_BstoreContainer_BSE::BLIPTYPE_JPEG;
$renderingFunction = 'imagejpeg';
break;
case PHPExcel_Worksheet_MemoryDrawing::RENDERING_GIF:
case PHPExcel_Worksheet_MemoryDrawing::RENDERING_PNG:
//.........这里部分代码省略.........
示例2: create_worksheet
/**
* create new worksheet
*
* @access protected
*/
protected function create_worksheet()
{
$newsheet = $this->_spreadsheet->createSheet();
$new_worksheet = new Worksheet($this->_spreadsheet, $newsheet);
$this->_worksheets[$this->_spreadsheet->getIndex($newsheet)] = $new_worksheet;
return $new_worksheet;
}
示例3: getStyle
/**
* Get style for cell
*
* @param string $pCellCoordinate Cell coordinate (or range) to get style for
* @return PHPExcel_Style
* @throws PHPExcel_Exception
*/
public function getStyle($pCellCoordinate = 'A1')
{
// set this sheet as active
$this->_parent->setActiveSheetIndex($this->_parent->getIndex($this));
// set cell coordinate as active
$this->setSelectedCells(strtoupper($pCellCoordinate));
return $this->_parent->getCellXfSupervisor();
}
示例4: _readWindow2
/**
* Read WINDOW2 record
*/
private function _readWindow2()
{
$length = self::_GetInt2d($this->_data, $this->_pos + 2);
$recordData = substr($this->_data, $this->_pos + 4, $length);
// move stream pointer to next record
$this->_pos += 4 + $length;
// offset: 0; size: 2; option flags
$options = self::_GetInt2d($recordData, 0);
// offset: 2; size: 2; index to first visible row
$firstVisibleRow = self::_GetInt2d($recordData, 2);
// offset: 4; size: 2; index to first visible colum
$firstVisibleColumn = self::_GetInt2d($recordData, 4);
if ($this->_version === self::XLS_BIFF8) {
// offset: 8; size: 2; not used
// offset: 10; size: 2; cached magnification factor in page break preview (in percent); 0 = Default (60%)
// offset: 12; size: 2; cached magnification factor in normal view (in percent); 0 = Default (100%)
// offset: 14; size: 4; not used
$zoomscaleInPageBreakPreview = self::_GetInt2d($recordData, 10);
if ($zoomscaleInPageBreakPreview === 0) {
$zoomscaleInPageBreakPreview = 60;
}
$zoomscaleInNormalView = self::_GetInt2d($recordData, 12);
if ($zoomscaleInNormalView === 0) {
$zoomscaleInNormalView = 100;
}
}
// bit: 1; mask: 0x0002; 0 = do not show gridlines, 1 = show gridlines
$showGridlines = (bool) ((0x2 & $options) >> 1);
$this->_phpSheet->setShowGridlines($showGridlines);
// bit: 2; mask: 0x0004; 0 = do not show headers, 1 = show headers
$showRowColHeaders = (bool) ((0x4 & $options) >> 2);
$this->_phpSheet->setShowRowColHeaders($showRowColHeaders);
// bit: 3; mask: 0x0008; 0 = panes are not frozen, 1 = panes are frozen
$this->_frozen = (bool) ((0x8 & $options) >> 3);
// bit: 6; mask: 0x0040; 0 = columns from left to right, 1 = columns from right to left
$this->_phpSheet->setRightToLeft((bool) ((0x40 & $options) >> 6));
// bit: 10; mask: 0x0400; 0 = sheet not active, 1 = sheet active
$isActive = (bool) ((0x400 & $options) >> 10);
if ($isActive) {
$this->_phpExcel->setActiveSheetIndex($this->_phpExcel->getIndex($this->_phpSheet));
}
// bit: 11; mask: 0x0800; 0 = normal view, 1 = page break view
$isPageBreakPreview = (bool) ((0x800 & $options) >> 11);
//FIXME: set $firstVisibleRow and $firstVisibleColumn
if ($this->_phpSheet->getSheetView()->getView() !== PHPExcel_Worksheet_SheetView::SHEETVIEW_PAGE_LAYOUT) {
//NOTE: this setting is inferior to page layout view(Excel2007-)
$view = $isPageBreakPreview ? PHPExcel_Worksheet_SheetView::SHEETVIEW_PAGE_BREAK_PREVIEW : PHPExcel_Worksheet_SheetView::SHEETVIEW_NORMAL;
$this->_phpSheet->getSheetView()->setView($view);
if ($this->_version === self::XLS_BIFF8) {
$zoomScale = $isPageBreakPreview ? $zoomscaleInPageBreakPreview : $zoomscaleInNormalView;
$this->_phpSheet->getSheetView()->setZoomScale($zoomScale);
$this->_phpSheet->getSheetView()->setZoomScaleNormal($zoomscaleInNormalView);
}
}
}
示例5: writeAllDefinedNamesBiff8
/**
* Writes all the DEFINEDNAME records (BIFF8).
* So far this is only used for repeating rows/columns (print titles) and print areas
*/
private function writeAllDefinedNamesBiff8()
{
$chunk = '';
// Named ranges
if (count($this->phpExcel->getNamedRanges()) > 0) {
// Loop named ranges
$namedRanges = $this->phpExcel->getNamedRanges();
foreach ($namedRanges as $namedRange) {
// Create absolute coordinate
$range = PHPExcel_Cell::splitRange($namedRange->getRange());
for ($i = 0; $i < count($range); $i++) {
$range[$i][0] = '\'' . str_replace("'", "''", $namedRange->getWorksheet()->getTitle()) . '\'!' . PHPExcel_Cell::absoluteCoordinate($range[$i][0]);
if (isset($range[$i][1])) {
$range[$i][1] = PHPExcel_Cell::absoluteCoordinate($range[$i][1]);
}
}
$range = PHPExcel_Cell::buildRange($range);
// e.g. Sheet1!$A$1:$B$2
// parse formula
try {
$error = $this->parser->parse($range);
$formulaData = $this->parser->toReversePolish();
// make sure tRef3d is of type tRef3dR (0x3A)
if (isset($formulaData[0]) and ($formulaData[0] == "z" or $formulaData[0] == "Z")) {
$formulaData = ":" . substr($formulaData, 1);
}
if ($namedRange->getLocalOnly()) {
// local scope
$scope = $this->phpExcel->getIndex($namedRange->getScope()) + 1;
} else {
// global scope
$scope = 0;
}
$chunk .= $this->writeData($this->writeDefinedNameBiff8($namedRange->getName(), $formulaData, $scope, false));
} catch (PHPExcel_Exception $e) {
// do nothing
}
}
}
// total number of sheets
$total_worksheets = $this->phpExcel->getSheetCount();
// write the print titles (repeating rows, columns), if any
for ($i = 0; $i < $total_worksheets; ++$i) {
$sheetSetup = $this->phpExcel->getSheet($i)->getPageSetup();
// simultaneous repeatColumns repeatRows
if ($sheetSetup->isColumnsToRepeatAtLeftSet() && $sheetSetup->isRowsToRepeatAtTopSet()) {
$repeat = $sheetSetup->getColumnsToRepeatAtLeft();
$colmin = PHPExcel_Cell::columnIndexFromString($repeat[0]) - 1;
$colmax = PHPExcel_Cell::columnIndexFromString($repeat[1]) - 1;
$repeat = $sheetSetup->getRowsToRepeatAtTop();
$rowmin = $repeat[0] - 1;
$rowmax = $repeat[1] - 1;
// construct formula data manually
$formulaData = pack('Cv', 0x29, 0x17);
// tMemFunc
$formulaData .= pack('Cvvvvv', 0x3b, $i, 0, 65535, $colmin, $colmax);
// tArea3d
$formulaData .= pack('Cvvvvv', 0x3b, $i, $rowmin, $rowmax, 0, 255);
// tArea3d
$formulaData .= pack('C', 0x10);
// tList
// store the DEFINEDNAME record
$chunk .= $this->writeData($this->writeDefinedNameBiff8(pack('C', 0x7), $formulaData, $i + 1, true));
// (exclusive) either repeatColumns or repeatRows
} elseif ($sheetSetup->isColumnsToRepeatAtLeftSet() || $sheetSetup->isRowsToRepeatAtTopSet()) {
// Columns to repeat
if ($sheetSetup->isColumnsToRepeatAtLeftSet()) {
$repeat = $sheetSetup->getColumnsToRepeatAtLeft();
$colmin = PHPExcel_Cell::columnIndexFromString($repeat[0]) - 1;
$colmax = PHPExcel_Cell::columnIndexFromString($repeat[1]) - 1;
} else {
$colmin = 0;
$colmax = 255;
}
// Rows to repeat
if ($sheetSetup->isRowsToRepeatAtTopSet()) {
$repeat = $sheetSetup->getRowsToRepeatAtTop();
$rowmin = $repeat[0] - 1;
$rowmax = $repeat[1] - 1;
} else {
$rowmin = 0;
$rowmax = 65535;
}
// construct formula data manually because parser does not recognize absolute 3d cell references
$formulaData = pack('Cvvvvv', 0x3b, $i, $rowmin, $rowmax, $colmin, $colmax);
// store the DEFINEDNAME record
$chunk .= $this->writeData($this->writeDefinedNameBiff8(pack('C', 0x7), $formulaData, $i + 1, true));
}
}
// write the print areas, if any
for ($i = 0; $i < $total_worksheets; ++$i) {
$sheetSetup = $this->phpExcel->getSheet($i)->getPageSetup();
if ($sheetSetup->isPrintAreaSet()) {
// Print area, e.g. A3:J6,H1:X20
$printArea = PHPExcel_Cell::splitRange($sheetSetup->getPrintArea());
$countPrintArea = count($printArea);
//.........这里部分代码省略.........
示例6: rebindParent
/**
* Re-bind parent
*
* @param PHPExcel $parent
*/
public function rebindParent(PHPExcel $parent)
{
$namedRanges = $this->_parent->getNamedRanges();
foreach ($namedRanges as $namedRange) {
$parent->addNamedRange($namedRange);
}
$this->_parent->removeSheetByIndex($this->_parent->getIndex($this));
$this->_parent = $parent;
}
示例7: _writeMsoDrawingGroup
/**
* Writes the MSODRAWINGGROUP record if needed. Possibly split using CONTINUE records.
*/
private function _writeMsoDrawingGroup()
{
// any drawings in this workbook?
$found = false;
foreach ($this->_phpExcel->getAllSheets() as $sheet) {
if (count($sheet->getDrawingCollection()) > 0) {
$found = true;
}
}
// if there are drawings, then we need to write MSODRAWINGGROUP record
if ($found) {
// create intermediate Escher object
$escher = new PHPExcel_Shared_Escher();
// dggContainer
$dggContainer = new PHPExcel_Shared_Escher_DggContainer();
$escher->setDggContainer($dggContainer);
// this loop is for determining maximum shape identifier of all drawing
$spIdMax = 0;
$totalCountShapes = 0;
$countDrawings = 0;
foreach ($this->_phpExcel->getAllsheets() as $sheet) {
$sheetCountShapes = 0;
// count number of shapes (minus group shape), in sheet
if (count($sheet->getDrawingCollection()) > 0) {
++$countDrawings;
foreach ($sheet->getDrawingCollection() as $drawing) {
++$sheetCountShapes;
++$totalCountShapes;
$spId = $sheetCountShapes | $this->_phpExcel->getIndex($sheet) + 1 << 10;
$spIdMax = max($spId, $spIdMax);
}
}
}
$dggContainer->setSpIdMax($spIdMax + 1);
$dggContainer->setCDgSaved($countDrawings);
$dggContainer->setCSpSaved($totalCountShapes + $countDrawings);
// total number of shapes incl. one group shapes per drawing
// bstoreContainer
$bstoreContainer = new PHPExcel_Shared_Escher_DggContainer_BstoreContainer();
$dggContainer->setBstoreContainer($bstoreContainer);
// the BSE's (all the images)
foreach ($this->_phpExcel->getAllsheets() as $sheet) {
foreach ($sheet->getDrawingCollection() as $drawing) {
if ($drawing instanceof PHPExcel_Worksheet_Drawing) {
$filename = $drawing->getPath();
list($imagesx, $imagesy, $imageFormat) = getimagesize($filename);
switch ($imageFormat) {
case 1:
// GIF, not supported by BIFF8, we convert to PNG
$blipType = PHPExcel_Shared_Escher_DggContainer_BstoreContainer_BSE::BLIPTYPE_PNG;
$imageResource = imagecreatefromgif($filename);
ob_start();
imagepng($imageResource);
$blipData = ob_get_contents();
ob_end_clean();
break;
case 2:
// JPEG
$blipType = PHPExcel_Shared_Escher_DggContainer_BstoreContainer_BSE::BLIPTYPE_JPEG;
$blipData = file_get_contents($filename);
break;
case 3:
// PNG
$blipType = PHPExcel_Shared_Escher_DggContainer_BstoreContainer_BSE::BLIPTYPE_PNG;
$blipData = file_get_contents($filename);
break;
case 6:
// Windows DIB (BMP), we convert to PNG
$blipType = PHPExcel_Shared_Escher_DggContainer_BstoreContainer_BSE::BLIPTYPE_PNG;
$imageResource = PHPExcel_Shared_Drawing::imagecreatefrombmp($filename);
ob_start();
imagepng($imageResource);
$blipData = ob_get_contents();
ob_end_clean();
break;
default:
continue 2;
}
$blip = new PHPExcel_Shared_Escher_DggContainer_BstoreContainer_BSE_Blip();
$blip->setData($blipData);
$BSE = new PHPExcel_Shared_Escher_DggContainer_BstoreContainer_BSE();
$BSE->setBlipType($blipType);
$BSE->setBlip($blip);
$bstoreContainer->addBSE($BSE);
} else {
if ($drawing instanceof PHPExcel_Worksheet_MemoryDrawing) {
switch ($drawing->getRenderingFunction()) {
case PHPExcel_Worksheet_MemoryDrawing::RENDERING_JPEG:
$blipType = PHPExcel_Shared_Escher_DggContainer_BstoreContainer_BSE::BLIPTYPE_JPEG;
$renderingFunction = 'imagejpeg';
break;
case PHPExcel_Worksheet_MemoryDrawing::RENDERING_GIF:
case PHPExcel_Worksheet_MemoryDrawing::RENDERING_PNG:
case PHPExcel_Worksheet_MemoryDrawing::RENDERING_DEFAULT:
$blipType = PHPExcel_Shared_Escher_DggContainer_BstoreContainer_BSE::BLIPTYPE_PNG;
$renderingFunction = 'imagepng';
break;
//.........这里部分代码省略.........
示例8: _readWindow2
/**
* Read WINDOW2 record
*/
private function _readWindow2()
{
$pos = $this->_pos;
$length = $this->_GetInt2d($this->_data, $pos + 2);
$recordData = substr($this->_data, $pos + 4, $length);
$pos += 4;
// offset: 0; size: 2; option flags
$options = $this->_GetInt2d($recordData, 0);
// bit: 1; mask: 0x0002; 0 = do not show gridlines, 1 = show gridlines
$showGridlines = (bool) ((0x2 & $options) >> 1);
$this->_phpSheet->setShowGridlines($showGridlines);
// bit: 3; mask: 0x0008; 0 = panes are not frozen, 1 = panes are frozen
$this->_frozen = (bool) ((0x8 & $options) >> 3);
// bit: 10; mask: 0x0400; 0 = sheet not active, 1 = sheet active
$isActive = (bool) ((0x400 & $options) >> 10);
if ($isActive) {
$this->_phpExcel->setActiveSheetIndex($this->_phpExcel->getIndex($this->_phpSheet));
}
// move stream pointer to next record
$this->_pos += 4 + $length;
}
示例9: visitPage
/**
* Render $page into html.
*
* This method is generally called via double-dispatch, as provided by Visitor\VisitableTrait.
*
* @param PageInterface $page
* @return string
* @throws Exception if no tables found in page.
*/
public function visitPage(PageInterface $page)
{
/** @var WritableInterface[] $writables */
$writables = [$page];
/** @var TableInterface[] $tables */
$tables = [];
while ($writables !== []) {
$writable = array_pop($writables);
if (method_exists($writable, 'getWritable') === true && $writable->getWritable() !== null) {
$writables[] = $writable->getWritable();
}
if (method_exists($writable, 'getWritables') === true) {
$writables = array_merge($writables, array_values($writable->getWritables()));
}
if ($writable instanceof TableInterface) {
$tables[] = $writable;
}
}
if ($tables === []) {
throw new Exception("No tables found in writables.");
}
$objPHPExcel = new \PHPExcel();
foreach ($tables as $table) {
// Create a sheet
$objWorkSheet = $objPHPExcel->createSheet();
if (sizeof($table->getRows()) > 0) {
// Write header
/** @var FieldInterface $field */
foreach (array_values($table->getRows()[0]->getWritableBearer()->getWritables()) as $j => $field) {
$cellIndex = static::excelRow($j) . "1";
$objWorkSheet->setCellValue($cellIndex, $field->getLabel());
$objWorkSheet->getStyle($cellIndex)->getFont()->setBold(true);
}
// Write cells
foreach ($table->getRows() as $i => $row) {
foreach (array_values($row->getWritableBearer()->getWritables()) as $j => $field) {
if ($field->getInitial() !== "") {
$cellIndex = static::excelRow($j) . ($i + 2);
$objWorkSheet->setCellValue($cellIndex, $field->getInitial());
}
}
}
} else {
$objWorkSheet->setCellValue("A1", "No records found");
}
}
// Remove worksheet 0; it was created with the file but we never wrote to it
$objPHPExcel->removeSheetByIndex(0);
// Auto size columns for each worksheet
foreach ($objPHPExcel->getWorksheetIterator() as $worksheet) {
$objPHPExcel->setActiveSheetIndex($objPHPExcel->getIndex($worksheet));
$sheet = $objPHPExcel->getActiveSheet();
$cellIterator = $sheet->getRowIterator()->current()->getCellIterator();
$cellIterator->setIterateOnlyExistingCells(true);
foreach ($cellIterator as $cell) {
$sheet->getColumnDimension($cell->getColumn())->setAutoSize(true);
}
}
$objPHPExcel->setActiveSheetIndex(0);
$objWriter = new \PHPExcel_Writer_Excel2007($objPHPExcel);
$tmp = tmpfile();
$fileLocation = stream_get_meta_data($tmp)['uri'];
ob_start();
$objWriter->save('php://output');
return ob_get_clean();
}
示例10: _readLabelSst
* This record represents a cell that contains a string. It
* replaces the LABEL record and RSTRING record used in
* BIFF2-BIFF5.
*
* -- "OpenOffice.org's Documentation of the Microsoft
* Excel File Format"
*/
private function _readLabelSst()
{
$length = self::_GetInt2d($this->_data, $this->_pos + 2);
$recordData = substr($this->_data, $this->_pos + 4, $length);
// move stream pointer to next record
$this->_pos += 4 + $length;
// offset: 0; size: 2; index to row
$row = self::_GetInt2d($recordData, 0);
// offset: 2; size: 2; index to column
$column = self::_GetInt2d($recordData, 2);
$columnString = PHPExcel_Cell::stringFromColumnIndex($column);
// Read cell?
if (!is_null($this->getReadFilter()) && $this->getReadFilter()->readCell($columnString, $row + 1, $this->_phpSheet->getTitle())) {
// offset: 4; size: 2; index to XF record
$xfIndex = self::_GetInt2d($recordData, 4);
// offset: 6; size: 4; index to SST record
$index = self::_GetInt4d($recordData, 6);
// add cell