Completed
Push — master ( bb6ccc...147b14 )
by satoru
03:20 queued 01:57
created

PhpSpreadsheetWrapper::getPlainVal()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.9332
c 0
b 0
f 0
cc 3
nc 2
nop 3
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
    * @author hagiwara
118
    */
119
    public function setVal($value, $col, $row, $sheetNo = 0, $refCol = null, $refRow = null, $refSheet = 0)
120
    {
121
        $cellInfo = $this->cellInfo($col, $row);
122
        //値のセット
123
        $this->getSheet($sheetNo)->setCellValue($cellInfo, $value);
124
125
        //参照セルの指定がある場合には書式をコピーする
126
        if (!is_null($refCol) && !is_null($refRow)) {
127
            $this->styleCopy($col, $row, $sheetNo, $refCol, $refRow, $refSheet);
128
        }
129
    }
130
131
    /**
132
    * getVal
133
    * 値の取得
134
    * @param integer $col 行
135
    * @param integer $row 列
136
    * @param integer $sheetNo シート番号
137
    * @author hagiwara
138
    */
139
    public function getVal($col, $row, $sheetNo = 0)
140
    {
141
        $cellInfo = $this->cellInfo($col, $row);
142
        //値の取得
143
        return $this->getSheet($sheetNo)->getCell($cellInfo)->getValue();
144
    }
145
146
    /**
147
    * getPlainVal
148
    * 値の取得
149
    * @param integer $col 行
150
    * @param integer $row 列
151
    * @param integer $sheetNo シート番号
152
    * @author hagiwara
153
    */
154
    public function getPlainVal($col, $row, $sheetNo = 0)
155
    {
156
        $val = $this->getVal($col, $row, $sheetNo);
157
158
        // RichTextが来たときにplainのtextを返すため
159
        if (is_object($val) && is_a($val, '\PhpOffice\PhpSpreadsheet\RichText\RichText')) {
160
            $val = $val-> getPlainText();
161
        }
162
        return $val;
163
    }
164
165
    /**
166
    * setImage
167
    * 画像のセット
168
    * @param string $img 画像のファイルパス
169
    * @param integer $col 行
170
    * @param integer $row 列
171
    * @param integer $sheetNo シート番号
172
    * @param integer $height 画像の縦幅
173
    * @param integer $width 画像の横幅
174
    * @param boolean $proportial 縦横比を維持するか
175
    * @param integer $offsetx セルから何ピクセルずらすか(X軸)
176
    * @param integer $offsety セルから何ピクセルずらすか(Y軸)
177
    * @author hagiwara
178
    */
179
    public function setImage($img, $col, $row, $sheetNo = 0, $height = null, $width = null, $proportial = false, $offsetx = null, $offsety = null)
180
    {
181
        $cellInfo = $this->cellInfo($col, $row);
182
183
        $objDrawing = new Drawing();//画像用のオプジェクト作成
184
        $objDrawing->setPath($img);//貼り付ける画像のパスを指定
185
        $objDrawing->setCoordinates($cellInfo);//位置
186
        if (!is_null($proportial)) {
187
            $objDrawing->setResizeProportional($proportial);//縦横比の変更なし
188
        }
189
        if (!is_null($height)) {
190
            $objDrawing->setHeight($height);//画像の高さを指定
191
        }
192
        if (!is_null($width)) {
193
            $objDrawing->setWidth($width);//画像の高さを指定
194
        }
195
        if (!is_null($offsetx)) {
196
            $objDrawing->setOffsetX($offsetx);//指定した位置からどれだけ横方向にずらすか。
197
        }
198
        if (!is_null($offsety)) {
199
            $objDrawing->setOffsetY($offsety);//指定した位置からどれだけ縦方向にずらすか。
200
        }
201
        $objDrawing->setWorksheet($this->getSheet($sheetNo));
202
    }
203
204
    /**
205
    * cellMerge
206
    * セルのマージ
207
    * @param integer $col1 行
208
    * @param integer $row1 列
209
    * @param integer $col2 行
210
    * @param integer $row2 列
211
    * @param integer $sheetNo シート番号
212
    * @author hagiwara
213
    */
214
    public function cellMerge($col1, $row1, $col2, $row2, $sheetNo)
215
    {
216
        $cell1Info = $this->cellInfo($col1, $row1);
217
        $cell2Info = $this->cellInfo($col2, $row2);
218
219
        $this->getSheet($sheetNo)->mergeCells($cell1Info . ':' . $cell2Info);
220
    }
221
222
223
    /**
224
    * styleCopy
225
    * セルの書式コピー
226
    * @param integer $col 行
227
    * @param integer $row 列
228
    * @param integer $sheetNo シート番号
229
    * @param integer $refCol 参照セル行
230
    * @param integer $refRow 参照セル列
231
    * @param integer $refSheet 参照シート
232
    * @author hagiwara
233
    */
234
    public function styleCopy($col, $row, $sheetNo, $refCol, $refRow, $refSheet)
235
    {
236
        $cellInfo = $this->cellInfo($col, $row);
237
        $refCellInfo = $this->cellInfo($refCol, $refRow);
238
        $style = $this->getSheet($refSheet)->getStyle($refCellInfo);
239
240
        $this->getSheet($sheetNo)->duplicateStyle($style, $cellInfo);
241
    }
242
243
    /**
244
    * setStyle
245
    * 書式のセット(まとめて)
246
    * @param integer $col 行
247
    * @param integer $row 列
248
    * @param integer $sheetNo シート番号
249
    * @param array $style スタイル情報
250
    * @author hagiwara
251
    */
252
    public function setStyle($col, $row, $sheetNo, $style)
253
    {
254
        $default_style = [
255
            'font' => null,
256
            'underline' => null,
257
            'bold' => null,
258
            'italic' => null,
259
            'strikethrough' => null,
260
            'color' => null,
261
            'size' => null,
262
            'alignh' => null,
263
            'alignv' => null,
264
            'bgcolor' => null,
265
            'bgpattern' => null,
266
            'border' => null,
267
        ];
268
        $style = array_merge($default_style, $style);
269
        $this->setFontName($col, $row, $sheetNo, $style['font']);
270
        $this->setUnderline($col, $row, $sheetNo, $style['underline']);
271
        $this->setFontBold($col, $row, $sheetNo, $style['bold']);
272
        $this->setItalic($col, $row, $sheetNo, $style['italic']);
273
        $this->setStrikethrough($col, $row, $sheetNo, $style['strikethrough']);
274
        $this->setColor($col, $row, $sheetNo, $style['color']);
275
        $this->setSize($col, $row, $sheetNo, $style['size']);
276
        $this->setAlignHolizonal($col, $row, $sheetNo, $style['alignh']);
277
        $this->setAlignVertical($col, $row, $sheetNo, $style['alignv']);
278
        $this->setBackgroundColor($col, $row, $sheetNo, $style['bgcolor'], $style['bgpattern']);
279
        $this->setBorder($col, $row, $sheetNo, $style['border']);
280
    }
281
282
    /**
283
    * setFontName
284
    * フォントのセット
285
    * @param integer $col 行
286
    * @param integer $row 列
287
    * @param integer $sheetNo シート番号
288
    * @param string|null $fontName フォント名
289
    * @author hagiwara
290
    */
291
    public function setFontName($col, $row, $sheetNo, $fontName)
292
    {
293
        if (is_null($fontName)) {
294
            return;
295
        }
296
        $this->getFont($col, $row, $sheetNo)->setName($fontName);
297
    }
298
299
    /**
300
    * setUnderline
301
    * 下線のセット
302
    * @param integer $col 行
303
    * @param integer $row 列
304
    * @param integer $sheetNo シート番号
305
    * @param string|null $underline 下線の種類
306
    * @author hagiwara
307
    */
308
    public function setUnderline($col, $row, $sheetNo, $underline)
309
    {
310
        if (is_null($underline)) {
311
            return;
312
        }
313
        $this->getFont($col, $row, $sheetNo)->setUnderline($underline);
314
    }
315
316
317
    /**
318
    * getUnderlineType
319
    * 下線の種類の設定
320
    * @param string $type
321
    * @author hagiwara
322
    */
323
    private function getUnderlineType($type)
324
    {
325
        $type_list = self::$__underlineType;
326
        if (array_key_exists($type, $type_list)) {
327
            return $type_list[$type];
328
        }
329
        return Border::UNDERLINE_NONE;
330
    }
331
332
    /**
333
    * setFontBold
334
    * 太字のセット
335
    * @param integer $col 行
336
    * @param integer $row 列
337
    * @param integer $sheetNo シート番号
338
    * @param boolean|null $bold 太字を引くか
339
    * @author hagiwara
340
    */
341
    public function setFontBold($col, $row, $sheetNo, $bold)
342
    {
343
        if (is_null($bold)) {
344
            return;
345
        }
346
        $this->getFont($col, $row, $sheetNo)->setBold($bold);
347
    }
348
349
    /**
350
    * setItalic
351
    * イタリックのセット
352
    * @param integer $col 行
353
    * @param integer $row 列
354
    * @param integer $sheetNo シート番号
355
    * @param boolean|null $italic イタリックにするか
356
    * @author hagiwara
357
    */
358
    public function setItalic($col, $row, $sheetNo, $italic)
359
    {
360
        if (is_null($italic)) {
361
            return;
362
        }
363
        $this->getFont($col, $row, $sheetNo)->setItalic($italic);
364
    }
365
366
    /**
367
    * setStrikethrough
368
    * 打ち消し線のセット
369
    * @param integer $col 行
370
    * @param integer $row 列
371
    * @param integer $sheetNo シート番号
372
    * @param boolean|null $strikethrough 打ち消し線をつけるか
373
    * @author hagiwara
374
    */
375
    public function setStrikethrough($col, $row, $sheetNo, $strikethrough)
376
    {
377
        if (is_null($strikethrough)) {
378
            return;
379
        }
380
        var_dump($col);
0 ignored issues
show
Security Debugging Code introduced by
var_dump($col); looks like debug code. Are you sure you do not want to remove it? This might expose sensitive data.
Loading history...
381
        var_dump($row);
382
        var_dump($sheetNo);
383
        var_dump($strikethrough);
384
        $this->getFont($col, $row, $sheetNo)->setStrikethrough($strikethrough);
385
    }
386
387
    /**
388
    * setColor
389
    * 文字の色
390
    * @param integer $col 行
391
    * @param integer $row 列
392
    * @param integer $sheetNo シート番号
393
    * @param string|null $color 色(ARGB)
394
    * @author hagiwara
395
    */
396
    public function setColor($col, $row, $sheetNo, $color)
397
    {
398
        if (is_null($color)) {
399
            return;
400
        }
401
        $this->getFont($col, $row, $sheetNo)->getColor()->setARGB($color);
402
    }
403
404
    /**
405
    * setSize
406
    * 文字サイズ
407
    * @param integer $col 行
408
    * @param integer $row 列
409
    * @param integer $sheetNo シート番号
410
    * @param integer|null $size
411
    * @author hagiwara
412
    */
413
    public function setSize($col, $row, $sheetNo, $size)
414
    {
415
        if (is_null($size)) {
416
            return;
417
        }
418
        $this->getFont($col, $row, $sheetNo)->setSize($size);
419
    }
420
421
    /**
422
    * getFont
423
    * fontデータ取得
424
    * @param integer $col 行
425
    * @param integer $row 列
426
    * @param integer $sheetNo シート番号
427
    * @author hagiwara
428
    */
429
    private function getFont($col, $row, $sheetNo)
430
    {
431
        $cellInfo = $this->cellInfo($col, $row);
432
        return $this->getSheet($sheetNo)->getStyle($cellInfo)->getFont();
433
    }
434
435
    /**
436
    * setAlignHolizonal
437
    * 水平方向のalign
438
    * @param integer $col 行
439
    * @param integer $row 列
440
    * @param integer $sheetNo シート番号
441
    * @param string|null $type
442
    * typeはgetAlignHolizonalType参照
443
    * @author hagiwara
444
    */
445
    public function setAlignHolizonal($col, $row, $sheetNo, $type)
446
    {
447
        if (is_null($type)) {
448
            return;
449
        }
450
        $this->getAlignment($col, $row, $sheetNo)->setHorizontal($this->getAlignHolizonalType($type));
451
    }
452
453
    /**
454
    * setAlignVertical
455
    * 垂直方法のalign
456
    * @param integer $col 行
457
    * @param integer $row 列
458
    * @param integer $sheetNo シート番号
459
    * @param string|null $type
460
    * typeはgetAlignVerticalType参照
461
    * @author hagiwara
462
    */
463
    public function setAlignVertical($col, $row, $sheetNo, $type)
464
    {
465
        if (is_null($type)) {
466
            return;
467
        }
468
        $this->getAlignment($col, $row, $sheetNo)->setVertical($this->getAlignVerticalType($type));
469
    }
470
471
    /**
472
    * getAlignment
473
    * alignmentデータ取得
474
    * @param integer $col 行
475
    * @param integer $row 列
476
    * @param integer $sheetNo シート番号
477
    * @author hagiwara
478
    */
479
    private function getAlignment($col, $row, $sheetNo)
480
    {
481
        $cellInfo = $this->cellInfo($col, $row);
482
        return $this->getSheet($sheetNo)->getStyle($cellInfo)->getAlignment();
483
    }
484
485
    /**
486
    * setBorder
487
    * 罫線の設定
488
    * @param integer $col 行
489
    * @param integer $row 列
490
    * @param integer $sheetNo シート番号
491
    * @param array|null $border
492
    * borderの内部はgetBorderType参照
493
    * @author hagiwara
494
    */
495
    public function setBorder($col, $row, $sheetNo, $border)
496
    {
497
        if (is_null($border)) {
498
            return;
499
        }
500
        $cellInfo = $this->cellInfo($col, $row);
501
        $default_border = [
502
            'left' => null,
503
            'right' => null,
504
            'top' => null,
505
            'bottom' => null,
506
            'diagonal' => null,
507
            'all_borders' => null,
508
            'outline' => null,
509
            'inside' => null,
510
            'vertical' => null,
511
            'horizontal' => null,
512
        ];
513
        $border = array_merge($default_border, $border);
514
        foreach ($border as $border_position => $border_setting) {
515
            if (!is_null($border_setting)) {
516
                $borderInfo =  $this->getSheet($sheetNo)->getStyle($cellInfo)->getBorders()->{'get' . $this->camelize($border_position)}();
517
                if (array_key_exists('type', $border_setting)) {
518
                    $borderInfo->setBorderStyle($this->getBorderType($border_setting['type']));
519
                }
520
                if (array_key_exists('color', $border_setting)) {
521
                    $borderInfo->getColor()->setARGB($border_setting['color']);
522
                }
523
            }
524
        }
525
    }
526
527
    /**
528
    * setBackgroundColor
529
    * 背景色の設定
530
    * @param integer $col 行
531
    * @param integer $row 列
532
    * @param integer $sheetNo シート番号
533
    * @param string $color 色
534
    * @param string $fillType 塗りつぶし方(デフォルトsolid)
535
    * fillTypeの内部はgetFillType参照
536
    * @author hagiwara
537
    */
538
    public function setBackgroundColor($col, $row, $sheetNo, $color, $fillType = 'solid')
539
    {
540
        $cellInfo = $this->cellInfo($col, $row);
541
542
        $this->getSheet($sheetNo)->getStyle($cellInfo)->getFill()->setFillType($this->getFillType($fillType))->getStartColor()->setARGB($color);
543
    }
544
545
    /**
546
    * getBorderType
547
    * 罫線の種類の設定
548
    * @param string $type
549
    * @author hagiwara
550
    */
551
    private function getBorderType($type)
552
    {
553
        $type_list = self::$__borderType;
554
        if (array_key_exists($type, $type_list)) {
555
            return $type_list[$type];
556
        }
557
        return Border::BORDER_NONE;
558
    }
559
560
    /**
561
    * getAlignHolizonalType
562
    * 水平方向のAlignの設定
563
    * @param string $type
564
    * @author hagiwara
565
    */
566
    private function getAlignHolizonalType($type)
567
    {
568
        $type_list = self::$__alignHolizonalType;
569
        if (array_key_exists($type, $type_list)) {
570
            return $type_list[$type];
571
        }
572
        return Alignment::HORIZONTAL_GENERAL;
573
    }
574
575
    /**
576
    * getAlignVerticalType
577
    * 垂直方向のAlignの設定
578
    * @param string $type
579
    * @author hagiwara
580
    */
581
    private function getAlignVerticalType($type)
582
    {
583
        $type_list = self::$__alignVerticalType;
584
        if (array_key_exists($type, $type_list)) {
585
            return $type_list[$type];
586
        }
587
        return null;
588
    }
589
590
    /**
591
    * getFillType
592
    * 塗りつぶしの設定
593
    * @param string $type
594
    * @author hagiwara
595
    */
596
    private function getFillType($type)
597
    {
598
        $type_list = self::$__fillType;
599
        if (array_key_exists($type, $type_list)) {
600
            return $type_list[$type];
601
        }
602
        return Fill::FILL_SOLID;
603
    }
604
605
    /**
606
    * createSheet
607
    * シートの作成
608
    * @param string $name
609
    * @author hagiwara
610
    */
611
    public function createSheet($name = null)
612
    {
613
        //シートの新規作成
614
        $newSheet = $this->__phpexcel->createSheet();
615
        $sheetNo = $this->__phpexcel->getIndex($newSheet);
616
        $this->__sheet[$sheetNo] = $newSheet;
617
        if (!is_null($name)) {
618
            $this->renameSheet($sheetNo, $name);
619
        }
620
    }
621
622
    /**
623
    * deleteSheet
624
    * シートの削除
625
    * @param integer $sheetNo
626
    * @author hagiwara
627
    */
628
    public function deleteSheet($sheetNo)
629
    {
630
        //シートの削除は一番最後に行う
631
        $this->__deleteSheetList[] = $sheetNo;
632
    }
633
634
    /**
635
    * copySheet
636
    * シートのコピー
637
    * @param integer $sheetNo
638
    * @param integer $position
639
    * @param string $name
640
    * @author hagiwara
641
    */
642
    public function copySheet($sheetNo, $position = null, $name = null)
643
    {
644
        $base = $this->getSheet($sheetNo)->copy();
645
        if ($name === null) {
646
            $name = uniqid();
647
        }
648
        $base->setTitle($name);
649
650
        // $positionが null(省略時含む)の場合は最後尾に追加される
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
651
        $this->__phpexcel->addSheet($base, $position);
652
    }
653
654
    /**
655
    * renameSheet
656
    * シート名の変更
657
    * @param integer $sheetNo
658
    * @param string $name
659
    * @author hagiwara
660
    */
661
    public function renameSheet($sheetNo, $name)
662
    {
663
        $this->getSheet($sheetNo)->setTitle($name);
664
    }
665
666
    /**
667
    * write
668
    * xlsxファイルの書き込み
669
    * @param string $file 書き込み先のファイルパス
670
    * @author hagiwara
671
    */
672
    public function write($file, $type = 'Xlsx')
673
    {
674
        //書き込み前に削除シートを削除する
675
        foreach ($this->__deleteSheetList as $deleteSheet) {
676
            $this->__phpexcel->removeSheetByIndex($deleteSheet);
677
        }
678
        $writer = IOFactory::createWriter($this->__phpexcel, $type);
679
        $writer->save($file);
680
    }
681
682
    /**
683
    * getReader
684
    * readerを返す(※直接Spreadsheetの関数を実行できるように)
685
    * @author hagiwara
686
    */
687
    public function getReader()
688
    {
689
        return $this->__phpexcel;
690
    }
691
692
    /**
693
    * getSheet
694
    * シート情報の読み込み
695
    * @param integer $sheetNo シート番号
696
    * @author hagiwara
697
    * @return null|\Spreadsheet_Worksheet
698
    */
699
    private function getSheet($sheetNo)
700
    {
701
        if (!array_key_exists($sheetNo, $this->__sheet)) {
702
            $this->__sheet[$sheetNo] = $this->__phpexcel->setActiveSheetIndex($sheetNo);
703
        }
704
        return $this->__sheet[$sheetNo];
705
    }
706
707
    /**
708
    * cellInfo
709
    * R1C1参照をA1参照に変換して返す
710
    * @param integer $col 行
711
    * @param integer $row 列
712
    * @author hagiwara
713
    */
714
    private function cellInfo($col, $row)
715
    {
716
        $stringCol = Coordinate::stringFromColumnIndex($col);
717
        return $stringCol . $row;
718
    }
719
720
    /**
721
    * cellInfo
722
    * http://qiita.com/Hiraku/items/036080976884fad1e450
723
    * @param string $str
724
    */
725
    private function camelize($str)
726
    {
727
        $str = ucwords($str, '_');
728
        return str_replace('_', '', $str);
729
    }
730
}
731