Framework  3.9
ExcelFile Class Reference

Generate a binary format Microsoft Excel file for download. More...

+ Inheritance diagram for ExcelFile:
+ Collaboration diagram for ExcelFile:

Public Member Functions

 ExcelFile ($filename)
 Create a new ExcelFile object. More...
 
 _xlsBOF ()
 
 _xlsEOF ()
 
 writeNumber ($row, $col, $value)
 Write a number to the cell at the specified row and column. More...
 
 writeText ($row, $col, $value, $wrap=false)
 Write text to the cell at the specified row and column. More...
 
 writeHeading ($row, $col, $value)
 Write text with column heading styles. More...
 
 writeSubheading ($row, $col, $value)
 Write text with column sub-heading styles. More...
 
 writeFooter ($row, $col, $value)
 Write text with column footer styles. More...
 
 writeFooterNumber ($row, $col, $value)
 Write number with column footer styles. More...
 
 writePercentage ($row, $col, $value)
 Write a number to the cell at the specified row and column and format as a percentage. More...
 
 writeCurrency ($row, $col, $value)
 Write a number to the cell at the specified row and column with currency formatting. More...
 
 setWorksheetTitle ($title)
 Set the title of the currently active worksheet. More...
 
 addWorksheet ($title)
 Adds a new worksheet to the Excel file. More...
 
 abort ($error)
 Abort processing, output the specified error string. More...
 
 close ()
 Prevent further output to the spreadsheet. More...
 
 send ()
 Transmit the spreadsheet to the client. More...
 

Public Attributes

 $filename
 
 $open
 
 $content
 

Detailed Description

Generate a binary format Microsoft Excel file for download.

The default ExcelFile writer is an extremely limited implementation that outputs BIFF8 format (Excel 97/2000). It is designed to be compact and provide Excel output without incurring any external dependencies.

Author
andy

Definition at line 173 of file excel.inc.

Member Function Documentation

◆ _xlsBOF()

ExcelFile::_xlsBOF ( )

Definition at line 192 of file excel.inc.

193  {
194  echo pack("ssssss", 0x809, 0x8, 0x0, 0x10, 0x0, 0x0);
195  }

◆ _xlsEOF()

ExcelFile::_xlsEOF ( )

Definition at line 197 of file excel.inc.

198  {
199  echo pack("ss", 0x0A, 0x00);
200  }

◆ abort()

ExcelFile::abort (   $error)

Abort processing, output the specified error string.

Parameters
string$error

Implements IExcelFile.

Definition at line 268 of file excel.inc.

269  {
270  ob_end_clean();
271  ajaxReturn($error);
272  }
ajaxReturn($msg=null)
Returns a string output and exits the script cleanly.
Definition: functions.inc:1783

◆ addWorksheet()

ExcelFile::addWorksheet (   $title)

Adds a new worksheet to the Excel file.

Parameters
string$titlethe title of the new worksheet

Implements IExcelFile.

Definition at line 263 of file excel.inc.

264  {
265  throw new Exception("Multiple worksheets are not supported with the built-in Excel writer. Install PHPExcel.");
266  }

◆ close()

ExcelFile::close ( )

Prevent further output to the spreadsheet.

Implements IExcelFile.

Definition at line 274 of file excel.inc.

275  {
276  $this->_xlsEOF();
277  $this->content = ob_get_contents();
278  ob_end_clean();
279  $this->open = false;
280  }
_xlsEOF()
Definition: excel.inc:197

◆ ExcelFile()

ExcelFile::ExcelFile (   $filename)

Create a new ExcelFile object.

Parameters
string$filenamethe name of the file to generate

Definition at line 183 of file excel.inc.

184  {
185  $this->filename = $filename;
186  ob_start();
187  $this->open = true;
188  $this->_xlsBOF();
189  }
_xlsBOF()
Definition: excel.inc:192

◆ send()

ExcelFile::send ( )

Transmit the spreadsheet to the client.

Implements IExcelFile.

Definition at line 282 of file excel.inc.

