本文整理汇总了PHP中PHPExcel_Worksheet::mergeCells方法的典型用法代码示例。如果您正苦于以下问题:PHP PHPExcel_Worksheet::mergeCells方法的具体用法?PHP PHPExcel_Worksheet::mergeCells怎么用?PHP PHPExcel_Worksheet::mergeCells使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PHPExcel_Worksheet
的用法示例。
在下文中一共展示了PHPExcel_Worksheet::mergeCells方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: copyRows
/**
* 行を完全コピーする
*
* http://blog.kotemaru.org/old/2012/04/06.html より
* @param PHPExcel_Worksheet $sheet
* @param int $srcRow
* @param int $dstRow
* @param int $height
* @param int $width
* @throws PHPExcel_Exception
*/
function copyRows(PHPExcel_Worksheet $sheet, $srcRow, $dstRow, $height, $width)
{
for ($row = 0; $row < $height; $row++) {
// セルの書式と値の複製
for ($col = 0; $col < $width; $col++) {
$cell = $sheet->getCellByColumnAndRow($col, $srcRow + $row);
$style = $sheet->getStyleByColumnAndRow($col, $srcRow + $row);
$dstCell = PHPExcel_Cell::stringFromColumnIndex($col) . (string) ($dstRow + $row);
$sheet->setCellValue($dstCell, $cell->getValue());
$sheet->duplicateStyle($style, $dstCell);
}
// 行の高さ複製。
$h = $sheet->getRowDimension($srcRow + $row)->getRowHeight();
$sheet->getRowDimension($dstRow + $row)->setRowHeight($h);
}
// セル結合の複製
// - $mergeCell="AB12:AC15" 複製範囲の物だけ行を加算して復元。
// - $merge="AB16:AC19"
foreach ($sheet->getMergeCells() as $mergeCell) {
$mc = explode(":", $mergeCell);
$col_s = preg_replace("/[0-9]*/", "", $mc[0]);
$col_e = preg_replace("/[0-9]*/", "", $mc[1]);
$row_s = (int) preg_replace("/[A-Z]*/", "", $mc[0]) - $srcRow;
$row_e = (int) preg_replace("/[A-Z]*/", "", $mc[1]) - $srcRow;
// 複製先の行範囲なら。
if (0 <= $row_s && $row_s < $height) {
$merge = $col_s . (string) ($dstRow + $row_s) . ":" . $col_e . (string) ($dstRow + $row_e);
$sheet->mergeCells($merge);
}
}
}
示例2: exportExcel
/**
* @param Worksheet $worksheet
* @param array $style_h2
* @return Worksheet
* @throws \PHPExcel_Exception
*/
public function exportExcel(Worksheet $worksheet, array $style_h2)
{
$last_row = $worksheet->getHighestDataRow();
$last_row += 2;
$max_col = $worksheet->getHighestDataColumn();
$worksheet->mergeCells("A{$last_row}:{$max_col}{$last_row}");
$worksheet->setCellValue("A{$last_row}", utf8_encode($this->getTitulo()));
$worksheet->getStyle("A{$last_row}:{$max_col}{$last_row}")->applyFromArray($style_h2);
$worksheet->getRowDimension($last_row)->setRowHeight(20);
$last_row += 2;
$worksheet->setCellValue("C{$last_row}", utf8_encode('Opción'));
$worksheet->setCellValue("D{$last_row}", 'Votos');
$first_row = $last_row;
$last_row += 1;
foreach ($this->getDatos() as $key => $dato) {
$worksheet->setCellValue("B{$last_row}", $key + 1);
$worksheet->setCellValue("C{$last_row}", utf8_encode($dato[0]));
if (mb_strlen($dato[0]) > 45) {
$worksheet->getRowDimension($last_row)->setRowHeight(27);
}
$worksheet->setCellValue("D{$last_row}", $dato[1]);
$last_row++;
}
$last_row -= 1;
$worksheet->getStyle("C{$first_row}:D{$last_row}")->applyFromArray($this->getEstiloTabla('center', true));
$first_row++;
$worksheet->getStyle("B{$first_row}:D{$last_row}")->applyFromArray($this->getEstiloTabla());
$first_row -= 1;
$top_chart = $first_row - 1;
$bottom_chart = $first_row + 12;
$chart1 = $this->getChart($first_row, $last_row, $top_chart, $bottom_chart);
$worksheet->addChart($chart1);
$worksheet->setCellValue("A{$bottom_chart}", "");
return $worksheet;
}
示例3: _addFilters
/**
*
*/
protected function _addFilters()
{
$pFilters = $this->_content->getElementsByTagName('p');
if (empty($pFilters->length)) {
return false;
}
$filters = array();
foreach ($pFilters->item(0)->childNodes as $child) {
$nodeValue = trim($child->nodeValue);
if (!empty($nodeValue)) {
$filters[] = $nodeValue;
}
}
$this->_mainSheet->getCell('C6')->setValue(implode(' ', $filters))->getStyle()->getAlignment()->setWrapText(true);
$this->_mainSheet->mergeCells('C6:T6');
}
示例4: insertNewBefore
//.........这里部分代码省略.........
$pSheet->refreshColumnDimensions();
// Update worksheet: row dimensions
$aRowDimensions = array_reverse($pSheet->getRowDimensions(), true);
foreach ($aRowDimensions as $objRowDimension) {
$newReference = $this->updateCellReference('A' . $objRowDimension->getRowIndex(), $pBefore, $pNumCols, $pNumRows);
list(, $newReference) = PHPExcel_Cell::coordinateFromString($newReference);
if ($objRowDimension->getRowIndex() != $newReference) {
$objRowDimension->setRowIndex($newReference);
}
}
$pSheet->refreshRowDimensions();
$copyDimension = $pSheet->getRowDimension($beforeRow - 1);
for ($i = $beforeRow; $i <= $beforeRow - 1 + $pNumRows; $i++) {
$newDimension = $pSheet->getRowDimension($i);
$newDimension->setRowHeight($copyDimension->getRowHeight());
$newDimension->setVisible($copyDimension->getVisible());
$newDimension->setOutlineLevel($copyDimension->getOutlineLevel());
$newDimension->setCollapsed($copyDimension->getCollapsed());
}
// Update worksheet: breaks
$aBreaks = array_reverse($pSheet->getBreaks(), true);
foreach ($aBreaks as $key => $value) {
$newReference = $this->updateCellReference($key, $pBefore, $pNumCols, $pNumRows);
if ($key != $newReference) {
$pSheet->setBreak( $newReference, $value );
$pSheet->setBreak( $key, PHPExcel_Worksheet::BREAK_NONE );
}
}
// Update worksheet: merge cells
$aMergeCells = array_reverse($pSheet->getMergeCells(), true);
foreach ($aMergeCells as $key => $value) {
$newReference = $this->updateCellReference($key, $pBefore, $pNumCols, $pNumRows);
if ($key != $newReference) {
$pSheet->mergeCells( $newReference );
$pSheet->unmergeCells( $key );
}
}
// Update worksheet: protected cells
$aProtectedCells = array_reverse($pSheet->getProtectedCells(), true);
foreach ($aProtectedCells as $key => $value) {
$newReference = $this->updateCellReference($key, $pBefore, $pNumCols, $pNumRows);
if ($key != $newReference) {
$pSheet->protectCells( $newReference, $value, true );
$pSheet->unprotectCells( $key );
}
}
// Update worksheet: autofilter
if ($pSheet->getAutoFilter() != '') {
$pSheet->setAutoFilter( $this->updateCellReference($pSheet->getAutoFilter(), $pBefore, $pNumCols, $pNumRows) );
}
// Update worksheet: freeze pane
if ($pSheet->getFreezePane() != '') {
$pSheet->setFreezePane( $this->updateCellReference($pSheet->getFreezePane(), $pBefore, $pNumCols, $pNumRows) );
}
// Page setup
if ($pSheet->getPageSetup()->isPrintAreaSet()) {
$pSheet->getPageSetup()->setPrintArea( $this->updateCellReference($pSheet->getPageSetup()->getPrintArea(), $pBefore, $pNumCols, $pNumRows) );
}
// Update worksheet: drawings
$aDrawings = $pSheet->getDrawingCollection();
foreach ($aDrawings as $objDrawing) {
$newReference = $this->updateCellReference($objDrawing->getCoordinates(), $pBefore, $pNumCols, $pNumRows);
if ($objDrawing->getCoordinates() != $newReference) {
$objDrawing->setCoordinates($newReference);
}
}
// Update workbook: named ranges
if (count($pSheet->getParent()->getNamedRanges()) > 0) {
foreach ($pSheet->getParent()->getNamedRanges() as $namedRange) {
if ($namedRange->getWorksheet()->getHashCode() == $pSheet->getHashCode()) {
$namedRange->setRange(
$this->updateCellReference($namedRange->getRange(), $pBefore, $pNumCols, $pNumRows)
);
}
}
}
// Garbage collect
$pSheet->garbageCollect();
}
示例5: _readMergedCells
/**
* MERGEDCELLS
*
* This record contains the addresses of merged cell ranges
* in the current sheet.
*
* -- "OpenOffice.org's Documentation of the Microsoft
* Excel File Format"
*/
private function _readMergedCells()
{
$spos = $this->_pos;
$length = $this->_GetInt2d($this->_data, $spos + 2);
$recordData = substr($this->_data, $spos + 4, $length);
$spos += 4;
if ($this->_version == self::XLS_BIFF8 && !$this->_readDataOnly) {
$cellRangeAddressList = $this->_readBIFF8CellRangeAddressList($recordData);
foreach ($cellRangeAddressList['cellRangeAddresses'] as $cellRangeAddress) {
$this->_phpSheet->mergeCells($cellRangeAddress);
}
}
$this->_pos += 4 + $length;
}
示例6: mergeAndCenter
/**
*
* @param string $range Range in format A1:A1
* @return Formatter
*/
public function mergeAndCenter($range)
{
$this->sheet->mergeCells($range);
$this->sheet->getStyle($range)->getAlignment()->setHorizontal(PhpOffice_PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
return $this;
}
示例7: readMergedCells
/**
* MERGEDCELLS
*
* This record contains the addresses of merged cell ranges
* in the current sheet.
*
* -- "OpenOffice.org's Documentation of the Microsoft
* Excel File Format"
*/
private function readMergedCells()
{
$length = self::getInt2d($this->data, $this->pos + 2);
$recordData = $this->readRecordData($this->data, $this->pos + 4, $length);
// move stream pointer to next record
$this->pos += 4 + $length;
if ($this->version == self::XLS_BIFF8 && !$this->readDataOnly) {
$cellRangeAddressList = $this->readBIFF8CellRangeAddressList($recordData);
foreach ($cellRangeAddressList['cellRangeAddresses'] as $cellRangeAddress) {
if (strpos($cellRangeAddress, ':') !== false && $this->includeCellRangeFiltered($cellRangeAddress)) {
$this->phpSheet->mergeCells($cellRangeAddress);
}
}
}
}
示例8: insertNewBefore
//.........这里部分代码省略.........
}
}
$pSheet->refreshColumnDimensions();
}
// Update worksheet: row dimensions
$aRowDimensions = array_reverse($pSheet->getRowDimensions(), true);
if (count($aRowDimensions) > 0) {
foreach ($aRowDimensions as $objRowDimension) {
$newReference = $this->updateCellReference('A' . $objRowDimension->getRowIndex(), $pBefore, $pNumCols, $pNumRows);
list(, $newReference) = PHPExcel_Cell::coordinateFromString($newReference);
if ($objRowDimension->getRowIndex() != $newReference) {
$objRowDimension->setRowIndex($newReference);
}
}
$pSheet->refreshRowDimensions();
$copyDimension = $pSheet->getRowDimension($beforeRow - 1);
for ($i = $beforeRow; $i <= $beforeRow - 1 + $pNumRows; ++$i) {
$newDimension = $pSheet->getRowDimension($i);
$newDimension->setRowHeight($copyDimension->getRowHeight());
$newDimension->setVisible($copyDimension->getVisible());
$newDimension->setOutlineLevel($copyDimension->getOutlineLevel());
$newDimension->setCollapsed($copyDimension->getCollapsed());
}
}
// Update worksheet: breaks
$aBreaks = array_reverse($pSheet->getBreaks(), true);
foreach ($aBreaks as $key => $value) {
$newReference = $this->updateCellReference($key, $pBefore, $pNumCols, $pNumRows);
if ($key != $newReference) {
$pSheet->setBreak($newReference, $value);
$pSheet->setBreak($key, PHPExcel_Worksheet::BREAK_NONE);
}
}
// Update worksheet: hyperlinks
$aHyperlinkCollection = array_reverse($pSheet->getHyperlinkCollection(), true);
foreach ($aHyperlinkCollection as $key => $value) {
$newReference = $this->updateCellReference($key, $pBefore, $pNumCols, $pNumRows);
if ($key != $newReference) {
$pSheet->setHyperlink($newReference, $value);
$pSheet->setHyperlink($key, null);
}
}
// Update worksheet: data validations
$aDataValidationCollection = array_reverse($pSheet->getDataValidationCollection(), true);
foreach ($aDataValidationCollection as $key => $value) {
$newReference = $this->updateCellReference($key, $pBefore, $pNumCols, $pNumRows);
if ($key != $newReference) {
$pSheet->setDataValidation($newReference, $value);
$pSheet->setDataValidation($key, null);
}
}
// Update worksheet: merge cells
$aMergeCells = array_reverse($pSheet->getMergeCells(), true);
foreach ($aMergeCells as $key => $value) {
$newReference = $this->updateCellReference($key, $pBefore, $pNumCols, $pNumRows);
if ($key != $newReference) {
$pSheet->mergeCells($newReference);
$pSheet->unmergeCells($key);
}
}
// Update worksheet: protected cells
$aProtectedCells = array_reverse($pSheet->getProtectedCells(), true);
foreach ($aProtectedCells as $key => $value) {
$newReference = $this->updateCellReference($key, $pBefore, $pNumCols, $pNumRows);
if ($key != $newReference) {
$pSheet->protectCells($newReference, $value, true);
$pSheet->unprotectCells($key);
}
}
// Update worksheet: autofilter
if ($pSheet->getAutoFilter() != '') {
$pSheet->setAutoFilter($this->updateCellReference($pSheet->getAutoFilter(), $pBefore, $pNumCols, $pNumRows));
}
// Update worksheet: freeze pane
if ($pSheet->getFreezePane() != '') {
$pSheet->freezePane($this->updateCellReference($pSheet->getFreezePane(), $pBefore, $pNumCols, $pNumRows));
}
// Page setup
if ($pSheet->getPageSetup()->isPrintAreaSet()) {
$pSheet->getPageSetup()->setPrintArea($this->updateCellReference($pSheet->getPageSetup()->getPrintArea(), $pBefore, $pNumCols, $pNumRows));
}
// Update worksheet: drawings
$aDrawings = $pSheet->getDrawingCollection();
foreach ($aDrawings as $objDrawing) {
$newReference = $this->updateCellReference($objDrawing->getCoordinates(), $pBefore, $pNumCols, $pNumRows);
if ($objDrawing->getCoordinates() != $newReference) {
$objDrawing->setCoordinates($newReference);
}
}
// Update workbook: named ranges
if (count($pSheet->getParent()->getNamedRanges()) > 0) {
foreach ($pSheet->getParent()->getNamedRanges() as $namedRange) {
if ($namedRange->getWorksheet()->getHashCode() == $pSheet->getHashCode()) {
$namedRange->setRange($this->updateCellReference($namedRange->getRange(), $pBefore, $pNumCols, $pNumRows));
}
}
}
// Garbage collect
$pSheet->garbageCollect();
}
示例9: mbatik
private function mbatik($data, $title)
{
$worksheet = new PHPExcel_Worksheet();
$worksheet->setTitle($title);
// Siswa Start
$worksheet->mergeCells('A3:R3');
$worksheet->setCellValue('A3', 'Data Siswa');
$worksheet->getColumnDimension('A')->setAutoSize(true);
$worksheet->SetCellValue('A4', 'No. Pendaftaran');
$worksheet->getColumnDimension('B')->setAutoSize(true);
$worksheet->SetCellValue('B4', 'NISN');
$worksheet->getColumnDimension('C')->setAutoSize(true);
$worksheet->SetCellValue('C4', 'Nama');
$worksheet->getColumnDimension('D')->setAutoSize(true);
$worksheet->SetCellValue('D4', 'Ikhwan/Akhwat');
$worksheet->getColumnDimension('E')->setAutoSize(true);
$worksheet->SetCellValue('E4', 'Sekolah Asal');
$worksheet->getColumnDimension('F')->setAutoSize(true);
$worksheet->SetCellValue('F4', 'Program');
$worksheet->getColumnDimension('G')->setAutoSize(true);
$worksheet->SetCellValue('G4', 'TTL');
$worksheet->getColumnDimension('H')->setAutoSize(true);
$worksheet->SetCellValue('H4', 'Alamat');
$worksheet->getColumnDimension('I')->setAutoSize(true);
$worksheet->SetCellValue('I4', 'Keluarga');
$worksheet->getColumnDimension('J')->setAutoSize(true);
$worksheet->SetCellValue('J4', 'Kewarganegaraan');
$worksheet->getColumnDimension('K')->setAutoSize(true);
$worksheet->SetCellValue('K4', 'Agama');
$worksheet->getColumnDimension('L')->setAutoSize(true);
$worksheet->SetCellValue('L4', 'Tinggi');
$worksheet->getColumnDimension('M')->setAutoSize(true);
$worksheet->SetCellValue('M4', 'Berat');
$worksheet->getColumnDimension('N')->setAutoSize(true);
$worksheet->SetCellValue('N4', 'Riwayat Penyakit');
$worksheet->getColumnDimension('O')->setAutoSize(true);
$worksheet->SetCellValue('O4', 'Kelainan Jasmani');
$worksheet->getColumnDimension('P')->setAutoSize(true);
$worksheet->SetCellValue('P4', 'Tinggal Bersama');
$worksheet->getColumnDimension('Q')->setAutoSize(true);
$worksheet->SetCellValue('Q4', 'Hobi');
$worksheet->getColumnDimension('R')->setAutoSize(true);
$worksheet->SetCellValue('R4', 'Prestasi');
// End Siswa
// Start Ayah
$worksheet->mergeCells('S3:AF3');
$worksheet->setCellValue('S3', 'Data Ayah');
$worksheet->getColumnDimension('S')->setAutoSize(true);
$worksheet->SetCellValue('S4', 'Nama');
$worksheet->getColumnDimension('T')->setAutoSize(true);
$worksheet->SetCellValue('T4', 'Status');
$worksheet->getColumnDimension('U')->setAutoSize(true);
$worksheet->SetCellValue('U4', 'TTL');
$worksheet->getColumnDimension('V')->setAutoSize(true);
$worksheet->SetCellValue('V4', 'Alamat');
$worksheet->getColumnDimension('W')->setAutoSize(true);
$worksheet->SetCellValue('W4', 'No. Telp');
$worksheet->getColumnDimension('X')->setAutoSize(true);
$worksheet->SetCellValue('X4', 'Hubungan dengan pendaftar');
$worksheet->getColumnDimension('Y')->setAutoSize(true);
$worksheet->SetCellValue('Y4', 'Kewarganegaraan');
$worksheet->getColumnDimension('Z')->setAutoSize(true);
$worksheet->SetCellValue('Z4', 'Agama');
$worksheet->getColumnDimension('AA')->setAutoSize(true);
$worksheet->SetCellValue('AA4', 'Tingkat Pendidikan');
$worksheet->getColumnDimension('AB')->setAutoSize(true);
$worksheet->SetCellValue('AB4', 'Pekerjaan');
$worksheet->getColumnDimension('AC')->setAutoSize(true);
$worksheet->SetCellValue('AC4', 'Jabatan');
$worksheet->getColumnDimension('AD')->setAutoSize(true);
$worksheet->SetCellValue('AD4', 'Instansi');
$worksheet->getColumnDimension('AE')->setAutoSize(true);
$worksheet->SetCellValue('AE4', 'Penghasilan');
$worksheet->getColumnDimension('AF')->setAutoSize(true);
$worksheet->SetCellValue('AF4', 'Jumlah Tanggungan');
// End Ayah
// Start Ibu
$worksheet->mergeCells('AG3:AT3');
$worksheet->setCellValue('AG3', 'Data Ibu');
$worksheet->getColumnDimension('AG')->setAutoSize(true);
$worksheet->SetCellValue('AG4', 'Nama');
$worksheet->getColumnDimension('AH')->setAutoSize(true);
$worksheet->SetCellValue('AH4', 'Status');
$worksheet->getColumnDimension('AI')->setAutoSize(true);
$worksheet->SetCellValue('AI4', 'TTL');
$worksheet->getColumnDimension('AJ')->setAutoSize(true);
$worksheet->SetCellValue('AJ4', 'Alamat');
$worksheet->getColumnDimension('AK')->setAutoSize(true);
$worksheet->SetCellValue('AK4', 'No. Telp');
$worksheet->getColumnDimension('AL')->setAutoSize(true);
$worksheet->SetCellValue('AL4', 'Hubungan dengan pendaftar');
$worksheet->getColumnDimension('AM')->setAutoSize(true);
$worksheet->SetCellValue('AM4', 'Kewarganegaraan');
$worksheet->getColumnDimension('AN')->setAutoSize(true);
$worksheet->SetCellValue('AN4', 'Agama');
$worksheet->getColumnDimension('AO')->setAutoSize(true);
$worksheet->SetCellValue('AO4', 'Tingkat Pendidikan');
$worksheet->getColumnDimension('AP')->setAutoSize(true);
$worksheet->SetCellValue('AP4', 'Pekerjaan');
$worksheet->getColumnDimension('AQ')->setAutoSize(true);
//.........这里部分代码省略.........
示例10: _readNumber
*
* -- "OpenOffice.org's Documentation of the Microsoft
* Excel File Format"
*/
private function _readNumber()
{
$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?