Skip to content

Instantly share code, notes, and snippets.

@r-sal
Last active May 26, 2025 08:41
Show Gist options
  • Save r-sal/4313500 to your computer and use it in GitHub Desktop.
Save r-sal/4313500 to your computer and use it in GitHub Desktop.

Revisions

  1. r-sal revised this gist Aug 9, 2013. 1 changed file with 9 additions and 1 deletion.
    10 changes: 9 additions & 1 deletion PHPExcel_a.md
    Original file line number Diff line number Diff line change
    @@ -3,4 +3,12 @@

    [PHPExcel: Documentation](https://github.com/PHPOffice/PHPExcel/tree/develop/Documentation)

    - [Valid array keys for style applyFromArray](https://github.com/PHPOffice/PHPExcel/blob/develop/Documentation/markdown/Overview/11-Appendices.md#valid-array-keys-for-style-applyfromarray)
    - [Valid array keys for style applyFromArray](https://github.com/PHPOffice/PHPExcel/blob/develop/Documentation/markdown/Overview/11-Appendices.md#valid-array-keys-for-style-applyfromarray)




    ```
    $sheetData = $objPHPExcel->getActiveSheet()->toArray(null,true,true,true);
    var_dump($sheetData);
    ```
  2. r-sal revised this gist Aug 9, 2013. 1 changed file with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions PHPExcel_a.md
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@


    (Valid array keys for style applyFromArray)[https://github.com/PHPOffice/PHPExcel/blob/develop/Documentation/markdown/Overview/11-Appendices.md#valid-array-keys-for-style-applyfromarray]

    [PHPExcel: Class Reference](http://www.contao-docs.org/docs/PHPExcel/html/class_p_h_p_excel___worksheet.html)

    [https://github.com/PHPOffice/PHPExcel/blob/develop/Documentation/markdown/Overview/11-Appendices.md#valid-array-keys-for-style-applyfromarray](Valid array keys for style applyFromArray)
    [PHPExcel: Documentation](https://github.com/PHPOffice/PHPExcel/tree/develop/Documentation)

    - [Valid array keys for style applyFromArray](https://github.com/PHPOffice/PHPExcel/blob/develop/Documentation/markdown/Overview/11-Appendices.md#valid-array-keys-for-style-applyfromarray)
  3. r-sal revised this gist Aug 9, 2013. 1 changed file with 4 additions and 1 deletion.
    5 changes: 4 additions & 1 deletion PHPExcel_a.md
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,6 @@


    (https://github.com/PHPOffice/PHPExcel/blob/develop/Documentation/markdown/Overview/11-Appendices.md#valid-array-keys-for-style-applyfromarray)[Valid array keys for style applyFromArray()]
    (Valid array keys for style applyFromArray)[https://github.com/PHPOffice/PHPExcel/blob/develop/Documentation/markdown/Overview/11-Appendices.md#valid-array-keys-for-style-applyfromarray]


    [https://github.com/PHPOffice/PHPExcel/blob/develop/Documentation/markdown/Overview/11-Appendices.md#valid-array-keys-for-style-applyfromarray](Valid array keys for style applyFromArray)
  4. r-sal revised this gist Aug 9, 2013. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions PHPExcel_a.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,3 @@


    (https://github.com/PHPOffice/PHPExcel/blob/develop/Documentation/markdown/Overview/11-Appendices.md#valid-array-keys-for-style-applyfromarray)[Valid array keys for style applyFromArray()]
  5. r-sal revised this gist Jul 12, 2013. No changes.
  6. r-sal revised this gist Jul 12, 2013. 3 changed files with 480 additions and 0 deletions.
    File renamed without changes.
    140 changes: 140 additions & 0 deletions PHPExcel_Misc.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,140 @@
    ## Sort
    ```php
    <?php
    $objPHPExcel->getActiveSheet()->toArray();

    // Rename worksheet
    $objPHPExcel->getActiveSheet()->setTitle('Datatypes');
    // Set active sheet index to the first sheet, so Excel opens this as the first sheet
    $objPHPExcel->setActiveSheetIndex(0);

    $objPHPExcel->getActiveSheet()->setShowGridLines(false);
    $objPHPExcel->getActiveSheet()->getColumnDimension('B')->setAutoSize(true);
    ```

    **Named Ranges**
    ```php
    // Define named ranges
    $objPHPExcel->addNamedRange( new PHPExcel_NamedRange('PersonName', $objPHPExcel->getActiveSheet(), 'B1') );
    // Rename named ranges
    $objPHPExcel->getNamedRange('PersonName')->setName('PersonFN');
    // Add some data to the sheet
    $objPHPExcel->getActiveSheet()->setCellValue('A1', 'Firstname:')
    ->setCellValue('B1', '=PersonFN');
    // Resolve range
    $objPHPExcel->getActiveSheet()->getCell('B1')->getCalculatedValue()l
    ```


    ## Date/Time

    * `PHPExcel_Style_NumberFormat::FORMAT_DATE_YYYYMMDD2` //2012-12-18
    * `PHPExcel_Style_NumberFormat::FORMAT_DATE_TIME4` //3:06:11
    * `PHPExcel_Style_NumberFormat::FORMAT_DATE_DATETIME` //18/12/12 3:06

    ```php
    $dateTimeNow = time();

    $sheet = $objPHPExcel->getActiveSheet();
    $sheet->setCellValue('A1', PHPExcel_Shared_Date::PHPToExcel( $dateTimeNow ));

    $sheet->getStyle('A1')
    ->getNumberFormat()
    ->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_DATE_YYYYMMDD2); //2012-12-18

    ```




    # Iterator
    ```php
    <?php
    $objReader = PHPExcel_IOFactory::createReader('Excel2007');
    $objPHPExcel = $objReader->load("05featuredemo.xlsx");

    echo date('H:i:s') , " Iterate worksheets" , EOL;
    foreach ($objPHPExcel->getWorksheetIterator() as $worksheet) {
    echo 'Worksheet - ' , $worksheet->getTitle() , EOL;

    foreach ($worksheet->getRowIterator() as $row) {
    echo ' Row number - ' , $row->getRowIndex() , EOL;

    $cellIterator = $row->getCellIterator();
    $cellIterator->setIterateOnlyExistingCells(false); // Loop all cells, even if it is not set
    foreach ($cellIterator as $cell) {
    if (!is_null($cell)) {
    echo ' Cell - ' , $cell->getCoordinate() , ' - ' , $cell->getCalculatedValue() , EOL;
    }
    }
    }
    }
    ```

    # Doc Properties
    **Core Properties:**
    ```php
    $objPHPExcel->getProperties()->setCreator("Maarten Balliauw")
    ->setLastModifiedBy("Maarten Balliauw")
    ->setTitle("Office 2007 XLSX Test Document")
    ->setSubject("Office 2007 XLSX Test Document")
    ->setDescription("Tasses.")
    ->setKeywords("office 2007 openxml php")
    ->setCategory("Test result file");

    $objPHPExcel->getProperties()->getCreator()
    $objPHPExcel->getProperties()->getCreated()
    $objPHPExcel->getProperties()->getLastModifiedBy()
    $objPHPExcel->getProperties()->getModified()
    $objPHPExcel->getProperties()->getTitle()
    $objPHPExcel->getProperties()->getSubject()
    $objPHPExcel->getProperties()->getDescription()
    $objPHPExcel->getProperties()->getKeywords()
    ```
    **Extended (Application) Properties**
    ```php
    $objPHPExcel->getProperties()->getCategory()
    $objPHPExcel->getProperties()->getCompany()
    $objPHPExcel->getProperties()->getManager()
    ```
    **Custom Properties**
    ```php
    $customProperties = $objPHPExcel->getProperties()->getCustomProperties();
    foreach($customProperties as $customProperty) {
    $propertyValue = $objPHPExcel->getProperties()->getCustomPropertyValue($customProperty);
    $propertyType = $objPHPExcel->getProperties()->getCustomPropertyType($customProperty);

    echo ' ' , $customProperty , ' - (' , $propertyType , ') - ';
    if ($propertyType == PHPExcel_DocumentProperties::PROPERTY_TYPE_DATE) {
    echo date('d-M-Y H:i:s',$propertyValue) , EOL;
    } elseif ($propertyType == PHPExcel_DocumentProperties::PROPERTY_TYPE_BOOLEAN) {
    echo (($propertyValue) ? 'TRUE' : 'FALSE') , EOL;
    } else {
    echo $propertyValue , EOL;
    }
    }

    # Reading Files

    ```php
    <?php
    $objReader = PHPExcel_IOFactory::createReader('Excel2007');
    $objPHPExcel = $objReader->load("templates/template_1.xlsx");

    $data = array(array('title' => 'Excel for dummies', 'price'=> 17.99, 'quantity' => 2),
    array('title' => 'PHP for dummies', 'price'=> 15.99, 'quantity' => 1),
    array('title' => 'Inside OOP', 'price'=> 12.95, 'quantity' => 1));

    $baseRow = 4;
    foreach($data as $r => $dataRow) {
    $row = $baseRow + $r;
    $objPHPExcel->getActiveSheet()->insertNewRowBefore($row,1);

    $objPHPExcel->getActiveSheet()->setCellValue('A'.$row, $r+1)
    ->setCellValue('B'.$row, $dataRow['title'])
    ->setCellValue('C'.$row, $dataRow['price'])
    ->setCellValue('D'.$row, $dataRow['quantity'])
    ->setCellValue('E'.$row, '=C'.$row.'*D'.$row);
    }
    $objPHPExcel->getActiveSheet()->removeRow($baseRow-1,1);
    ```
    340 changes: 340 additions & 0 deletions PHPExcel_featDem.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,340 @@
    ```php
    <?php

    // Create new PHPExcel object
    $objPHPExcel = new PHPExcel();

    // Set document properties
    $objPHPExcel->getProperties()->setCreator("Maarten Balliauw")
    ->setLastModifiedBy("Maarten Balliauw");


    // Create a first sheet, representing sales data
    $objPHPExcel->setActiveSheetIndex(0);
    $objPHPExcel->getActiveSheet()->setCellValue('B1', 'Invoice');
    $objPHPExcel->getActiveSheet()->setCellValue('D1', PHPExcel_Shared_Date::PHPToExcel( gmmktime(0,0,0,date('m'),date('d'),date('Y')) ));
    $objPHPExcel->getActiveSheet()->getStyle('D1')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_DATE_XLSX15);
    $objPHPExcel->getActiveSheet()->setCellValue('E1', '#12566');

    $objPHPExcel->getActiveSheet()->setCellValue('A3', 'Product Id');
    $objPHPExcel->getActiveSheet()->setCellValue('B3', 'Description');
    $objPHPExcel->getActiveSheet()->setCellValue('C3', 'Price');
    $objPHPExcel->getActiveSheet()->setCellValue('D3', 'Amount');
    $objPHPExcel->getActiveSheet()->setCellValue('E3', 'Total');

    $objPHPExcel->getActiveSheet()->setCellValue('A4', '1001');
    $objPHPExcel->getActiveSheet()->setCellValue('B4', 'PHP for dummies');
    $objPHPExcel->getActiveSheet()->setCellValue('C4', '20');
    $objPHPExcel->getActiveSheet()->setCellValue('D4', '1');
    $objPHPExcel->getActiveSheet()->setCellValue('E4', '=IF(D4<>"",C4*D4,"")');

    $objPHPExcel->getActiveSheet()->setCellValue('A5', '1012');
    $objPHPExcel->getActiveSheet()->setCellValue('B5', 'OpenXML for dummies');
    $objPHPExcel->getActiveSheet()->setCellValue('C5', '22');
    $objPHPExcel->getActiveSheet()->setCellValue('D5', '2');
    $objPHPExcel->getActiveSheet()->setCellValue('E5', '=IF(D5<>"",C5*D5,"")');

    $objPHPExcel->getActiveSheet()->setCellValue('E6', '=IF(D6<>"",C6*D6,"")');
    $objPHPExcel->getActiveSheet()->setCellValue('E7', '=IF(D7<>"",C7*D7,"")');
    $objPHPExcel->getActiveSheet()->setCellValue('E8', '=IF(D8<>"",C8*D8,"")');
    $objPHPExcel->getActiveSheet()->setCellValue('E9', '=IF(D9<>"",C9*D9,"")');

    $objPHPExcel->getActiveSheet()->setCellValue('D11', 'Total excl.:');
    $objPHPExcel->getActiveSheet()->setCellValue('E11', '=SUM(E4:E9)');

    $objPHPExcel->getActiveSheet()->setCellValue('D12', 'VAT:');
    $objPHPExcel->getActiveSheet()->setCellValue('E12', '=E11*0.21');

    $objPHPExcel->getActiveSheet()->setCellValue('D13', 'Total incl.:');
    $objPHPExcel->getActiveSheet()->setCellValue('E13', '=E11+E12');

    // Add comment
    $objPHPExcel->getActiveSheet()->getComment('E11')->setAuthor('PHPExcel');
    $objCommentRichText = $objPHPExcel->getActiveSheet()->getComment('E11')->getText()->createTextRun('PHPExcel:');
    $objCommentRichText->getFont()->setBold(true);
    $objPHPExcel->getActiveSheet()->getComment('E11')->getText()->createTextRun("\r\n");
    $objPHPExcel->getActiveSheet()->getComment('E11')->getText()->createTextRun('Total amount on the current invoice, excluding VAT.');

    $objPHPExcel->getActiveSheet()->getComment('E12')->setAuthor('PHPExcel');
    $objCommentRichText = $objPHPExcel->getActiveSheet()->getComment('E12')->getText()->createTextRun('PHPExcel:');
    $objCommentRichText->getFont()->setBold(true);
    $objPHPExcel->getActiveSheet()->getComment('E12')->getText()->createTextRun("\r\n");
    $objPHPExcel->getActiveSheet()->getComment('E12')->getText()->createTextRun('Total amount of VAT on the current invoice.');

    $objPHPExcel->getActiveSheet()->getComment('E13')->setAuthor('PHPExcel');
    $objCommentRichText = $objPHPExcel->getActiveSheet()->getComment('E13')->getText()->createTextRun('PHPExcel:');
    $objCommentRichText->getFont()->setBold(true);
    $objPHPExcel->getActiveSheet()->getComment('E13')->getText()->createTextRun("\r\n");
    $objPHPExcel->getActiveSheet()->getComment('E13')->getText()->createTextRun('Total amount o...uding VAT.');
    $objPHPExcel->getActiveSheet()->getComment('E13')->setWidth('100pt');
    $objPHPExcel->getActiveSheet()->getComment('E13')->setHeight('100pt');
    $objPHPExcel->getActiveSheet()->getComment('E13')->setMarginLeft('150pt');
    $objPHPExcel->getActiveSheet()->getComment('E13')->getFillColor()->setRGB('EEEEEE');


    // Add rich-text string
    $objRichText = new PHPExcel_RichText();
    $objRichText->createText('This invoice is ');

    $objPayable = $objRichText->createTextRun('payable within thirty days after the end of the month');
    $objPayable->getFont()->setBold(true);
    $objPayable->getFont()->setItalic(true);
    $objPayable->getFont()->setColor( new PHPExcel_Style_Color( PHPExcel_Style_Color::COLOR_DARKGREEN ) );

    $objRichText->createText(', unless specified otherwise on the invoice.');

    $objPHPExcel->getActiveSheet()->getCell('A18')->setValue($objRichText);

    // Merge cells
    $objPHPExcel->getActiveSheet()->mergeCells('A18:E22');
    $objPHPExcel->getActiveSheet()->mergeCells('A28:B28'); // Just to test...
    $objPHPExcel->getActiveSheet()->unmergeCells('A28:B28'); // Just to test...

    // Protect cells
    // Needs to be set to true in order to enable any worksheet protection!
    $objPHPExcel->getActiveSheet()->getProtection()->setSheet(true);
    $objPHPExcel->getActiveSheet()->protectCells('A3:E13', 'PHPExcel');

    // Set cell number formats
    $objPHPExcel->getActiveSheet()->getStyle('E4:E13')
    ->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_CURRENCY_EUR_SIMPLE);

    // Set column widths
    $objPHPExcel->getActiveSheet()->getColumnDimension('B')->setAutoSize(true);
    $objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(12);
    $objPHPExcel->getActiveSheet()->getColumnDimension('E')->setWidth(12);

    // Set fonts
    $objPHPExcel->getActiveSheet()->getStyle('B1')->getFont()->setName('Candara');
    $objPHPExcel->getActiveSheet()->getStyle('B1')->getFont()->setSize(20);
    $objPHPExcel->getActiveSheet()->getStyle('B1')->getFont()->setBold(true);
    $objPHPExcel->getActiveSheet()->getStyle('B1')->getFont()->setUnderline(PHPExcel_Style_Font::UNDERLINE_SINGLE);
    $objPHPExcel->getActiveSheet()->getStyle('B1')->getFont()->getColor()->setARGB(PHPExcel_Style_Color::COLOR_WHITE);

    $objPHPExcel->getActiveSheet()->getStyle('D1')->getFont()->getColor()->setARGB(PHPExcel_Style_Color::COLOR_WHITE);
    $objPHPExcel->getActiveSheet()->getStyle('E1')->getFont()->getColor()->setARGB(PHPExcel_Style_Color::COLOR_WHITE);

    $objPHPExcel->getActiveSheet()->getStyle('D13')->getFont()->setBold(true);
    $objPHPExcel->getActiveSheet()->getStyle('E13')->getFont()->setBold(true);

    // Set alignments
    $objPHPExcel->getActiveSheet()->getStyle('D11')->getAlignment()
    ->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
    $objPHPExcel->getActiveSheet()->getStyle('D12')->getAlignment()
    ->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
    $objPHPExcel->getActiveSheet()->getStyle('D13')->getAlignment()
    ->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);

    $objPHPExcel->getActiveSheet()->getStyle('A18')->getAlignment()
    ->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_JUSTIFY);
    $objPHPExcel->getActiveSheet()->getStyle('A18')->getAlignment()
    ->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);

    $objPHPExcel->getActiveSheet()->getStyle('B5')->getAlignment()->setShrinkToFit(true);

    // Set thin black border outline around column
    $styleThinBlackBorderOutline = array(
    'borders' => array(
    'outline' => array(
    'style' => PHPExcel_Style_Border::BORDER_THIN,
    'color' => array('argb' => 'FF000000'),
    ),
    ),
    );
    $objPHPExcel->getActiveSheet()->getStyle('A4:E10')
    ->applyFromArray($styleThinBlackBorderOutline);


    // Set thick brown border outline around "Total"
    $styleThickBrownBorderOutline = array(
    'borders' => array(
    'outline' => array(
    'style' => PHPExcel_Style_Border::BORDER_THICK,
    'color' => array('argb' => 'FF993300'),
    ),
    ),
    );
    $objPHPExcel->getActiveSheet()->getStyle('D13:E13')
    ->applyFromArray($styleThickBrownBorderOutline);

    // Set fills
    $objPHPExcel->getActiveSheet()->getStyle('A1:E1')
    ->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID);
    $objPHPExcel->getActiveSheet()->getStyle('A1:E1')
    ->getFill()->getStartColor()->setARGB('FF808080');

    // Set style for header row using alternative method
    $objPHPExcel->getActiveSheet()->getStyle('A3:E3')->applyFromArray(
    array(
    'font' => array(
    'bold' => true
    ),
    'alignment' => array(
    'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_RIGHT,
    ),
    'borders' => array(
    'top' => array(
    'style' => PHPExcel_Style_Border::BORDER_THIN
    )
    ),
    'fill' => array(
    'type' => PHPExcel_Style_Fill::FILL_GRADIENT_LINEAR,
    'rotation' => 90,
    'startcolor' => array(
    'argb' => 'FFA0A0A0'
    ),
    'endcolor' => array(
    'argb' => 'FFFFFFFF'
    )
    )
    )
    );

    $objPHPExcel->getActiveSheet()->getStyle('A3')->applyFromArray(
    array(
    'alignment' => array(
    'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_LEFT,
    ),
    'borders' => array(
    'left' => array(
    'style' => PHPExcel_Style_Border::BORDER_THIN
    )
    )
    )
    );

    $objPHPExcel->getActiveSheet()->getStyle('B3')->applyFromArray(
    array(
    'alignment' => array(
    'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_LEFT,
    )
    )
    );

    $objPHPExcel->getActiveSheet()->getStyle('E3')->applyFromArray(
    array(
    'borders' => array(
    'right' => array(
    'style' => PHPExcel_Style_Border::BORDER_THIN
    )
    )
    )
    );

    // Unprotect a cell
    $objPHPExcel->getActiveSheet()
    ->getStyle('B1')->getProtection()->setLocked(PHPExcel_Style_Protection::PROTECTION_UNPROTECTED);

    // Add a hyperlink to the sheet
    $objPHPExcel->getActiveSheet()->setCellValue('E26', 'www.phpexcel.net');
    $objPHPExcel->getActiveSheet()->getCell('E26')->getHyperlink()->setUrl('http://www.phpexcel.net');
    $objPHPExcel->getActiveSheet()->getCell('E26')->getHyperlink()->setTooltip('Navigate to website');
    $objPHPExcel->getActiveSheet()->getStyle('E26')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);

    $objPHPExcel->getActiveSheet()->setCellValue('E27', 'Terms and conditions');
    $objPHPExcel->getActiveSheet()->getCell('E27')->getHyperlink()->setUrl("sheet://'Terms and conditions'!A1");
    $objPHPExcel->getActiveSheet()->getCell('E27')->getHyperlink()->setTooltip('Review terms and conditions');
    $objPHPExcel->getActiveSheet()->getStyle('E27')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);

    // Add a drawing to the worksheet
    $objDrawing = new PHPExcel_Worksheet_Drawing();
    $objDrawing->setName('Logo');
    $objDrawing->setDescription('Logo');
    $objDrawing->setPath('./images/officelogo.jpg');
    $objDrawing->setHeight(36);
    $objDrawing->setWorksheet($objPHPExcel->getActiveSheet());

    // Add a drawing to the worksheet
    $objDrawing = new PHPExcel_Worksheet_Drawing();
    $objDrawing->setName('Paid');
    $objDrawing->setDescription('Paid');
    $objDrawing->setPath('./images/paid.png');
    $objDrawing->setCoordinates('B15');
    $objDrawing->setOffsetX(110);
    $objDrawing->setRotation(25);
    $objDrawing->getShadow()->setVisible(true);
    $objDrawing->getShadow()->setDirection(45);
    $objDrawing->setWorksheet($objPHPExcel->getActiveSheet());

    // Add a drawing to the worksheet
    $objDrawing = new PHPExcel_Worksheet_Drawing();
    $objDrawing->setName('PHPExcel logo');
    $objDrawing->setDescription('PHPExcel logo');
    $objDrawing->setPath('./images/phpexcel_logo.gif');
    $objDrawing->setHeight(36);
    $objDrawing->setCoordinates('D24');
    $objDrawing->setOffsetX(10);
    $objDrawing->setWorksheet($objPHPExcel->getActiveSheet());

    // Play around with inserting and removing rows and columns
    $objPHPExcel->getActiveSheet()->insertNewRowBefore(6, 10);
    $objPHPExcel->getActiveSheet()->removeRow(6, 10);
    $objPHPExcel->getActiveSheet()->insertNewColumnBefore('E', 5);
    $objPHPExcel->getActiveSheet()->removeColumn('E', 5);

    // Set header and footer. When no different headers for odd/even are used, odd header is assumed.
    $objPHPExcel->getActiveSheet()->getHeaderFooter()
    ->setOddHeader('&L&BInvoice&RPrinted on &D');
    $objPHPExcel->getActiveSheet()->getHeaderFooter()
    ->setOddFooter('&L&B' . $objPHPExcel->getProperties()->getTitle() . '&RPage &P of &N');

    // Set page orientation and size
    $objPHPExcel->getActiveSheet()->getPageSetup()->setOrientation(PHPExcel_Worksheet_PageSetup::ORIENTATION_PORTRAIT);
    $objPHPExcel->getActiveSheet()->getPageSetup()->setPaperSize(PHPExcel_Worksheet_PageSetup::PAPERSIZE_A4);

    // Rename first worksheet
    $objPHPExcel->getActiveSheet()->setTitle('Invoice');


    // Create a new worksheet, after the default sheet
    $objPHPExcel->createSheet();

    // Llorem ipsum...
    $sLloremIpsum = 'Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Vivamus eget ante. Sed cursus nunc semper tortor. Aliquam luctus purus non elit. Fusce vel elit commodo sapien dignissim dignissim. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Curabitur accumsan magna sed massa. Nullam bibendum quam ac ipsum. Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Proin augue. Praesent malesuada justo sed orci. Pellentesque lacus ligula, sodales quis, ultricies a, ultricies vitae, elit. Sed luctus consectetuer dolor. Vivamus vel sem ut nisi sodales accumsan. Nunc et felis. Suspendisse semper viverra odio. Morbi at odio. Integer a orci a purus venenatis molestie. Nam mattis. Praesent rhoncus, nisi vel mattis auctor, neque nisi faucibus sem, non dapibus elit pede ac nisl. Cras turpis.';

    // Add some data to the second sheet, resembling some different data types
    $objPHPExcel->setActiveSheetIndex(1);
    $objPHPExcel->getActiveSheet()->setCellValue('A1', 'Terms and conditions');
    $objPHPExcel->getActiveSheet()->setCellValue('A3', $sLloremIpsum);
    $objPHPExcel->getActiveSheet()->setCellValue('A4', $sLloremIpsum);
    $objPHPExcel->getActiveSheet()->setCellValue('A5', $sLloremIpsum);
    $objPHPExcel->getActiveSheet()->setCellValue('A6', $sLloremIpsum);

    // Set the worksheet tab color
    $objPHPExcel->getActiveSheet()->getTabColor()->setARGB('FF0094FF');

    // Set alignments
    $objPHPExcel->getActiveSheet()->getStyle('A3:A6')->getAlignment()->setWrapText(true);

    // Set column widths
    $objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(80);

    // Set fonts
    $objPHPExcel->getActiveSheet()->getStyle('A1')->getFont()->setName('Candara');
    $objPHPExcel->getActiveSheet()->getStyle('A1')->getFont()->setSize(20);
    $objPHPExcel->getActiveSheet()->getStyle('A1')->getFont()->setBold(true);
    $objPHPExcel->getActiveSheet()->getStyle('A1')->getFont()->setUnderline(PHPExcel_Style_Font::UNDERLINE_SINGLE);

    $objPHPExcel->getActiveSheet()->getStyle('A3:A6')->getFont()->setSize(8);

    // Add a drawing to the worksheet
    $objDrawing = new PHPExcel_Worksheet_Drawing();
    $objDrawing->setName('Terms and conditions');
    $objDrawing->setDescription('Terms and conditions');
    $objDrawing->setPath('./images/termsconditions.jpg');
    $objDrawing->setCoordinates('B14');
    $objDrawing->setWorksheet($objPHPExcel->getActiveSheet());

    // Set page orientation and size
    $objPHPExcel->getActiveSheet()->getPageSetup()
    ->setOrientation(PHPExcel_Worksheet_PageSetup::ORIENTATION_LANDSCAPE);
    $objPHPExcel->getActiveSheet()->getPageSetup()
    ->setPaperSize(PHPExcel_Worksheet_PageSetup::PAPERSIZE_A4);

    // Rename second worksheet
    $objPHPExcel->getActiveSheet()->setTitle('Terms and conditions');


    // Set active sheet index to the first sheet, so Excel opens this as the first sheet
    $objPHPExcel->setActiveSheetIndex(0);
    ```
  7. r-sal revised this gist Jul 12, 2013. 1 changed file with 33 additions and 0 deletions.
    33 changes: 33 additions & 0 deletions PHPExcel_to-sort.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,33 @@
    **Merge & Un-Merge cells**
    ```
    $objPHPExcel->getActiveSheet()->mergeCells('A28:B28');
    $objPHPExcel->getActiveSheet()->unmergeCells('A28:B28');
    ```

    Add a hyperlink to the sheet
    ```
    $objPHPExcel->getActiveSheet()->setCellValue('E26', 'www.phpexcel.net');
    $objPHPExcel->getActiveSheet()->getCell('E26')->getHyperlink()->setUrl('http://www.phpexcel.net');
    $objPHPExcel->getActiveSheet()->getCell('E26')->getHyperlink()->setTooltip('Navigate to website');
    $objPHPExcel->getActiveSheet()->getStyle('E26')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
    ```

    tab color
    ```
    $objPHPExcel->getActiveSheet()->getTabColor()->setARGB('FF0094FF');
    ```

    inserting and removing rows and columns
    ```
    $objPHPExcel->getActiveSheet()->insertNewRowBefore(6, 10);
    $objPHPExcel->getActiveSheet()->removeRow(6, 10);
    $objPHPExcel->getActiveSheet()->insertNewColumnBefore('E', 5);
    $objPHPExcel->getActiveSheet()->removeColumn('E', 5);
    ```


    Set page orientation and size
    ```
    $objPHPExcel->getActiveSheet()->getPageSetup()->setOrientation(PHPExcel_Worksheet_PageSetup::ORIENTATION_PORTRAIT);
    $objPHPExcel->getActiveSheet()->getPageSetup()->setPaperSize(PHPExcel_Worksheet_PageSetup::PAPERSIZE_A4);
    ```
  8. r-sal revised this gist Jan 22, 2013. 1 changed file with 80 additions and 0 deletions.
    80 changes: 80 additions & 0 deletions PHPExcel_Styles.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,80 @@
    # PHPExcel:Styles


    **Set default font**
    ```php
    $objPHPExcel->getDefaultStyle()->getFont()->setName('Arial')->setSize(10);
    ```

    **Set fonts**
    ```php
    <?php
    $sheet->getStyle('B1')->getFont()->setName('Candara');
    $sheet->getStyle('B1')->getFont()->setSize(20);
    $sheet->getStyle('B1')->getFont()->setBold(true);
    $sheet->getStyle('B1')->getFont()->setUnderline(PHPExcel_Style_Font::UNDERLINE_SINGLE);
    $sheet->getStyle('D1')->getFont()->getColor()->setARGB(PHPExcel_Style_Color::COLOR_WHITE);
    $sheet->getStyle('D13')->getFont()->setBold(true);
    ```

    **Set alignments**
    ```php
    $sheet->getStyle('D11')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
    $sheet->getStyle('A18')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_JUSTIFY);
    $sheet->getStyle('A18')->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
    $sheet->getStyle('B5')->getAlignment()->setShrinkToFit(true);
    ```

    ## Add rich-text
    ```php
    $objRichText = new PHPExcel_RichText();
    $objRichText->createText('This invoice is ');

    $objPayable = $objRichText->createTextRun('payable within thirty days after the end of the month');
    $objPayable->getFont()->setBold(true);
    $objPayable->getFont()->setItalic(true);
    $objPayable->getFont()->setColor( new PHPExcel_Style_Color( PHPExcel_Style_Color::COLOR_DARKGREEN ) );

    $objRichText->createText(', unless specified otherwise on the invoice.');
    $objPHPExcel->getActiveSheet()->getCell('A18')->setValue($objRichText);
    ```

    ## Comments
    ```php
    $sheet->getComment('E13')->setAuthor('PHPExcel');
    $objCommentRichText = $sheet->getComment('E13')->getText()->createTextRun('PHPExcel:');
    $objCommentRichText->getFont()->setBold(true);
    $sheet->getComment('E13')->getText()->createTextRun("\r\n");
    $sheet->getComment('E13')->getText()->createTextRun('some text....');
    $sheet->getComment('E13')->setWidth('100pt');
    $sheet->getComment('E13')->setHeight('100pt');
    $sheet->getComment('E13')->setMarginLeft('150pt');
    $sheet->getComment('E13')->getFillColor()->setRGB('EEEEEE');
    ```

    ## Shared Styles
    ```php
    $sharedStyle = new PHPExcel_Style();
    $sharedStyle1->applyFromArray(
    array('fill' => array(
    'type' => PHPExcel_Style_Fill::FILL_SOLID,
    'color' => array('argb' => 'FFCCFFCC')
    ),
    'borders' => array(
    'bottom' => array('style' => PHPExcel_Style_Border::BORDER_THIN),
    'right' => array('style' => PHPExcel_Style_Border::BORDER_MEDIUM)
    )
    ));

    $objPHPExcel->getActiveSheet()->setSharedStyle($sharedStyle, "A1:T100");
    ```

    ## Duplicate Style
    ```php
    $style = new PHPExcel_Style();
    $style->getFont()->setSize(20);
    $coord = PHPExcel_Cell::stringFromColumnIndex($col) . $row;
    $worksheet->setCellValue($coord, $str);
    // Copy the style to that cell
    $worksheet->duplicateStyle($style, $coord);
    ```
  9. r-sal revised this gist Dec 16, 2012. 1 changed file with 31 additions and 1 deletion.
    32 changes: 31 additions & 1 deletion PHPExcel_Basics.markdown
    Original file line number Diff line number Diff line change
    @@ -33,7 +33,13 @@ Text can be added to a cell using `setCellValue($colRow, $data)`
    `$data` - The data to write

    ```
    $this->activeSheet->setCellValue($colRow, $data);
    $this->activeSheet
    ->setCellValue($colRow, $data);
    $this->activeSheet
    ->setCellValue("B1", $data)
    ->setCellValue("B2", $data);
    ->setCellValue("B5", $data);
    ```

    ```
    @@ -99,18 +105,42 @@ Default row height for an entire sheet:

    ## Styling Cells
    ```
    $this->activeSheet
    ->getStyle("B1")
    ->getAlignment()
    ->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
    $styleArray = array(
    'font' => array(
    'bold' => true,
    )
    );
    $this->activeSheet
    ->getStyle("B1:F1")
    ->applyFromArray(array("font" => array( "bold" => true)));
    ```

    ```
    ->getStyle("D1:D20")->getAlignment()->setWrapText(true);
    ```

    Setting default styles for the active sheet
    ```
    $this->activeSheet
    ->getDefaultStyle()
    ->applyFromArray($this->defaultStyle);
    ```

    ## Setting file properties
    ```
    $this->PHPExcel->getProperties()->setCreator("");
    $this->PHPExcel->getProperties()->setLastModifiedBy("");
    $this->PHPExcel->getProperties()->setTitle("");
    $this->PHPExcel->getProperties()->setSubject("");
    $this->PHPExcel->getProperties()->setDescription("..");
    $this->PHPExcel->getProperties()->setKeywords("");
    $this->PHPExcel->getProperties()->setCategory("");
    ```
  10. r-sal revised this gist Dec 16, 2012. 1 changed file with 6 additions and 6 deletions.
    12 changes: 6 additions & 6 deletions PHPExcel_Basics.markdown
    Original file line number Diff line number Diff line change
    @@ -6,19 +6,19 @@ Creating a new PHPExcel Object.

    ### Working with sheets

    **Creating a new sheet:**
    Creating a new sheet:
    ```
    $this->activeSheet = $this->PHPExcel->createSheet();
    ```
    **Getting the active Sheet:**
    Getting the active Sheet:
    ```
    $this->activeSheet = $this->PHPExcel->getActiveSheet();
    ```
    **Setting the active sheet:**
    Setting the active sheet:
    ```
    $this->PHPExcel->setActiveSheetIndex(2);
    ```
    **Renaming a worksheet:**
    Renaming a worksheet:
    ```
    $this->activeSheet->setTitle($title);
    ```
    @@ -65,7 +65,7 @@ Or the array can be written manually by looping through the array and calling `s
    }
    ```

    ### Formatting
    ### Formatting Cells
    **Setting column width**
    A single column:
    ```
    @@ -97,7 +97,7 @@ Default row height for an entire sheet:
    ->setRowHeight($height);
    ```

    ## Adding styles
    ## Styling Cells
    ```
    $this->activeSheet
    ->getStyle("B1")
  11. r-sal revised this gist Dec 16, 2012. 1 changed file with 36 additions and 26 deletions.
    62 changes: 36 additions & 26 deletions PHPExcel_Basics.markdown
    Original file line number Diff line number Diff line change
    @@ -1,26 +1,26 @@
    ## Basics
    Creating a new PHPExcel Object.
    ```
    $this->PHPExcel = new PHPExcel();
    $this->PHPExcel = new PHPExcel();
    ```

    ### Working with sheets

    **Creating a new sheet:**
    ```
    $this->activeSheet = $this->PHPExcel->createSheet();
    $this->activeSheet = $this->PHPExcel->createSheet();
    ```
    **Getting the active Sheet:**
    ```
    $this->activeSheet = $this->PHPExcel->getActiveSheet();
    $this->activeSheet = $this->PHPExcel->getActiveSheet();
    ```
    **Setting the active sheet:**
    ```
    $this->PHPExcel->setActiveSheetIndex(2);
    $this->PHPExcel->setActiveSheetIndex(2);
    ```
    **Renaming a worksheet:**
    ```
    $this->activeSheet->setTitle($title);
    $this->activeSheet->setTitle($title);
    ```


    @@ -52,55 +52,65 @@ A 2-dimensional array can be written to the current sheet usng `fromArray($twoDi
    * `$topLeftCorner` - where the top left corner should be.

    ```
    $this->activeSheet->fromArray($sheet);
    $this->activeSheet->fromArray($sheet, "", $colRow);
    $this->activeSheet->fromArray($sheet);
    $this->activeSheet->fromArray($sheet, "", $colRow);
    ```

    Or the array can be written manually by looping through the array and calling `setCellValue`
    ```
    foreach($rows as $row => $columns) {
    foreach($columns as $column => $data) {
    $this->activeSheet->setCellValue($column.$row, $data);
    foreach($rows as $row => $columns) {
    foreach($columns as $column => $data) {
    $this->activeSheet->setCellValue($column.$row, $data);
    }
    }
    }
    ```

    ### Formatting
    **Setting column width**
    A single column:
    ```
    $this->activeSheet->getColumnDimension($colString)->setWidth($width);
    $this->activeSheet
    ->getColumnDimension($colString)
    ->setWidth($width);
    ```
    Default width for all columns on a sheet:
    ```
    $this->activeSheet->getDefaultColumnDimension()->setWidth($width);
    $this->activeSheet
    ->getDefaultColumnDimension()
    ->setWidth($width);
    ```
    Auto size
    ```
    $this->activeSheet->getColumnDimension("A")->setAutoSize(true);
    $this->activeSheet
    ->getColumnDimension("A")
    ->setAutoSize(true);
    ```

    ```
    $this->activeSheet->getStyle("B1")->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
    $this->activeSheet->getStyle("B1:F1")->applyFromArray(array("font" => array( "bold" => true)));
    ```

    **Setting row height**
    A single row:
    ```
    ```
    Default row height for an entire sheet:
    ```
    $this->activeSheet
    ->getDefaultRowDimension()
    ->setRowHeight($height);
    $this->activeSheet
    ->getDefaultRowDimension()
    ->setRowHeight($height);
    ```

    ## Adding styles
    ```
    $this->activeSheet
    ->getStyle("B1")
    ->getAlignment()
    ->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
    $this->activeSheet
    ->getStyle("B1:F1")
    ->applyFromArray(array("font" => array( "bold" => true)));
    ```
    Setting default styles for the active sheet
    ```
    $this->activeSheet
    ->getDefaultStyle()
    ->applyFromArray($this->defaultStyle);
    $this->activeSheet
    ->getDefaultStyle()
    ->applyFromArray($this->defaultStyle);
    ```
  12. r-sal revised this gist Dec 16, 2012. 1 changed file with 32 additions and 23 deletions.
    55 changes: 32 additions & 23 deletions PHPExcel_Basics.markdown
    Original file line number Diff line number Diff line change
    @@ -23,30 +23,7 @@ $this->PHPExcel->setActiveSheetIndex(2);
    $this->activeSheet->setTitle($title);
    ```

    **Setting column width**
    A single column:
    ```
    $this->activeSheet
    ->getColumnDimension($colString)
    ->setWidth($width);
    ```
    Default width for all columns on a sheet:
    ```
    $this->activeSheet
    ->getDefaultColumnDimension()
    ->setWidth($width);
    ```
    **Setting row height**
    A single row:
    ```

    ```
    Default row height for an entire sheet:
    ```
    $this->activeSheet
    ->getDefaultRowDimension()
    ->setRowHeight($height);
    ```



    @@ -88,6 +65,38 @@ foreach($rows as $row => $columns) {
    }
    ```

    ### Formatting
    **Setting column width**
    A single column:
    ```
    $this->activeSheet->getColumnDimension($colString)->setWidth($width);
    ```
    Default width for all columns on a sheet:
    ```
    $this->activeSheet->getDefaultColumnDimension()->setWidth($width);
    ```
    Auto size
    ```
    $this->activeSheet->getColumnDimension("A")->setAutoSize(true);
    ```

    ```
    $this->activeSheet->getStyle("B1")->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
    $this->activeSheet->getStyle("B1:F1")->applyFromArray(array("font" => array( "bold" => true)));
    ```

    **Setting row height**
    A single row:
    ```
    ```
    Default row height for an entire sheet:
    ```
    $this->activeSheet
    ->getDefaultRowDimension()
    ->setRowHeight($height);
    ```

    ## Adding styles
    Setting default styles for the active sheet
    ```
  13. r-sal revised this gist Dec 16, 2012. 1 changed file with 11 additions and 11 deletions.
    22 changes: 11 additions & 11 deletions PHPExcel_Basics.markdown
    Original file line number Diff line number Diff line change
    @@ -6,8 +6,6 @@ $this->PHPExcel = new PHPExcel();

    ### Working with sheets



    **Creating a new sheet:**
    ```
    $this->activeSheet = $this->PHPExcel->createSheet();
    @@ -16,32 +14,34 @@ $this->activeSheet = $this->PHPExcel->createSheet();
    ```
    $this->activeSheet = $this->PHPExcel->getActiveSheet();
    ```
    **Setting the active sheet:**
    ```
    $this->PHPExcel->setActiveSheetIndex(2);
    ```
    **Renaming a worksheet:**
    ```
    $this->activeSheet->setTitle($title);
    ```

    Setting the active sheet:
    ```
    $sheetIndex = 2;
    $this->PHPExcel->setActiveSheetIndex($sheetIndex)
    ```

    **Setting column width**
    Setting width for a single column:
    A single column:
    ```
    $this->activeSheet
    ->getColumnDimension($colString)
    ->setWidth($width);
    ```
    Setting the default width for all columns on a sheet:
    Default width for all columns on a sheet:
    ```
    $this->activeSheet
    ->getDefaultColumnDimension()
    ->setWidth($width);
    ```
    **Setting row height**
    Setting the default row height for an entire sheet:
    A single row:
    ```
    ```
    Default row height for an entire sheet:
    ```
    $this->activeSheet
    ->getDefaultRowDimension()
  14. r-sal revised this gist Dec 16, 2012. 1 changed file with 11 additions and 11 deletions.
    22 changes: 11 additions & 11 deletions PHPExcel_Basics.markdown
    Original file line number Diff line number Diff line change
    @@ -5,21 +5,21 @@ $this->PHPExcel = new PHPExcel();
    ```

    ### Working with sheets
    <dl>
    <dt>Creating a new sheet:</dt>
    <dd>`$this->activeSheet = $this->PHPExcel->createSheet();`</dd>
    <dt>Getting the active Sheet:</dt>
    <dd>```$this->activeSheet = $this->PHPExcel->getActiveSheet();```</dd>
    <dt></dt>
    <dd></dd>
    </dl>



    **Creating a new sheet:**
    ```$this->activeSheet = $this->PHPExcel->createSheet();```
    ```
    $this->activeSheet = $this->PHPExcel->createSheet();
    ```
    **Getting the active Sheet:**
    ```$this->activeSheet = $this->PHPExcel->getActiveSheet();```
    ```
    $this->activeSheet = $this->PHPExcel->getActiveSheet();
    ```
    **Renaming a worksheet:**
    ```$this->activeSheet->setTitle($title);```
    ```
    $this->activeSheet->setTitle($title);
    ```

    Setting the active sheet:
    ```
  15. r-sal revised this gist Dec 16, 2012. 1 changed file with 6 additions and 3 deletions.
    9 changes: 6 additions & 3 deletions PHPExcel_Basics.markdown
    Original file line number Diff line number Diff line change
    @@ -14,9 +14,12 @@ $this->PHPExcel = new PHPExcel();
    <dd></dd>
    </dl>

    * Creating a new sheet: `$this->activeSheet = $this->PHPExcel->createSheet();`
    * Getting the active Sheet: `$this->activeSheet = $this->PHPExcel->getActiveSheet();`
    > Renaming a worksheet: `$this->activeSheet->setTitle($title);`
    **Creating a new sheet:**
    ```$this->activeSheet = $this->PHPExcel->createSheet();```
    **Getting the active Sheet:**
    ```$this->activeSheet = $this->PHPExcel->getActiveSheet();```
    **Renaming a worksheet:**
    ```$this->activeSheet->setTitle($title);```

    Setting the active sheet:
    ```
  16. r-sal revised this gist Dec 16, 2012. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions PHPExcel_Basics.markdown
    Original file line number Diff line number Diff line change
    @@ -7,9 +7,9 @@ $this->PHPExcel = new PHPExcel();
    ### Working with sheets
    <dl>
    <dt>Creating a new sheet:</dt>
    <dd> `$this->activeSheet = $this->PHPExcel->createSheet();` </dd>
    <dd>`$this->activeSheet = $this->PHPExcel->createSheet();`</dd>
    <dt>Getting the active Sheet:</dt>
    <dd> `$this->activeSheet = $this->PHPExcel->getActiveSheet();` </dd>
    <dd>```$this->activeSheet = $this->PHPExcel->getActiveSheet();```</dd>
    <dt></dt>
    <dd></dd>
    </dl>
  17. r-sal revised this gist Dec 16, 2012. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions PHPExcel_Basics.markdown
    Original file line number Diff line number Diff line change
    @@ -7,9 +7,9 @@ $this->PHPExcel = new PHPExcel();
    ### Working with sheets
    <dl>
    <dt>Creating a new sheet:</dt>
    <dd>`$this->activeSheet = $this->PHPExcel->createSheet();`</dd>
    <dd> `$this->activeSheet = $this->PHPExcel->createSheet();` </dd>
    <dt>Getting the active Sheet:</dt>
    <dd>`$this->activeSheet = $this->PHPExcel->getActiveSheet();`</dd>
    <dd> `$this->activeSheet = $this->PHPExcel->getActiveSheet();` </dd>
    <dt></dt>
    <dd></dd>
    </dl>
  18. r-sal revised this gist Dec 16, 2012. 1 changed file with 11 additions and 2 deletions.
    13 changes: 11 additions & 2 deletions PHPExcel_Basics.markdown
    Original file line number Diff line number Diff line change
    @@ -5,8 +5,17 @@ $this->PHPExcel = new PHPExcel();
    ```

    ### Working with sheets
    > Creating a new sheet: `$this->activeSheet = $this->PHPExcel->createSheet();`
    > Getting the active Sheet: `$this->activeSheet = $this->PHPExcel->getActiveSheet();`
    <dl>
    <dt>Creating a new sheet:</dt>
    <dd>`$this->activeSheet = $this->PHPExcel->createSheet();`</dd>
    <dt>Getting the active Sheet:</dt>
    <dd>`$this->activeSheet = $this->PHPExcel->getActiveSheet();`</dd>
    <dt></dt>
    <dd></dd>
    </dl>

    * Creating a new sheet: `$this->activeSheet = $this->PHPExcel->createSheet();`
    * Getting the active Sheet: `$this->activeSheet = $this->PHPExcel->getActiveSheet();`
    > Renaming a worksheet: `$this->activeSheet->setTitle($title);`
    Setting the active sheet:
  19. r-sal revised this gist Dec 16, 2012. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions PHPExcel_Basics.markdown
    Original file line number Diff line number Diff line change
    @@ -5,9 +5,9 @@ $this->PHPExcel = new PHPExcel();
    ```

    ### Working with sheets
    **Creating a new sheet:** - `$this->activeSheet = $this->PHPExcel->createSheet();`
    **Renaming a worksheet:** - `$this->activeSheet->setTitle($title);`
    **Getting the active Sheet:** - `$this->activeSheet = $this->PHPExcel->getActiveSheet();`
    > Creating a new sheet: `$this->activeSheet = $this->PHPExcel->createSheet();`
    > Getting the active Sheet: `$this->activeSheet = $this->PHPExcel->getActiveSheet();`
    > Renaming a worksheet: `$this->activeSheet->setTitle($title);`
    Setting the active sheet:
    ```
  20. r-sal revised this gist Dec 16, 2012. 1 changed file with 3 additions and 9 deletions.
    12 changes: 3 additions & 9 deletions PHPExcel_Basics.markdown
    Original file line number Diff line number Diff line change
    @@ -5,15 +5,9 @@ $this->PHPExcel = new PHPExcel();
    ```

    ### Working with sheets
    **Creating a new sheet**
    A new sheet can be added to the excel file using:
    `$this->activeSheet = $this->PHPExcel->createSheet();`
    and the sheet title can be set or renamed using:
    `$this->activeSheet->setTitle($title);`

    **Active Sheet**
    Getting the active sheet:
    `$this->activeSheet = $this->PHPExcel->getActiveSheet();`
    **Creating a new sheet:** - `$this->activeSheet = $this->PHPExcel->createSheet();`
    **Renaming a worksheet:** - `$this->activeSheet->setTitle($title);`
    **Getting the active Sheet:** - `$this->activeSheet = $this->PHPExcel->getActiveSheet();`

    Setting the active sheet:
    ```
  21. r-sal revised this gist Dec 16, 2012. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions PHPExcel_Basics.markdown
    Original file line number Diff line number Diff line change
    @@ -5,13 +5,13 @@ $this->PHPExcel = new PHPExcel();
    ```

    ### Working with sheets
    **Creating a new sheet**
    A new sheet can be added to the excel file using:
    `$this->activeSheet = $this->PHPExcel->createSheet();`
    and the sheet title can be set or renamed using:
    `$this->activeSheet->setTitle($title);`


    **Active Sheet**
    Getting the active sheet:
    `$this->activeSheet = $this->PHPExcel->getActiveSheet();`

  22. r-sal revised this gist Dec 16, 2012. 1 changed file with 17 additions and 14 deletions.
    31 changes: 17 additions & 14 deletions PHPExcel_Basics.markdown
    Original file line number Diff line number Diff line change
    @@ -4,7 +4,7 @@ Creating a new PHPExcel Object.
    $this->PHPExcel = new PHPExcel();
    ```

    ### Sheets
    ### Working with sheets

    A new sheet can be added to the excel file using:
    `$this->activeSheet = $this->PHPExcel->createSheet();`
    @@ -21,33 +21,28 @@ $sheetIndex = 2;
    $this->PHPExcel->setActiveSheetIndex($sheetIndex)
    ```



    Setting the width of a specific column.
    **Setting column width**
    Setting width for a single column:
    ```
    $this->activeSheet
    ->getColumnDimension($colString)
    ->setWidth($width);
    ```

    Setting the default column width/row height for an entire sheet.
    Setting the default width for all columns on a sheet:
    ```
    $this->activeSheet
    ->getDefaultColumnDimension()
    ->setWidth($width);
    ```
    **Setting row height**
    Setting the default row height for an entire sheet:
    ```
    $this->activeSheet
    ->getDefaultRowDimension()
    ->setRowHeight($height);
    ```

    ## Styles
    Setting default styles for the active sheet
    ```
    $this->activeSheet
    ->getDefaultStyle()
    ->applyFromArray($this->defaultStyle);
    ```


    ## Writing to cells
    Text can be added to a cell using `setCellValue($colRow, $data)`
    @@ -85,4 +80,12 @@ foreach($rows as $row => $columns) {
    $this->activeSheet->setCellValue($column.$row, $data);
    }
    }
    ```

    ## Adding styles
    Setting default styles for the active sheet
    ```
    $this->activeSheet
    ->getDefaultStyle()
    ->applyFromArray($this->defaultStyle);
    ```
  23. r-sal revised this gist Dec 16, 2012. 1 changed file with 3 additions and 2 deletions.
    5 changes: 3 additions & 2 deletions PHPExcel_Basics.markdown
    Original file line number Diff line number Diff line change
    @@ -51,8 +51,9 @@ $this->activeSheet

    ## Writing to cells
    Text can be added to a cell using `setCellValue($colRow, $data)`
    * `$colRow` - The column and row to write to (i.e. 'A2')
    * `$data` - The data to write
    `$colRow` - The column and row to write to (i.e. 'A2')
    `$data` - The data to write

    ```
    $this->activeSheet->setCellValue($colRow, $data);
    ```
  24. r-sal revised this gist Dec 16, 2012. 1 changed file with 7 additions and 3 deletions.
    10 changes: 7 additions & 3 deletions PHPExcel_Basics.markdown
    Original file line number Diff line number Diff line change
    @@ -50,10 +50,14 @@ $this->activeSheet
    ```

    ## Writing to cells
    To set the value of a cell:
    Text can be added to a cell using `setCellValue($colRow, $data)`
    * `$colRow` - The column and row to write to (i.e. 'A2')
    * `$data` - The data to write
    ```
    $this->activeSheet->setCellValue($colRow, $data);
    ```

    ```
    $this->activeSheet->setCellValue($column.$row, $data);
    $this->activeSheet->setCellValueByColumnAndRow($column, $row, $data);
    ```

  25. r-sal revised this gist Dec 16, 2012. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions PHPExcel_Basics.markdown
    Original file line number Diff line number Diff line change
    @@ -67,6 +67,7 @@ A 2-dimensional array can be written to the current sheet usng `fromArray($twoDi
    * `$twoDimArray` - the 2D array to be written
    * `$useWhenNull` - what to use if there is a null value
    * `$topLeftCorner` - where the top left corner should be.

    ```
    $this->activeSheet->fromArray($sheet);
    $this->activeSheet->fromArray($sheet, "", $colRow);
  26. r-sal revised this gist Dec 16, 2012. 1 changed file with 35 additions and 3 deletions.
    38 changes: 35 additions & 3 deletions PHPExcel_Basics.markdown
    Original file line number Diff line number Diff line change
    @@ -10,18 +10,18 @@ A new sheet can be added to the excel file using:
    `$this->activeSheet = $this->PHPExcel->createSheet();`
    and the sheet title can be set or renamed using:
    `$this->activeSheet->setTitle($title);`


    Getting the active sheet:
    `$this->activeSheet = $this->PHPExcel->getActiveSheet();'
    `$this->activeSheet = $this->PHPExcel->getActiveSheet();`

    Setting the active sheet:
    ```
    $sheetIndex = 2;
    $this->PHPExcel->setActiveSheetIndex($sheetIndex)
    ```




    Setting the width of a specific column.
    ```
    @@ -47,4 +47,36 @@ Setting default styles for the active sheet
    $this->activeSheet
    ->getDefaultStyle()
    ->applyFromArray($this->defaultStyle);
    ```

    ## Writing to cells
    To set the value of a cell:
    ```
    $this->activeSheet->setCellValue($column.$row, $data);
    $this->activeSheet->setCellValueByColumnAndRow($column, $row, $data);
    ```

    ```
    $this->activeSheet->setCellValueExplicit($coord, $value, $dataType);
    $this->activeSheet->setCellValueExplicitByColumnAndRow($col, $row, $value, $dataType);
    ```

    #### Writing from arrays
    A 2-dimensional array can be written to the current sheet usng `fromArray($twoDimArray)`
    * `$twoDimArray` - the 2D array to be written
    * `$useWhenNull` - what to use if there is a null value
    * `$topLeftCorner` - where the top left corner should be.
    ```
    $this->activeSheet->fromArray($sheet);
    $this->activeSheet->fromArray($sheet, "", $colRow);
    ```

    Or the array can be written manually by looping through the array and calling `setCellValue`
    ```
    foreach($rows as $row => $columns) {
    foreach($columns as $column => $data) {
    $this->activeSheet->setCellValue($column.$row, $data);
    }
    }
    ```
  27. r-sal revised this gist Dec 16, 2012. 1 changed file with 10 additions and 7 deletions.
    17 changes: 10 additions & 7 deletions PHPExcel_Basics.markdown
    Original file line number Diff line number Diff line change
    @@ -6,28 +6,31 @@ $this->PHPExcel = new PHPExcel();

    ### Sheets

    Creating a new sheet: `$this->activeSheet = $this->PHPExcel->createSheet();`
    Setting the title: `$this->activeSheet->setTitle($title);`
    A new sheet can be added to the excel file using:
    `$this->activeSheet = $this->PHPExcel->createSheet();`
    and the sheet title can be set or renamed using:
    `$this->activeSheet->setTitle($title);`


    **Getting/setting the active worksheet.**
    Getting the active sheet:
    `$this->activeSheet = $this->PHPExcel->getActiveSheet();'
    Setting the active sheet:
    ```
    $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.

    Setting the default column width/row height for an entire sheet.
    ```
    $this->activeSheet
    ->getDefaultColumnDimension()
  28. r-sal revised this gist Dec 16, 2012. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions PHPExcel_Basics.markdown
    Original file line number Diff line number Diff line change
    @@ -6,8 +6,8 @@ $this->PHPExcel = new PHPExcel();

    ### Sheets

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


    **Getting/setting the active worksheet.**
  29. r-sal revised this gist Dec 16, 2012. 1 changed file with 7 additions and 11 deletions.
    18 changes: 7 additions & 11 deletions PHPExcel_Basics.markdown
    Original file line number Diff line number Diff line change
    @@ -6,15 +6,9 @@ $this->PHPExcel = new PHPExcel();

    ### Sheets

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


    **Getting/setting the active worksheet.**
    ```
    @@ -45,7 +39,9 @@ $this->activeSheet
    ```

    ## Styles
    // Setting default styles for the active sheet
    Setting default styles for the active sheet
    ```
    $this->activeSheet
    ->getDefaultStyle()->applyFromArray($this->defaultStyle);
    ->getDefaultStyle()
    ->applyFromArray($this->defaultStyle);
    ```
  30. r-sal revised this gist Dec 16, 2012. 1 changed file with 17 additions and 8 deletions.
    25 changes: 17 additions & 8 deletions PHPExcel_Basics.markdown
    Original file line number Diff line number Diff line change
    @@ -3,21 +3,30 @@ Creating a new PHPExcel Object.
    ```
    $this->PHPExcel = new PHPExcel();
    ```
    Getting the active worksheet.

    ### Sheets

    **Creating a new sheet**
    ```
    $this->PHPExcel->getActiveSheet()
    $this->activeSheet = $this->PHPExcel->createSheet();
    ```
    Setting the active worksheet.
    Setting the sheet title:
    ```
    $this->PHPExcel->setActiveSheetIndex(0)
    $this->activeSheet
    ->setTitle($title);
    ```

    **Getting/setting the active worksheet.**
    ```
    $this->activeSheet = $this->PHPExcel->getActiveSheet();
    **Creating a new sheet***
    ```
    $this->activeSheet = $this->PHPExcel->createSheet();
    $this->activeSheet->setTitle($title);
    $sheetIndex = 2;
    $this->PHPExcel->setActiveSheetIndex($sheetIndex)
    ```


    ### Row/Column Functions

    Setting the width of a specific column.
    ```
    $this->activeSheet