283  {
284  if ($this->open)
285  {
286  $this->close();
287  }
288 
289  session_cache_limiter("private_no_expire, must-revalidate");
290  header("Content-Type: application/vnd.msexcel");
291  header("Content-Disposition: attachment;filename=$this->filename");
292  header("Pragma: private");
293  header("Content-Transfer-Encoding: binary");
294  header("Content-Length: ".strlen($this->content));
295 
296  echo $this->content;
297  }
close()
Prevent further output to the spreadsheet.
Definition: excel.inc:274

◆ setWorksheetTitle()

ExcelFile::setWorksheetTitle (   $title)

Set the title of the currently active worksheet.

Parameters
string$titlethe title text.

Implements IExcelFile.

Definition at line 258 of file excel.inc.

259  {
260  throw new Exception("Multiple worksheets are not supported with the built-in Excel writer. Install PHPExcel.");
261  }

◆ writeCurrency()

ExcelFile::writeCurrency (   $row,
  $col,
  $value 
)

Write a number to the cell at the specified row and column with currency formatting.

Parameters
integer$row
integer$col
number$value

Implements IExcelFile.

Definition at line 253 of file excel.inc.

254  {
255  $this->writeNumber($row, $col, $value);
256  }
writeNumber($row, $col, $value)
Write a number to the cell at the specified row and column.
Definition: excel.inc:208

◆ writeFooter()

ExcelFile::writeFooter (   $row,
  $col,
  $value 
)

Write text with column footer styles.

Parameters
integer$row
integer$col
string$value

Implements IExcelFile.

Definition at line 238 of file excel.inc.

239  {
240  return $this->writeText($row, $col, $value);
241  }
writeText($row, $col, $value, $wrap=false)
Write text to the cell at the specified row and column.
Definition: excel.inc:221

◆ writeFooterNumber()

ExcelFile::writeFooterNumber (   $row,
  $col,
  $value 
)

Write number with column footer styles.

Parameters
integer$row
integer$col
string$value

Implements IExcelFile.

Definition at line 243 of file excel.inc.

244  {
245  return $this->writeNumber($row, $col, $value);
246  }

◆ writeHeading()

ExcelFile::writeHeading (   $row,
  $col,
  $value 
)

Write text with column heading styles.

Parameters
integer$row
integer$col
string$value

Implements IExcelFile.

Definition at line 228 of file excel.inc.

229  {
230  return $this->writeText($row, $col, $value);
231  }

◆ writeNumber()

ExcelFile::writeNumber (   $row,
  $col,
  $value 
)

Write a number to the cell at the specified row and column.

Parameters
integer$row
integer$col
number$value

Implements IExcelFile.

Definition at line 208 of file excel.inc.

209  {
210  echo pack("sssss", 0x203, 14, $row, $col, 0x0);
211  echo pack("d", $value);
212  }

◆ writePercentage()

ExcelFile::writePercentage (   $row,
  $col,
  $value 
)

Write a number to the cell at the specified row and column and format as a percentage.

Parameters
integer$row
integer$col
number$value

Implements IExcelFile.

Definition at line 248 of file excel.inc.

249  {
250  $this->writeText($row, $col, $value);
251  }

◆ writeSubheading()

ExcelFile::writeSubheading (   $row,
  $col,
  $value 
)

Write text with column sub-heading styles.

Parameters
integer$row
integer$col
string$value

Implements IExcelFile.

Definition at line 233 of file excel.inc.

234  {
235  return $this->writeText($row, $col, $value);
236  }

◆ writeText()

ExcelFile::writeText (   $row,
  $col,
  $value,
  $wrap = false 
)

Write text to the cell at the specified row and column.

Parameters
integer$rowthe cell row number
integer$colthe cell column number
string$valuethe string to insert
boolean$wrapwhether to allow text wrapping

Implements IExcelFile.

Definition at line 221 of file excel.inc.

222  {
223  $len = strlen($value);
224  echo pack("ssssss", 0x204, 8 + $len, $row, $col, 0x0, $len);
225  echo $value;
226  }

Member Data Documentation

◆ $content

ExcelFile::$content

Definition at line 177 of file excel.inc.

◆ $filename

ExcelFile::$filename

Definition at line 175 of file excel.inc.

◆ $open

ExcelFile::$open

Definition at line 176 of file excel.inc.


The documentation for this class was generated from the following file: