224
224
*/
225
225
class Excel extends \yii \base \Widget
226
226
{
227
+ // Border style
228
+ const BORDER_NONE = 'none ' ;
229
+ const BORDER_DASHDOT = 'dashDot ' ;
230
+ const BORDER_DASHDOTDOT = 'dashDotDot ' ;
231
+ const BORDER_DASHED = 'dashed ' ;
232
+ const BORDER_DOTTED = 'dotted ' ;
233
+ const BORDER_DOUBLE = 'double ' ;
234
+ const BORDER_HAIR = 'hair ' ;
235
+ const BORDER_MEDIUM = 'medium ' ;
236
+ const BORDER_MEDIUMDASHDOT = 'mediumDashDot ' ;
237
+ const BORDER_MEDIUMDASHDOTDOT = 'mediumDashDotDot ' ;
238
+ const BORDER_MEDIUMDASHED = 'mediumDashed ' ;
239
+ const BORDER_SLANTDASHDOT = 'slantDashDot ' ;
240
+ const BORDER_THICK = 'thick ' ;
241
+ const BORDER_THIN = 'thin ' ;
242
+
243
+ // Colors
244
+ const COLOR_BLACK = 'FF000000 ' ;
245
+ const COLOR_WHITE = 'FFFFFFFF ' ;
246
+ const COLOR_RED = 'FFFF0000 ' ;
247
+ const COLOR_DARKRED = 'FF800000 ' ;
248
+ const COLOR_BLUE = 'FF0000FF ' ;
249
+ const COLOR_DARKBLUE = 'FF000080 ' ;
250
+ const COLOR_GREEN = 'FF00FF00 ' ;
251
+ const COLOR_DARKGREEN = 'FF008000 ' ;
252
+ const COLOR_YELLOW = 'FFFFFF00 ' ;
253
+ const COLOR_DARKYELLOW = 'FF808000 ' ;
254
+
255
+ // Horizontal alignment styles
256
+ const HORIZONTAL_GENERAL = 'general ' ;
257
+ const HORIZONTAL_LEFT = 'left ' ;
258
+ const HORIZONTAL_RIGHT = 'right ' ;
259
+ const HORIZONTAL_CENTER = 'center ' ;
260
+ const HORIZONTAL_CENTER_CONTINUOUS = 'centerContinuous ' ;
261
+ const HORIZONTAL_JUSTIFY = 'justify ' ;
262
+ const HORIZONTAL_FILL = 'fill ' ;
263
+ const HORIZONTAL_DISTRIBUTED = 'distributed ' ; // Excel2007 only
264
+
265
+ // Vertical alignment styles
266
+ const VERTICAL_BOTTOM = 'bottom ' ;
267
+ const VERTICAL_TOP = 'top ' ;
268
+ const VERTICAL_CENTER = 'center ' ;
269
+ const VERTICAL_JUSTIFY = 'justify ' ;
270
+ const VERTICAL_DISTRIBUTED = 'distributed ' ; // Excel2007 only
271
+
272
+ // Read order
273
+ const READORDER_CONTEXT = 0 ;
274
+ const READORDER_LTR = 1 ;
275
+ const READORDER_RTL = 2 ;
276
+
277
+ // Fill types
278
+ const FILL_NONE = 'none ' ;
279
+ const FILL_SOLID = 'solid ' ;
280
+ const FILL_GRADIENT_LINEAR = 'linear ' ;
281
+ const FILL_GRADIENT_PATH = 'path ' ;
282
+ const FILL_PATTERN_DARKDOWN = 'darkDown ' ;
283
+ const FILL_PATTERN_DARKGRAY = 'darkGray ' ;
284
+ const FILL_PATTERN_DARKGRID = 'darkGrid ' ;
285
+ const FILL_PATTERN_DARKHORIZONTAL = 'darkHorizontal ' ;
286
+ const FILL_PATTERN_DARKTRELLIS = 'darkTrellis ' ;
287
+ const FILL_PATTERN_DARKUP = 'darkUp ' ;
288
+ const FILL_PATTERN_DARKVERTICAL = 'darkVertical ' ;
289
+ const FILL_PATTERN_GRAY0625 = 'gray0625 ' ;
290
+ const FILL_PATTERN_GRAY125 = 'gray125 ' ;
291
+ const FILL_PATTERN_LIGHTDOWN = 'lightDown ' ;
292
+ const FILL_PATTERN_LIGHTGRAY = 'lightGray ' ;
293
+ const FILL_PATTERN_LIGHTGRID = 'lightGrid ' ;
294
+ const FILL_PATTERN_LIGHTHORIZONTAL = 'lightHorizontal ' ;
295
+ const FILL_PATTERN_LIGHTTRELLIS = 'lightTrellis ' ;
296
+ const FILL_PATTERN_LIGHTUP = 'lightUp ' ;
297
+ const FILL_PATTERN_LIGHTVERTICAL = 'lightVertical ' ;
298
+ const FILL_PATTERN_MEDIUMGRAY = 'mediumGray ' ;
299
+
300
+ // Pre-defined formats
301
+ const FORMAT_GENERAL = 'General ' ;
302
+
303
+ const FORMAT_TEXT = '@ ' ;
304
+
305
+ const FORMAT_NUMBER = '0 ' ;
306
+ const FORMAT_NUMBER_00 = '0.00 ' ;
307
+ const FORMAT_NUMBER_COMMA_SEPARATED1 = '#,##0.00 ' ;
308
+ const FORMAT_NUMBER_COMMA_SEPARATED2 = '#,##0.00_- ' ;
309
+
310
+ const FORMAT_PERCENTAGE = '0% ' ;
311
+ const FORMAT_PERCENTAGE_00 = '0.00% ' ;
312
+
313
+ const FORMAT_DATE_YYYYMMDD2 = 'yyyy-mm-dd ' ;
314
+ const FORMAT_DATE_YYYYMMDD = 'yy-mm-dd ' ;
315
+ const FORMAT_DATE_DDMMYYYY = 'dd/mm/yy ' ;
316
+ const FORMAT_DATE_DMYSLASH = 'd/m/yy ' ;
317
+ const FORMAT_DATE_DMYMINUS = 'd-m-yy ' ;
318
+ const FORMAT_DATE_DMMINUS = 'd-m ' ;
319
+ const FORMAT_DATE_MYMINUS = 'm-yy ' ;
320
+ const FORMAT_DATE_XLSX14 = 'mm-dd-yy ' ;
321
+ const FORMAT_DATE_XLSX15 = 'd-mmm-yy ' ;
322
+ const FORMAT_DATE_XLSX16 = 'd-mmm ' ;
323
+ const FORMAT_DATE_XLSX17 = 'mmm-yy ' ;
324
+ const FORMAT_DATE_XLSX22 = 'm/d/yy h:mm ' ;
325
+ const FORMAT_DATE_DATETIME = 'd/m/yy h:mm ' ;
326
+ const FORMAT_DATE_TIME1 = 'h:mm AM/PM ' ;
327
+ const FORMAT_DATE_TIME2 = 'h:mm:ss AM/PM ' ;
328
+ const FORMAT_DATE_TIME3 = 'h:mm ' ;
329
+ const FORMAT_DATE_TIME4 = 'h:mm:ss ' ;
330
+ const FORMAT_DATE_TIME5 = 'mm:ss ' ;
331
+ const FORMAT_DATE_TIME6 = 'h:mm:ss ' ;
332
+ const FORMAT_DATE_TIME7 = 'i:s.S ' ;
333
+ const FORMAT_DATE_TIME8 = 'h:mm:ss;@ ' ;
334
+ const FORMAT_DATE_YYYYMMDDSLASH = 'yy/mm/dd;@ ' ;
335
+
336
+ const FORMAT_CURRENCY_USD_SIMPLE = '"$"#,##0.00_- ' ;
337
+ const FORMAT_CURRENCY_USD = '$#,##0_- ' ;
338
+ const FORMAT_CURRENCY_EUR_SIMPLE = '#,##0.00_-"€" ' ;
339
+ const FORMAT_CURRENCY_EUR = '#,##0_-"€" ' ;
340
+
227
341
/**
228
342
* @var string mode is an export mode or import mode. valid value are 'export' and 'import'.
229
343
*/
@@ -269,7 +383,7 @@ class Excel extends \yii\base\Widget
269
383
/**
270
384
* @var boolean to set the file excel to download mode.
271
385
*/
272
- public $ asAttachment = true ;
386
+ public $ asAttachment = false ;
273
387
/**
274
388
* @var boolean to set the first record on excel file to a keys of array per line.
275
389
* If you want to set the keys of record column with first record, if it not set, the header with use the alphabet column on excel.
@@ -305,6 +419,14 @@ class Excel extends \yii\base\Widget
305
419
* @var boolean define the column autosize
306
420
*/
307
421
public $ autoSize = false ;
422
+ /**
423
+ * @var boolean if true, this writer pre-calculates all formulas in the spreadsheet. This can be slow on large spreadsheets, and maybe even unwanted.
424
+ */
425
+ public $ preCalculationFormula = false ;
426
+ /**
427
+ * @var boolean Because of a bug in the Office2003 compatibility pack, there can be some small issues when opening Xlsx spreadsheets (mostly related to formula calculation)
428
+ */
429
+ public $ compatibilityOffice2003 = false ;
308
430
309
431
/**
310
432
* (non-PHPdoc)
@@ -361,6 +483,8 @@ public function executeColumns(&$activeSheet = null, $models, $columns = [], $he
361
483
$ header = $ headers [$ column ['attribute ' ]];
362
484
} elseif (isset ($ column ['attribute ' ])) {
363
485
$ header = $ model ->getAttributeLabel ($ column ['attribute ' ]);
486
+ } elseif (isset ($ column ['cellFormat ' ]) && is_array ($ column ['cellFormat ' ])) {
487
+ $ activeSheet ->getStyle ($ col .$ row )->applyFromArray ($ column ['cellFormat ' ]);
364
488
}
365
489
} else {
366
490
$ header = $ model ->getAttributeLabel ($ column );
@@ -386,7 +510,10 @@ public function executeColumns(&$activeSheet = null, $models, $columns = [], $he
386
510
}
387
511
$ col .= chr (64 +$ colnum );
388
512
if (is_array ($ column )) {
389
- $ column_value = $ this ->executeGetColumnData ($ model , $ column );
513
+ $ column_value = $ this ->executeGetColumnData ($ model , $ column );
514
+ if (isset ($ column ['cellFormat ' ]) && is_array ($ column ['cellFormat ' ])) {
515
+ $ activeSheet ->getStyle ($ col .$ row )->applyFromArray ($ column ['cellFormat ' ]);
516
+ }
390
517
} else {
391
518
$ column_value = $ this ->executeGetColumnData ($ model , ['attribute ' => $ column ]);
392
519
}
@@ -580,8 +707,11 @@ public function writeFile($sheet)
580
707
if (isset ($ this ->savePath ) && $ this ->savePath != null ) {
581
708
$ path = $ this ->savePath . '/ ' . $ this ->getFileName ();
582
709
}
710
+ $ objectwriter ->setOffice2003Compatibility ($ this ->compatibilityOffice2003 );
711
+ $ objectwriter ->setPreCalculateFormulas ($ this ->preCalculationFormula );
583
712
$ objectwriter ->save ($ path );
584
- exit ();
713
+ if ($ path == 'php://output ' )
714
+ exit ();
585
715
}
586
716
587
717
/**
0 commit comments