Skip to content

Instantly share code, notes, and snippets.

@onocom
Created October 16, 2015 06:18
Show Gist options
  • Save onocom/75afb05f19d369ef422e to your computer and use it in GitHub Desktop.
Save onocom/75afb05f19d369ef422e to your computer and use it in GitHub Desktop.
[PHPExcel] スタイルを維持したまま値を記述
<?php
public function set_value_with_style($pCoordinate = 'A1', $pValue = null, $sheet = null) {
$save_cell = 'A1'; // よっぽどA1に値が入っていることはないと想定してA1にスタイルを退避させる
if($sheet == null) $sheet = $this->current_sheet;
// A1セルに一旦スタイルを保存してから値を設定する
$sheet->duplicateStyle( $sheet->getStyle( $pCoordinate ), $save_cell );
$sheet->setCellValue($pCoordinate , $pValue);
// スタイルを元に戻す
$sheet->duplicateStyle( $sheet->getStyle( $save_cell), $pCoordinate );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment