This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | |||
| 3 | namespace PhpSpreadsheetWrapper; |
||
| 4 | |||
| 5 | use PhpOffice\PhpSpreadsheet\Cell\Cell; |
||
| 6 | use PhpOffice\PhpSpreadsheet\Cell\Coordinate; |
||
| 7 | use PhpOffice\PhpSpreadsheet\IOFactory; |
||
| 8 | use PhpOffice\PhpSpreadsheet\Spreadsheet; |
||
| 9 | use PhpOffice\PhpSpreadsheet\Style\Alignment; |
||
| 10 | use PhpOffice\PhpSpreadsheet\Style\Border; |
||
| 11 | use PhpOffice\PhpSpreadsheet\Style\Fill; |
||
| 12 | use PhpOffice\PhpSpreadsheet\Style\Font; |
||
| 13 | use PhpOffice\PhpSpreadsheet\Worksheet\Drawing; |
||
| 14 | |||
| 15 | /** |
||
| 16 | * PhpSpreadsheetWrapper |
||
| 17 | * Spreadsheetを記載しやすくするためのラッパー |
||
| 18 | */ |
||
| 19 | class PhpSpreadsheetWrapper |
||
| 20 | { |
||
| 21 | private $__phpexcel; |
||
| 22 | private $__sheet = []; |
||
| 23 | private $__deleteSheetList = []; |
||
| 24 | private static $__underlineType = [ |
||
| 25 | 'double' => Font::UNDERLINE_DOUBLE, |
||
| 26 | 'doubleaccounting' => Font::UNDERLINE_DOUBLEACCOUNTING, |
||
| 27 | 'none' => Font::UNDERLINE_NONE, |
||
| 28 | 'single' => Font::UNDERLINE_SINGLE, |
||
| 29 | 'singleaccounting' => Font::UNDERLINE_SINGLEACCOUNTING, |
||
| 30 | ]; |
||
| 31 | |||
| 32 | private static $__borderType = [ |
||
| 33 | 'none' => Border::BORDER_NONE, |
||
| 34 | 'thin' => Border::BORDER_THIN, |
||
| 35 | 'medium' => Border::BORDER_MEDIUM, |
||
| 36 | 'dashed' => Border::BORDER_DASHED, |
||
| 37 | 'dotted' => Border::BORDER_DOTTED, |
||
| 38 | 'thick' => Border::BORDER_THICK, |
||
| 39 | 'double' => Border::BORDER_DOUBLE, |
||
| 40 | 'hair' => Border::BORDER_HAIR, |
||
| 41 | 'mediumdashed' => Border::BORDER_MEDIUMDASHED, |
||
| 42 | 'dashdot' => Border::BORDER_DASHDOT, |
||
| 43 | 'mediumdashdot' => Border::BORDER_MEDIUMDASHDOT, |
||
| 44 | 'dashdotdot' => Border::BORDER_DASHDOTDOT, |
||
| 45 | 'mediumdashdotdot' => Border::BORDER_MEDIUMDASHDOTDOT, |
||
| 46 | 'slantdashdot' => Border::BORDER_SLANTDASHDOT, |
||
| 47 | ]; |
||
| 48 | |||
| 49 | private static $__alignHolizonalType = [ |
||
| 50 | 'general' => Alignment::HORIZONTAL_GENERAL, |
||
| 51 | 'center' => Alignment::HORIZONTAL_CENTER, |
||
| 52 | 'left' => Alignment::HORIZONTAL_LEFT, |
||
| 53 | 'right' => Alignment::HORIZONTAL_RIGHT, |
||
| 54 | 'justify' => Alignment::HORIZONTAL_JUSTIFY, |
||
| 55 | 'countinuous' => Alignment::HORIZONTAL_CENTER_CONTINUOUS, |
||
| 56 | ]; |
||
| 57 | |||
| 58 | private static $__alignVerticalType = [ |
||
| 59 | 'bottom' => Alignment::VERTICAL_BOTTOM, |
||
| 60 | 'center' => Alignment::VERTICAL_CENTER, |
||
| 61 | 'justify' => Alignment::VERTICAL_JUSTIFY, |
||
| 62 | 'top' => Alignment::VERTICAL_TOP, |
||
| 63 | ]; |
||
| 64 | |||
| 65 | private static $__fillType = [ |
||
| 66 | 'linear' => Fill::FILL_GRADIENT_LINEAR, |
||
| 67 | 'path' => Fill::FILL_GRADIENT_PATH, |
||
| 68 | 'none' => Fill::FILL_NONE, |
||
| 69 | 'darkdown' => Fill::FILL_PATTERN_DARKDOWN, |
||
| 70 | 'darkgray' => Fill::FILL_PATTERN_DARKGRAY, |
||
| 71 | 'darkgrid' => Fill::FILL_PATTERN_DARKGRID, |
||
| 72 | 'darkhorizontal' => Fill::FILL_PATTERN_DARKHORIZONTAL, |
||
| 73 | 'darktrellis' => Fill::FILL_PATTERN_DARKTRELLIS, |
||
| 74 | 'darkup' => Fill::FILL_PATTERN_DARKUP, |
||
| 75 | 'darkvertical' => Fill::FILL_PATTERN_DARKVERTICAL, |
||
| 76 | 'gray0625' => Fill::FILL_PATTERN_GRAY0625, |
||
| 77 | 'gray125' => Fill::FILL_PATTERN_GRAY125, |
||
| 78 | 'lightdown' => Fill::FILL_PATTERN_LIGHTDOWN, |
||
| 79 | 'lightgray' => Fill::FILL_PATTERN_LIGHTGRAY, |
||
| 80 | 'lightgrid' => Fill::FILL_PATTERN_LIGHTGRID, |
||
| 81 | 'lighthorizontal' => Fill::FILL_PATTERN_LIGHTHORIZONTAL, |
||
| 82 | 'lighttrellis' => Fill::FILL_PATTERN_LIGHTTRELLIS, |
||
| 83 | 'lightup' => Fill::FILL_PATTERN_LIGHTUP, |
||
| 84 | 'lightvertical' => Fill::FILL_PATTERN_LIGHTVERTICAL, |
||
| 85 | 'mediumgray' => Fill::FILL_PATTERN_MEDIUMGRAY, |
||
| 86 | 'solid' => Fill::FILL_SOLID, |
||
| 87 | ]; |
||
| 88 | |||
| 89 | /** |
||
| 90 | * __construct |
||
| 91 | * |
||
| 92 | * @param string $template テンプレートファイルのパス |
||
| 93 | * @author hagiwara |
||
| 94 | */ |
||
| 95 | public function __construct($template = null, $type = 'Xlsx') |
||
| 96 | { |
||
| 97 | if ($template === null) { |
||
| 98 | //テンプレート無し |
||
| 99 | $this->__phpexcel = new Spreadsheet(); |
||
| 100 | } else { |
||
| 101 | //テンプレートの読み込み |
||
| 102 | $reader = IOFactory::createReader($type); |
||
| 103 | $this->__phpexcel = $reader->load($template); |
||
| 104 | } |
||
| 105 | } |
||
| 106 | |||
| 107 | /** |
||
| 108 | * setVal |
||
| 109 | * 値のセット |
||
| 110 | * @param string $value 値 |
||
| 111 | * @param integer $col 行 |
||
| 112 | * @param integer $row 列 |
||
| 113 | * @param integer $sheetNo シート番号 |
||
| 114 | * @param integer $refCol 参照セル行 |
||
| 115 | * @param integer $refRow 参照セル列 |
||
| 116 | * @param integer $refSheet 参照シート |
||
| 117 | * @param string $dataType 書き込みするデータの方を強制的に指定 |
||
| 118 | * @author hagiwara |
||
| 119 | */ |
||
| 120 | public function setVal($value, $col, $row, $sheetNo = 0, $refCol = null, $refRow = null, $refSheet = 0, $dataType = null) |
||
| 121 | { |
||
| 122 | $cellInfo = $this->cellInfo($col, $row); |
||
| 123 | //値のセット |
||
| 124 | if (is_null($dataType)) { |
||
| 125 | $this->getSheet($sheetNo)->setCellValue($cellInfo, $value); |
||
| 126 | } else { |
||
| 127 | $this->getSheet($sheetNo)->getCell($cellInfo)->setValueExplicit($value, $dataType); |
||
| 128 | } |
||
| 129 | |||
| 130 | //参照セルの指定がある場合には書式をコピーする |
||
| 131 | if (!is_null($refCol) && !is_null($refRow)) { |
||
| 132 | $this->styleCopy($col, $row, $sheetNo, $refCol, $refRow, $refSheet); |
||
| 133 | } |
||
| 134 | } |
||
| 135 | |||
| 136 | /** |
||
| 137 | * getVal |
||
| 138 | * 値の取得 |
||
| 139 | * @param integer $col 行 |
||
| 140 | * @param integer $row 列 |
||
| 141 | * @param integer $sheetNo シート番号 |
||
| 142 | * @author hagiwara |
||
| 143 | */ |
||
| 144 | public function getVal($col, $row, $sheetNo = 0) |
||
| 145 | { |
||
| 146 | $cellInfo = $this->cellInfo($col, $row); |
||
| 147 | //値の取得 |
||
| 148 | return $this->getSheet($sheetNo)->getCell($cellInfo)->getValue(); |
||
| 149 | } |
||
| 150 | |||
| 151 | /** |
||
| 152 | * getPlainVal |
||
| 153 | * 値の取得 |
||
| 154 | * @param integer $col 行 |
||
| 155 | * @param integer $row 列 |
||
| 156 | * @param integer $sheetNo シート番号 |
||
| 157 | * @author hagiwara |
||
| 158 | */ |
||
| 159 | public function getPlainVal($col, $row, $sheetNo = 0) |
||
| 160 | { |
||
| 161 | $val = $this->getVal($col, $row, $sheetNo); |
||
| 162 | |||
| 163 | // RichTextが来たときにplainのtextを返すため |
||
| 164 | if (is_object($val) && is_a($val, '\PhpOffice\PhpSpreadsheet\RichText\RichText')) { |
||
| 165 | $val = $val-> getPlainText(); |
||
| 166 | } |
||
| 167 | return $val; |
||
| 168 | } |
||
| 169 | |||
| 170 | /** |
||
| 171 | * setImage |
||
| 172 | * 画像のセット |
||
| 173 | * @param string $img 画像のファイルパス |
||
| 174 | * @param integer $col 行 |
||
| 175 | * @param integer $row 列 |
||
| 176 | * @param integer $sheetNo シート番号 |
||
| 177 | * @param integer $height 画像の縦幅 |
||
| 178 | * @param integer $width 画像の横幅 |
||
| 179 | * @param boolean $proportial 縦横比を維持するか |
||
| 180 | * @param integer $offsetx セルから何ピクセルずらすか(X軸) |
||
| 181 | * @param integer $offsety セルから何ピクセルずらすか(Y軸) |
||
| 182 | * @author hagiwara |
||
| 183 | */ |
||
| 184 | public function setImage($img, $col, $row, $sheetNo = 0, $height = null, $width = null, $proportial = false, $offsetx = null, $offsety = null) |
||
| 185 | { |
||
| 186 | $cellInfo = $this->cellInfo($col, $row); |
||
| 187 | |||
| 188 | $objDrawing = new Drawing();//画像用のオプジェクト作成 |
||
| 189 | $objDrawing->setPath($img);//貼り付ける画像のパスを指定 |
||
| 190 | $objDrawing->setCoordinates($cellInfo);//位置 |
||
| 191 | if (!is_null($proportial)) { |
||
| 192 | $objDrawing->setResizeProportional($proportial);//縦横比の変更なし |
||
| 193 | } |
||
| 194 | if (!is_null($height)) { |
||
| 195 | $objDrawing->setHeight($height);//画像の高さを指定 |
||
| 196 | } |
||
| 197 | if (!is_null($width)) { |
||
| 198 | $objDrawing->setWidth($width);//画像の高さを指定 |
||
| 199 | } |
||
| 200 | if (!is_null($offsetx)) { |
||
| 201 | $objDrawing->setOffsetX($offsetx);//指定した位置からどれだけ横方向にずらすか。 |
||
| 202 | } |
||
| 203 | if (!is_null($offsety)) { |
||
| 204 | $objDrawing->setOffsetY($offsety);//指定した位置からどれだけ縦方向にずらすか。 |
||
| 205 | } |
||
| 206 | $objDrawing->setWorksheet($this->getSheet($sheetNo)); |
||
| 207 | } |
||
| 208 | |||
| 209 | /** |
||
| 210 | * cellMerge |
||
| 211 | * セルのマージ |
||
| 212 | * @param integer $col1 行 |
||
| 213 | * @param integer $row1 列 |
||
| 214 | * @param integer $col2 行 |
||
| 215 | * @param integer $row2 列 |
||
| 216 | * @param integer $sheetNo シート番号 |
||
| 217 | * @author hagiwara |
||
| 218 | */ |
||
| 219 | public function cellMerge($col1, $row1, $col2, $row2, $sheetNo) |
||
| 220 | { |
||
| 221 | $cell1Info = $this->cellInfo($col1, $row1); |
||
| 222 | $cell2Info = $this->cellInfo($col2, $row2); |
||
| 223 | |||
| 224 | $this->getSheet($sheetNo)->mergeCells($cell1Info . ':' . $cell2Info); |
||
| 225 | } |
||
| 226 | |||
| 227 | |||
| 228 | /** |
||
| 229 | * styleCopy |
||
| 230 | * セルの書式コピー |
||
| 231 | * @param integer $col 行 |
||
| 232 | * @param integer $row 列 |
||
| 233 | * @param integer $sheetNo シート番号 |
||
| 234 | * @param integer $refCol 参照セル行 |
||
| 235 | * @param integer $refRow 参照セル列 |
||
| 236 | * @param integer $refSheet 参照シート |
||
| 237 | * @author hagiwara |
||
| 238 | */ |
||
| 239 | public function styleCopy($col, $row, $sheetNo, $refCol, $refRow, $refSheet) |
||
| 240 | { |
||
| 241 | $cellInfo = $this->cellInfo($col, $row); |
||
| 242 | $refCellInfo = $this->cellInfo($refCol, $refRow); |
||
| 243 | $style = $this->getSheet($refSheet)->getStyle($refCellInfo); |
||
| 244 | |||
| 245 | $this->getSheet($sheetNo)->duplicateStyle($style, $cellInfo); |
||
| 246 | } |
||
| 247 | |||
| 248 | /** |
||
| 249 | * setStyle |
||
| 250 | * 書式のセット(まとめて) |
||
| 251 | * @param integer $col 行 |
||
| 252 | * @param integer $row 列 |
||
| 253 | * @param integer $sheetNo シート番号 |
||
| 254 | * @param array $style スタイル情報 |
||
| 255 | * @author hagiwara |
||
| 256 | */ |
||
| 257 | public function setStyle($col, $row, $sheetNo, $style) |
||
| 258 | { |
||
| 259 | $default_style = [ |
||
| 260 | 'font' => null, |
||
| 261 | 'underline' => null, |
||
| 262 | 'bold' => null, |
||
| 263 | 'italic' => null, |
||
| 264 | 'strikethrough' => null, |
||
| 265 | 'color' => null, |
||
| 266 | 'size' => null, |
||
| 267 | 'alignh' => null, |
||
| 268 | 'alignv' => null, |
||
| 269 | 'bgcolor' => null, |
||
| 270 | 'bgpattern' => null, |
||
| 271 | 'border' => null, |
||
| 272 | ]; |
||
| 273 | $style = array_merge($default_style, $style); |
||
| 274 | $this->setFontName($col, $row, $sheetNo, $style['font']); |
||
| 275 | $this->setUnderline($col, $row, $sheetNo, $style['underline']); |
||
| 276 | $this->setFontBold($col, $row, $sheetNo, $style['bold']); |
||
| 277 | $this->setItalic($col, $row, $sheetNo, $style['italic']); |
||
| 278 | $this->setStrikethrough($col, $row, $sheetNo, $style['strikethrough']); |
||
| 279 | $this->setColor($col, $row, $sheetNo, $style['color']); |
||
| 280 | $this->setSize($col, $row, $sheetNo, $style['size']); |
||
| 281 | $this->setAlignHolizonal($col, $row, $sheetNo, $style['alignh']); |
||
| 282 | $this->setAlignVertical($col, $row, $sheetNo, $style['alignv']); |
||
| 283 | $this->setBackgroundColor($col, $row, $sheetNo, $style['bgcolor'], $style['bgpattern']); |
||
| 284 | $this->setBorder($col, $row, $sheetNo, $style['border']); |
||
| 285 | } |
||
| 286 | |||
| 287 | /** |
||
| 288 | * setFontName |
||
| 289 | * フォントのセット |
||
| 290 | * @param integer $col 行 |
||
| 291 | * @param integer $row 列 |
||
| 292 | * @param integer $sheetNo シート番号 |
||
| 293 | * @param string|null $fontName フォント名 |
||
| 294 | * @author hagiwara |
||
| 295 | */ |
||
| 296 | public function setFontName($col, $row, $sheetNo, $fontName) |
||
| 297 | { |
||
| 298 | if (is_null($fontName)) { |
||
| 299 | return; |
||
| 300 | } |
||
| 301 | $this->getFont($col, $row, $sheetNo)->setName($fontName); |
||
| 302 | } |
||
| 303 | |||
| 304 | /** |
||
| 305 | * setUnderline |
||
| 306 | * 下線のセット |
||
| 307 | * @param integer $col 行 |
||
| 308 | * @param integer $row 列 |
||
| 309 | * @param integer $sheetNo シート番号 |
||
| 310 | * @param string|null $underline 下線の種類 |
||
| 311 | * @author hagiwara |
||
| 312 | */ |
||
| 313 | public function setUnderline($col, $row, $sheetNo, $underline) |
||
| 314 | { |
||
| 315 | if (is_null($underline)) { |
||
| 316 | return; |
||
| 317 | } |
||
| 318 | $this->getFont($col, $row, $sheetNo)->setUnderline($underline); |
||
| 319 | } |
||
| 320 | |||
| 321 | |||
| 322 | /** |
||
| 323 | * getUnderlineType |
||
| 324 | * 下線の種類の設定 |
||
| 325 | * @param string $type |
||
| 326 | * @author hagiwara |
||
| 327 | */ |
||
| 328 | private function getUnderlineType($type) |
||
| 329 | { |
||
| 330 | $type_list = self::$__underlineType; |
||
| 331 | if (array_key_exists($type, $type_list)) { |
||
| 332 | return $type_list[$type]; |
||
| 333 | } |
||
| 334 | return Border::UNDERLINE_NONE; |
||
| 335 | } |
||
| 336 | |||
| 337 | /** |
||
| 338 | * setFontBold |
||
| 339 | * 太字のセット |
||
| 340 | * @param integer $col 行 |
||
| 341 | * @param integer $row 列 |
||
| 342 | * @param integer $sheetNo シート番号 |
||
| 343 | * @param boolean|null $bold 太字を引くか |
||
| 344 | * @author hagiwara |
||
| 345 | */ |
||
| 346 | public function setFontBold($col, $row, $sheetNo, $bold) |
||
| 347 | { |
||
| 348 | if (is_null($bold)) { |
||
| 349 | return; |
||
| 350 | } |
||
| 351 | $this->getFont($col, $row, $sheetNo)->setBold($bold); |
||
| 352 | } |
||
| 353 | |||
| 354 | /** |
||
| 355 | * setItalic |
||
| 356 | * イタリックのセット |
||
| 357 | * @param integer $col 行 |
||
| 358 | * @param integer $row 列 |
||
| 359 | * @param integer $sheetNo シート番号 |
||
| 360 | * @param boolean|null $italic イタリックにするか |
||
| 361 | * @author hagiwara |
||
| 362 | */ |
||
| 363 | public function setItalic($col, $row, $sheetNo, $italic) |
||
| 364 | { |
||
| 365 | if (is_null($italic)) { |
||
| 366 | return; |
||
| 367 | } |
||
| 368 | $this->getFont($col, $row, $sheetNo)->setItalic($italic); |
||
| 369 | } |
||
| 370 | |||
| 371 | /** |
||
| 372 | * setStrikethrough |
||
| 373 | * 打ち消し線のセット |
||
| 374 | * @param integer $col 行 |
||
| 375 | * @param integer $row 列 |
||
| 376 | * @param integer $sheetNo シート番号 |
||
| 377 | * @param boolean|null $strikethrough 打ち消し線をつけるか |
||
| 378 | * @author hagiwara |
||
| 379 | */ |
||
| 380 | public function setStrikethrough($col, $row, $sheetNo, $strikethrough) |
||
| 381 | { |
||
| 382 | if (is_null($strikethrough)) { |
||
| 383 | return; |
||
| 384 | } |
||
| 385 | var_dump($col); |
||
|
0 ignored issues
–
show
Security
Debugging Code
introduced
by
Loading history...
|
|||
| 386 | var_dump($row); |
||
| 387 | var_dump($sheetNo); |
||
| 388 | var_dump($strikethrough); |
||
| 389 | $this->getFont($col, $row, $sheetNo)->setStrikethrough($strikethrough); |
||
| 390 | } |
||
| 391 | |||
| 392 | /** |
||
| 393 | * setColor |
||
| 394 | * 文字の色 |
||
| 395 | * @param integer $col 行 |
||
| 396 | * @param integer $row 列 |
||
| 397 | * @param integer $sheetNo シート番号 |
||
| 398 | * @param string|null $color 色(ARGB) |
||
| 399 | * @author hagiwara |
||
| 400 | */ |
||
| 401 | public function setColor($col, $row, $sheetNo, $color) |
||
| 402 | { |
||
| 403 | if (is_null($color)) { |
||
| 404 | return; |
||
| 405 | } |
||
| 406 | $this->getFont($col, $row, $sheetNo)->getColor()->setARGB($color); |
||
| 407 | } |
||
| 408 | |||
| 409 | /** |
||
| 410 | * setSize |
||
| 411 | * 文字サイズ |
||
| 412 | * @param integer $col 行 |
||
| 413 | * @param integer $row 列 |
||
| 414 | * @param integer $sheetNo シート番号 |
||
| 415 | * @param integer|null $size |
||
| 416 | * @author hagiwara |
||
| 417 | */ |
||
| 418 | public function setSize($col, $row, $sheetNo, $size) |
||
| 419 | { |
||
| 420 | if (is_null($size)) { |
||
| 421 | return; |
||
| 422 | } |
||
| 423 | $this->getFont($col, $row, $sheetNo)->setSize($size); |
||
| 424 | } |
||
| 425 | |||
| 426 | /** |
||
| 427 | * getFont |
||
| 428 | * fontデータ取得 |
||
| 429 | * @param integer $col 行 |
||
| 430 | * @param integer $row 列 |
||
| 431 | * @param integer $sheetNo シート番号 |
||
| 432 | * @author hagiwara |
||
| 433 | */ |
||
| 434 | private function getFont($col, $row, $sheetNo) |
||
| 435 | { |
||
| 436 | $cellInfo = $this->cellInfo($col, $row); |
||
| 437 | return $this->getSheet($sheetNo)->getStyle($cellInfo)->getFont(); |
||
| 438 | } |
||
| 439 | |||
| 440 | /** |
||
| 441 | * setAlignHolizonal |
||
| 442 | * 水平方向のalign |
||
| 443 | * @param integer $col 行 |
||
| 444 | * @param integer $row 列 |
||
| 445 | * @param integer $sheetNo シート番号 |
||
| 446 | * @param string|null $type |
||
| 447 | * typeはgetAlignHolizonalType参照 |
||
| 448 | * @author hagiwara |
||
| 449 | */ |
||
| 450 | public function setAlignHolizonal($col, $row, $sheetNo, $type) |
||
| 451 | { |
||
| 452 | if (is_null($type)) { |
||
| 453 | return; |
||
| 454 | } |
||
| 455 | $this->getAlignment($col, $row, $sheetNo)->setHorizontal($this->getAlignHolizonalType($type)); |
||
| 456 | } |
||
| 457 | |||
| 458 | /** |
||
| 459 | * setAlignVertical |
||
| 460 | * 垂直方法のalign |
||
| 461 | * @param integer $col 行 |
||
| 462 | * @param integer $row 列 |
||
| 463 | * @param integer $sheetNo シート番号 |
||
| 464 | * @param string|null $type |
||
| 465 | * typeはgetAlignVerticalType参照 |
||
| 466 | * @author hagiwara |
||
| 467 | */ |
||
| 468 | public function setAlignVertical($col, $row, $sheetNo, $type) |
||
| 469 | { |
||
| 470 | if (is_null($type)) { |
||
| 471 | return; |
||
| 472 | } |
||
| 473 | $this->getAlignment($col, $row, $sheetNo)->setVertical($this->getAlignVerticalType($type)); |
||
| 474 | } |
||
| 475 | |||
| 476 | /** |
||
| 477 | * getAlignment |
||
| 478 | * alignmentデータ取得 |
||
| 479 | * @param integer $col 行 |
||
| 480 | * @param integer $row 列 |
||
| 481 | * @param integer $sheetNo シート番号 |
||
| 482 | * @author hagiwara |
||
| 483 | */ |
||
| 484 | private function getAlignment($col, $row, $sheetNo) |
||
| 485 | { |
||
| 486 | $cellInfo = $this->cellInfo($col, $row); |
||
| 487 | return $this->getSheet($sheetNo)->getStyle($cellInfo)->getAlignment(); |
||
| 488 | } |
||
| 489 | |||
| 490 | /** |
||
| 491 | * setBorder |
||
| 492 | * 罫線の設定 |
||
| 493 | * @param integer $col 行 |
||
| 494 | * @param integer $row 列 |
||
| 495 | * @param integer $sheetNo シート番号 |
||
| 496 | * @param array|null $border |
||
| 497 | * borderの内部はgetBorderType参照 |
||
| 498 | * @author hagiwara |
||
| 499 | */ |
||
| 500 | public function setBorder($col, $row, $sheetNo, $border) |
||
| 501 | { |
||
| 502 | if (is_null($border)) { |
||
| 503 | return; |
||
| 504 | } |
||
| 505 | $cellInfo = $this->cellInfo($col, $row); |
||
| 506 | $default_border = [ |
||
| 507 | 'left' => null, |
||
| 508 | 'right' => null, |
||
| 509 | 'top' => null, |
||
| 510 | 'bottom' => null, |
||
| 511 | 'diagonal' => null, |
||
| 512 | 'all_borders' => null, |
||
| 513 | 'outline' => null, |
||
| 514 | 'inside' => null, |
||
| 515 | 'vertical' => null, |
||
| 516 | 'horizontal' => null, |
||
| 517 | ]; |
||
| 518 | $border = array_merge($default_border, $border); |
||
| 519 | foreach ($border as $border_position => $border_setting) { |
||
| 520 | if (!is_null($border_setting)) { |
||
| 521 | $borderInfo = $this->getSheet($sheetNo)->getStyle($cellInfo)->getBorders()->{'get' . $this->camelize($border_position)}(); |
||
| 522 | if (array_key_exists('type', $border_setting)) { |
||
| 523 | $borderInfo->setBorderStyle($this->getBorderType($border_setting['type'])); |
||
| 524 | } |
||
| 525 | if (array_key_exists('color', $border_setting)) { |
||
| 526 | $borderInfo->getColor()->setARGB($border_setting['color']); |
||
| 527 | } |
||
| 528 | } |
||
| 529 | } |
||
| 530 | } |
||
| 531 | |||
| 532 | /** |
||
| 533 | * setBackgroundColor |
||
| 534 | * 背景色の設定 |
||
| 535 | * @param integer $col 行 |
||
| 536 | * @param integer $row 列 |
||
| 537 | * @param integer $sheetNo シート番号 |
||
| 538 | * @param string $color 色 |
||
| 539 | * @param string $fillType 塗りつぶし方(デフォルトsolid) |
||
| 540 | * fillTypeの内部はgetFillType参照 |
||
| 541 | * @author hagiwara |
||
| 542 | */ |
||
| 543 | public function setBackgroundColor($col, $row, $sheetNo, $color, $fillType = 'solid') |
||
| 544 | { |
||
| 545 | $cellInfo = $this->cellInfo($col, $row); |
||
| 546 | |||
| 547 | $this->getSheet($sheetNo)->getStyle($cellInfo)->getFill()->setFillType($this->getFillType($fillType))->getStartColor()->setARGB($color); |
||
| 548 | } |
||
| 549 | |||
| 550 | /** |
||
| 551 | * getBorderType |
||
| 552 | * 罫線の種類の設定 |
||
| 553 | * @param string $type |
||
| 554 | * @author hagiwara |
||
| 555 | */ |
||
| 556 | private function getBorderType($type) |
||
| 557 | { |
||
| 558 | $type_list = self::$__borderType; |
||
| 559 | if (array_key_exists($type, $type_list)) { |
||
| 560 | return $type_list[$type]; |
||
| 561 | } |
||
| 562 | return Border::BORDER_NONE; |
||
| 563 | } |
||
| 564 | |||
| 565 | /** |
||
| 566 | * getAlignHolizonalType |
||
| 567 | * 水平方向のAlignの設定 |
||
| 568 | * @param string $type |
||
| 569 | * @author hagiwara |
||
| 570 | */ |
||
| 571 | private function getAlignHolizonalType($type) |
||
| 572 | { |
||
| 573 | $type_list = self::$__alignHolizonalType; |
||
| 574 | if (array_key_exists($type, $type_list)) { |
||
| 575 | return $type_list[$type]; |
||
| 576 | } |
||
| 577 | return Alignment::HORIZONTAL_GENERAL; |
||
| 578 | } |
||
| 579 | |||
| 580 | /** |
||
| 581 | * getAlignVerticalType |
||
| 582 | * 垂直方向のAlignの設定 |
||
| 583 | * @param string $type |
||
| 584 | * @author hagiwara |
||
| 585 | */ |
||
| 586 | private function getAlignVerticalType($type) |
||
| 587 | { |
||
| 588 | $type_list = self::$__alignVerticalType; |
||
| 589 | if (array_key_exists($type, $type_list)) { |
||
| 590 | return $type_list[$type]; |
||
| 591 | } |
||
| 592 | return null; |
||
| 593 | } |
||
| 594 | |||
| 595 | /** |
||
| 596 | * getFillType |
||
| 597 | * 塗りつぶしの設定 |
||
| 598 | * @param string $type |
||
| 599 | * @author hagiwara |
||
| 600 | */ |
||
| 601 | private function getFillType($type) |
||
| 602 | { |
||
| 603 | $type_list = self::$__fillType; |
||
| 604 | if (array_key_exists($type, $type_list)) { |
||
| 605 | return $type_list[$type]; |
||
| 606 | } |
||
| 607 | return Fill::FILL_SOLID; |
||
| 608 | } |
||
| 609 | |||
| 610 | /** |
||
| 611 | * createSheet |
||
| 612 | * シートの作成 |
||
| 613 | * @param string $name |
||
| 614 | * @author hagiwara |
||
| 615 | */ |
||
| 616 | public function createSheet($name = null) |
||
| 617 | { |
||
| 618 | //シートの新規作成 |
||
| 619 | $newSheet = $this->__phpexcel->createSheet(); |
||
| 620 | $sheetNo = $this->__phpexcel->getIndex($newSheet); |
||
| 621 | $this->__sheet[$sheetNo] = $newSheet; |
||
| 622 | if (!is_null($name)) { |
||
| 623 | $this->renameSheet($sheetNo, $name); |
||
| 624 | } |
||
| 625 | } |
||
| 626 | |||
| 627 | /** |
||
| 628 | * deleteSheet |
||
| 629 | * シートの削除 |
||
| 630 | * @param integer $sheetNo |
||
| 631 | * @author hagiwara |
||
| 632 | */ |
||
| 633 | public function deleteSheet($sheetNo) |
||
| 634 | { |
||
| 635 | //シートの削除は一番最後に行う |
||
| 636 | $this->__deleteSheetList[] = $sheetNo; |
||
| 637 | } |
||
| 638 | |||
| 639 | /** |
||
| 640 | * copySheet |
||
| 641 | * シートのコピー |
||
| 642 | * @param integer $sheetNo |
||
| 643 | * @param integer $position |
||
| 644 | * @param string $name |
||
| 645 | * @author hagiwara |
||
| 646 | */ |
||
| 647 | public function copySheet($sheetNo, $position = null, $name = null) |
||
| 648 | { |
||
| 649 | $base = $this->getSheet($sheetNo)->copy(); |
||
| 650 | if ($name === null) { |
||
| 651 | $name = uniqid(); |
||
| 652 | } |
||
| 653 | $base->setTitle($name); |
||
| 654 | |||
| 655 | // $positionが null(省略時含む)の場合は最後尾に追加される |
||
| 656 | $this->__phpexcel->addSheet($base, $position); |
||
| 657 | } |
||
| 658 | |||
| 659 | /** |
||
| 660 | * renameSheet |
||
| 661 | * シート名の変更 |
||
| 662 | * @param integer $sheetNo |
||
| 663 | * @param string $name |
||
| 664 | * @author hagiwara |
||
| 665 | */ |
||
| 666 | public function renameSheet($sheetNo, $name) |
||
| 667 | { |
||
| 668 | $this->getSheet($sheetNo)->setTitle($name); |
||
| 669 | } |
||
| 670 | |||
| 671 | /** |
||
| 672 | * write |
||
| 673 | * xlsxファイルの書き込み |
||
| 674 | * @param string $file 書き込み先のファイルパス |
||
| 675 | * @author hagiwara |
||
| 676 | */ |
||
| 677 | public function write($file, $type = 'Xlsx') |
||
| 678 | { |
||
| 679 | //書き込み前に削除シートを削除する |
||
| 680 | foreach ($this->__deleteSheetList as $deleteSheet) { |
||
| 681 | $this->__phpexcel->removeSheetByIndex($deleteSheet); |
||
| 682 | } |
||
| 683 | $writer = IOFactory::createWriter($this->__phpexcel, $type); |
||
| 684 | $writer->save($file); |
||
| 685 | } |
||
| 686 | |||
| 687 | /** |
||
| 688 | * getReader |
||
| 689 | * readerを返す(※直接Spreadsheetの関数を実行できるように) |
||
| 690 | * @author hagiwara |
||
| 691 | */ |
||
| 692 | public function getReader() |
||
| 693 | { |
||
| 694 | return $this->__phpexcel; |
||
| 695 | } |
||
| 696 | |||
| 697 | /** |
||
| 698 | * getSheet |
||
| 699 | * シート情報の読み込み |
||
| 700 | * @param integer $sheetNo シート番号 |
||
| 701 | * @author hagiwara |
||
| 702 | * @return null|\Spreadsheet_Worksheet |
||
| 703 | */ |
||
| 704 | private function getSheet($sheetNo) |
||
| 705 | { |
||
| 706 | if (!array_key_exists($sheetNo, $this->__sheet)) { |
||
| 707 | $this->__sheet[$sheetNo] = $this->__phpexcel->setActiveSheetIndex($sheetNo); |
||
| 708 | } |
||
| 709 | return $this->__sheet[$sheetNo]; |
||
| 710 | } |
||
| 711 | |||
| 712 | /** |
||
| 713 | * cellInfo |
||
| 714 | * R1C1参照をA1参照に変換して返す |
||
| 715 | * @param integer $col 行 |
||
| 716 | * @param integer $row 列 |
||
| 717 | * @author hagiwara |
||
| 718 | */ |
||
| 719 | private function cellInfo($col, $row) |
||
| 720 | { |
||
| 721 | $stringCol = Coordinate::stringFromColumnIndex($col); |
||
| 722 | return $stringCol . $row; |
||
| 723 | } |
||
| 724 | |||
| 725 | /** |
||
| 726 | * cellInfo |
||
| 727 | * http://qiita.com/Hiraku/items/036080976884fad1e450 |
||
| 728 | * @param string $str |
||
| 729 | */ |
||
| 730 | private function camelize($str) |
||
| 731 | { |
||
| 732 | $str = ucwords($str, '_'); |
||
| 733 | return str_replace('_', '', $str); |
||
| 734 | } |
||
| 735 | } |
||
| 736 |