Skip to content

Instantly share code, notes, and snippets.

@bablukpik
Forked from r-sal/PHPExcel_Basics.md
Created January 23, 2017 07:16
Show Gist options
  • Select an option

  • Save bablukpik/07439a866b0927b7b96bd6625b2aa80d to your computer and use it in GitHub Desktop.

Select an option

Save bablukpik/07439a866b0927b7b96bd6625b2aa80d to your computer and use it in GitHub Desktop.
PHPExcel Notes and code snippets

Basics

Creating a new PHPExcel Object.

$this->PHPExcel = new PHPExcel();

Sheets

Creating a new sheet: $this->activeSheet = $this->PHPExcel->createSheet(); Setting the title: $this->activeSheet->setTitle($title);

Getting/setting the active worksheet.

$this->activeSheet = $this->PHPExcel->getActiveSheet();

$sheetIndex = 2;
$this->PHPExcel->setActiveSheetIndex($sheetIndex)

Row/Column Functions

Setting the width of a specific column.

$this->activeSheet
    ->getColumnDimension($colString)
    ->setWidth($width);

Setting the default column width/row height for a sheet.

$this->activeSheet
    ->getDefaultColumnDimension()
    ->setWidth($width);
    
$this->activeSheet
    ->getDefaultRowDimension()
    ->setRowHeight($height);

Styles

Setting default styles for the active sheet

$this->activeSheet
    ->getDefaultStyle()
    ->applyFromArray($this->defaultStyle);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment