Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.

Differences Between: [Versions 310 and 311] [Versions 311 and 402] [Versions 311 and 403] [Versions 39 and 311]

Excel writer abstraction layer.

Copyright: (C) 2001-3001 Eloy Lafuente (stronk7) {@link http://contiento.com}
License: http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
File Size: 896 lines (31 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 3 classes

MoodleExcelWorkbook:: (5 methods):
  __construct()
  add_worksheet()
  add_format()
  close()
  send()

MoodleExcelWorksheet:: (17 methods):
  __construct()
  write_string()
  write_number()
  write_url()
  write_date()
  write_formula()
  write_blank()
  write()
  set_row()
  set_column()
  hide_gridlines()
  hide_screen_gridlines()
  insert_bitmap()
  merge_cells()
  apply_format()
  apply_column_format()
  apply_row_format()

MoodleExcelFormat:: (25 methods):
  __construct()
  get_format_array()
  set_size()
  set_bold()
  set_underline()
  set_italic()
  set_strikeout()
  set_outline()
  set_shadow()
  set_script()
  set_color()
  parse_color()
  set_fg_color()
  set_bg_color()
  set_pattern()
  set_text_wrap()
  set_align()
  set_h_align()
  set_v_align()
  set_top()
  set_bottom()
  set_left()
  set_right()
  set_border()
  set_num_format()


Class: MoodleExcelWorkbook  - X-Ref

Define and operate over one Moodle Workbook.

This class acts as a wrapper around another library
maintaining Moodle functions isolated from underlying code.

__construct($filename, $type = 'Xlsx')   X-Ref
Constructs one Moodle Workbook.

param: string $filename The name of the file
param: string $type file format type used to be 'Xls or Xlsx' but now only 'Xlsx'

add_worksheet($name = '')   X-Ref
Create one Moodle Worksheet

param: string $name Name of the sheet
return: MoodleExcelWorksheet

add_format($properties = array()   X-Ref
Create one cell Format.

param: array $properties array of properties [name]=value;
return: MoodleExcelFormat

close()   X-Ref
Close the Moodle Workbook


send($filename)   X-Ref
Not required to use.

param: string $filename Name of the downloaded file

Class: MoodleExcelWorksheet  - X-Ref

Define and operate over one Worksheet.

This class acts as a wrapper around another library
maintaining Moodle functions isolated from underlying code.

__construct($name, Spreadsheet $workbook)   X-Ref
Constructs one Moodle Worksheet.

param: string $name The name of the file
param: Spreadsheet $workbook The internal Workbook object we are creating.

write_string($row, $col, $str, $format = null)   X-Ref
Write one string somewhere in the worksheet.

param: integer $row    Zero indexed row
param: integer $col    Zero indexed column
param: string  $str    The string to write
param: mixed   $format The XF format for the cell

write_number($row, $col, $num, $format = null)   X-Ref
Write one number somewhere in the worksheet.

param: integer $row    Zero indexed row
param: integer $col    Zero indexed column
param: float   $num    The number to write
param: mixed   $format The XF format for the cell

write_url($row, $col, $url, $format = null)   X-Ref
Write one url somewhere in the worksheet.

param: integer $row    Zero indexed row
param: integer $col    Zero indexed column
param: string  $url    The url to write
param: mixed   $format The XF format for the cell

write_date($row, $col, $date, $format = null)   X-Ref
Write one date somewhere in the worksheet.

param: integer $row    Zero indexed row
param: integer $col    Zero indexed column
param: int     $date   The date to write in UNIX timestamp format
param: mixed   $format The XF format for the cell

write_formula($row, $col, $formula, $format = null)   X-Ref
Write one formula somewhere in the worksheet.

param: integer $row    Zero indexed row
param: integer $col    Zero indexed column
param: string  $formula The formula to write
param: mixed   $format The XF format for the cell

write_blank($row, $col, $format = null)   X-Ref
Write one blank somewhere in the worksheet.

param: integer $row    Zero indexed row
param: integer $col    Zero indexed column
param: mixed   $format The XF format for the cell

write($row, $col, $token, $format = null)   X-Ref
Write anything somewhere in the worksheet,
type will be automatically detected.

param: integer $row    Zero indexed row
param: integer $col    Zero indexed column
param: mixed   $token  What we are writing
param: mixed   $format The XF format for the cell

set_row($row, $height, $format = null, $hidden = false, $level = 0)   X-Ref
Sets the height (and other settings) of one row.

param: integer $row    The row to set
param: integer $height Height we are giving to the row (null to set just format without setting the height)
param: mixed   $format The optional format we are giving to the row
param: bool    $hidden The optional hidden attribute
param: integer $level  The optional outline level (0-7)

set_column($firstcol, $lastcol, $width, $format = null, $hidden = false, $level = 0)   X-Ref
Sets the width (and other settings) of one column.

param: integer $firstcol first column on the range
param: integer $lastcol  last column on the range
param: integer $width    width to set  (null to set just format without setting the width)
param: mixed   $format   The optional format to apply to the columns
param: bool    $hidden   The optional hidden attribute
param: integer $level    The optional outline level (0-7)

hide_gridlines()   X-Ref
Set the option to hide grid lines on the printed page.


hide_screen_gridlines()   X-Ref
Set the option to hide gridlines on the worksheet (as seen on the screen).


insert_bitmap($row, $col, $bitmap, $x = 0, $y = 0, $scalex = 1, $scaley = 1)   X-Ref
Insert an image in a worksheet.

param: integer $row     The row we are going to insert the bitmap into
param: integer $col     The column we are going to insert the bitmap into
param: string  $bitmap  The bitmap filename
param: integer $x       The horizontal position (offset) of the image inside the cell.
param: integer $y       The vertical position (offset) of the image inside the cell.
param: integer $scalex The horizontal scale
param: integer $scaley The vertical scale

merge_cells($firstrow, $firstcol, $lastrow, $lastcol)   X-Ref
Merges the area given by its arguments.

param: integer $firstrow First row of the area to merge
param: integer $firstcol First column of the area to merge
param: integer $lastrow  Last row of the area to merge
param: integer $lastcol  Last column of the area to merge

apply_format($row, $col, $format = null)   X-Ref
No description

apply_column_format($col, $format = null)   X-Ref
No description

apply_row_format($row, $format = null)   X-Ref
No description

Class: MoodleExcelFormat  - X-Ref

Define and operate over one Format.

A big part of this class acts as a wrapper over other libraries
maintaining Moodle functions isolated from underlying code.

__construct($properties = array()   X-Ref
Constructs one Moodle Format.

param: array $properties

get_format_array()   X-Ref
Returns standardised Excel format array.

return: array

set_size($size)   X-Ref
Set the size of the text in the format (in pixels).
By default all texts in generated sheets are 10pt.

param: integer $size Size of the text (in points)

set_bold($weight = 1)   X-Ref
Set weight of the format.

param: integer $weight Weight for the text, 0 maps to 400 (normal text),

set_underline($underline)   X-Ref
Set underline of the format.

param: integer $underline The value for underline. Possible values are:

set_italic()   X-Ref
Set italic of the format.


set_strikeout()   X-Ref
Set strikeout of the format.


set_outline()   X-Ref
Set outlining of the format.


set_shadow()   X-Ref
Set shadow of the format.


set_script($script)   X-Ref
Set the script of the text.

param: integer $script The value for script type. Possible values are:

set_color($color)   X-Ref
Set color of the format. Used to specify the color of the text to be formatted.

param: mixed $color either a string (like 'blue'), or an integer (range is [8...63])

parse_color($color)   X-Ref
Standardise colour name.

param: mixed $color name of the color (i.e.: 'blue', 'red', etc..), or an integer (range is [8...63]).
return: string the RGB color value

set_fg_color($color)   X-Ref
Not used.

param: mixed $color

set_bg_color($color)   X-Ref
Set background color of the cell.

param: mixed $color either a string (like 'blue'), or an integer (range is [8...63])

set_pattern($pattern=1)   X-Ref
Set the cell fill pattern.

param: integer

set_text_wrap()   X-Ref
Set text wrap of the format.


set_align($location)   X-Ref
Set the cell alignment of the format.

param: string $location alignment for the cell ('left', 'right', 'justify', etc...)

set_h_align($location)   X-Ref
Set the cell horizontal alignment of the format.

param: string $location alignment for the cell ('left', 'right', 'justify', etc...)

set_v_align($location)   X-Ref
Set the cell vertical alignment of the format.

param: string $location alignment for the cell ('top', 'bottom', 'center', 'justify')

set_top($style)   X-Ref
Set the top border of the format.

param: integer $style style for the cell. 1 => thin, 2 => thick

set_bottom($style)   X-Ref
Set the bottom border of the format.

param: integer $style style for the cell. 1 => thin, 2 => thick

set_left($style)   X-Ref
Set the left border of the format.

param: integer $style style for the cell. 1 => thin, 2 => thick

set_right($style)   X-Ref
Set the right border of the format.

param: integer $style style for the cell. 1 => thin, 2 => thick

set_border($style)   X-Ref
Set cells borders to the same style.

param: integer $style style to apply for all cell borders. 1 => thin, 2 => thick.

set_num_format($numformat)   X-Ref
Set the numerical format of the format.
It can be date, time, currency, etc...

param: mixed $numformat The numeric format