PHP code example of conceptsandtraining / lib-excel-wrapper

1. Go to this page and download the library: Download conceptsandtraining/lib-excel-wrapper library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

conceptsandtraining / lib-excel-wrapper example snippets


public function addRow(array $values) {
    $this->writer->addRow($values);
}

public function setColumnStyle(Style $style, $column) {
    $this->writer->setColumnStyle($column, $style);
};

public function createSheet($name) {
    $this->writer->createSheet($name);
}

Public function selectSheet($name) {
    $this->writer->setCurrentSheet($name);
}

public function getNewStyle() {
    $style = new Style();
    $style ->setFontFamily('Aarial')
           ->setFontSize(12)
           ->setItalic(false)
           ->setBorder(Style::TOP);

    return $style;
}

public function exportData($file_name, $file_path, array $header, array $values) {
    $writer = new Writer();
    $writer->setFileName($file_name);
    $writer->setPath($file_path);

    $header_style = $this->getHeaderStyle();
    $writer->setColumnStyle('A', $header_style);
    $write->addRow($header);

    $bold_style = $this->getBoldStyle();
    $basic_style = $this->getBasicStyle();

    $writer->setColumnStyle('A', $bold_style);
    $writer->setColumnStyle('B', $basic_style);
    foreach($values as $value) {
        $write->addRow($value);
    }

    $writer->setColumnStyle('A', $basic_style);
    $writer->setColumnStyle('B', $bold_style);
    foreach($values as $value) {
        $write->addRow($value);
    }

    $writer->saveFile();
    $write->close();
}

protected function getHeaderStyle() {
    $style = new Style()
    $style->setBold(true)
          ->setItalic(true);

    return $style;
}

protected function getBoldStyle() {
    $style = new Style()
    $style->setBold(true)

    return $style;
}

protected function getBsicStyle() {
    return new Style();
}