// 必要なクラスをインクルードする
set_include_path(get_include_path() . PATH_SEPARATOR . "./Classes/");
include "PHPExcel.php";
include "PHPExcel/IOFactory.php";
// PHPExcelオブジェクトを生成する
$book = new PHPExcel();
// シートの設定を行う
$book->setActiveSheetIndex(0);
$sheet = $book->getActiveSheet();
// セルを結合する
$sheet->mergeCells('A1:C5');
// Excel2007形式で保存する
$writer = PHPExcel_IOFactory::createWriter($book, "Excel2007");
$writer->save("./output.xlsx");
この例では、結合したセルがそのまま結合解除されます(意味なし)。
// 必要なクラスをインクルードする
set_include_path(get_include_path() . PATH_SEPARATOR . "./Classes/");
include "PHPExcel.php";
include "PHPExcel/IOFactory.php";
// PHPExcelオブジェクトを生成する
$book = new PHPExcel();
// シートの設定を行う
$book->setActiveSheetIndex(0);
$sheet = $book->getActiveSheet();
// セルを結合する
$sheet->mergeCells('A1:C5');
// セル結合を解除する
$sheet->unmergeCells('A1:C5');
// Excel2007形式で保存する
$writer = PHPExcel_IOFactory::createWriter($book, "Excel2007");
$writer->save("./output.xlsx");
[PHP - PHPExcel - セル操作]
セルに値をセットする 【setCellValueByColumnAndRow】
セルに式をセットする 【setCellValueByColumnAndRow】
セルの水平・垂直方向の文字位置を指定する 【PHPExcel_Style_Alignment】