add simple xls
This commit is contained in:
@@ -0,0 +1,110 @@
|
||||
<?php
|
||||
|
||||
/*******************************************************************
|
||||
|
||||
Module : /Data/SimpleXLS.php
|
||||
Desc. : v3 - Class pembuatan file Simple XLS
|
||||
Created By : Siau Pheng ([email protected]).
|
||||
Created Date : November 18th, 2012.
|
||||
Last Modified : November 17th, 2023.
|
||||
|
||||
(c) 2012 - 2023, 3FONIA Software; WWW.3FONIA.COM.
|
||||
|
||||
*******************************************************************/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace siaupheng\fonia3\Data;
|
||||
|
||||
final class SimpleXLS {
|
||||
private $__tnamafile = null;
|
||||
private $__wbook = null;
|
||||
private $__atabel = [];
|
||||
private $__aheader = [];
|
||||
private $__avalue = [];
|
||||
|
||||
public function __construct($tnama_file="", $oprop=[]) {
|
||||
$this->__tnamafile = $tnama_file;
|
||||
$this->__wbook = new \Shuchkin\SimpleXLSXGen();
|
||||
$this->__wbook
|
||||
->setAuthor($_SESSION['__WEB_APP']['APP_NAME']." v".$_SESSION['__WEB_APP']['APP_VER'])
|
||||
->setLastModifiedBy($_SESSION['__WEB_APP']['APP_NAME']." v".$_SESSION['__WEB_APP']['APP_VER'])
|
||||
->setTitle($oprop['title'] ?? "")
|
||||
->setSubject($oprop['subject'] ?? "")
|
||||
->setDescription($oprop['desc'] ?? "")
|
||||
->setCompany($_SESSION['__WEB_APP']['REG_NAME']);
|
||||
}
|
||||
|
||||
public function clear_field() {
|
||||
$this->__atabel = [];
|
||||
}
|
||||
|
||||
public function add_header($tjudul="") {
|
||||
if ($tjudul=="") return;
|
||||
$this->__aheader[] = $tjudul;
|
||||
}
|
||||
|
||||
public function add_empty_row($nrow=1) {
|
||||
$_jkolom = count($this->__atabel);
|
||||
for ($i=0; $i<$nrow; $i++) {
|
||||
$this->__avalue[] = array_values(array_fill(0,$_jkolom,""));
|
||||
}
|
||||
}
|
||||
|
||||
public function add_field($tnama="", $nlebar=0, $ffunc="") {
|
||||
$this->__atabel[] = [$tnama, $nlebar, $ffunc];
|
||||
}
|
||||
|
||||
public function add_sheet($tnama_sheet="BARU", $bw_header=true) {
|
||||
for ($i=0; $i<count($this->__atabel); $i++) {
|
||||
$this->__wbook->setColWidth($this->__kolom, $this->__atabel[$i][1]);
|
||||
}
|
||||
$_jkolom = count($this->__atabel);
|
||||
if ($_jkolom>0) $_jkolom--;
|
||||
foreach ($this->__aheader as $_key => $_val) {
|
||||
$this->__avalue[] = array_values(array_merge(["<b>".$_val."</b>"],array_fill(1,$_jkolom,null)));
|
||||
}
|
||||
if ($bw_header==true) $this->show_headers();
|
||||
}
|
||||
|
||||
public function add_value() {
|
||||
$tmp_arr = func_get_args();
|
||||
if (is_array($tmp_arr[0])) $tmp_arr = $tmp_arr[0];
|
||||
$a_out = [];
|
||||
for ($i=0; $i<count($this->__atabel); $i++) {
|
||||
$tmp_val = $tmp_arr[$i];
|
||||
if (is_array($this->__atabel[$i][2]) && trim($tmp_val)<>"") {
|
||||
$tmp_val = $this->__atabel[$i][2][$tmp_val];
|
||||
} else if (function_exists($this->__atabel[$i][2]) && trim($tmp_val)<>"") {
|
||||
$tmp_val = call_user_func($this->__atabel[$i][2], $tmp_val);
|
||||
}
|
||||
$a_out[] = $tmp_val;
|
||||
}
|
||||
$this->__avalue[] = $a_out;
|
||||
}
|
||||
|
||||
public function add_stamp($ctk_ke=1, $bnama=false) {
|
||||
$_jkolom = count($this->__atabel);
|
||||
if ($_jkolom>0) $_jkolom--;
|
||||
$this->__avalue[] = array_values(array_merge(["<i>".$_SESSION['__WEB_APP']['APP_NAME']."v".$_SESSION['__WEB_APP']['APP_VER'].date("\@ymd.His")."-".user_id(3).(($bnama==true)?"/".strtoupper(user_user()):"").(($ctk_ke>0)?"#".isi_nol($ctk_ke,2):"")."</i>"],array_fill(1,$_jkolom,null)));
|
||||
}
|
||||
|
||||
public function get_stamp($ctk_ke=1, $bnama=false) {
|
||||
return $_SESSION['__WEB_APP']['APP_NAME']."v".$_SESSION['__WEB_APP']['APP_VER'].date("\@ymd.His")."-".user_id(3).(($bnama==true)?"/".strtoupper(user_user()):"").(($ctk_ke>0)?"#".isi_nol($ctk_ke,2):"");
|
||||
}
|
||||
|
||||
public function show_headers() {
|
||||
$a_out = [];
|
||||
for ($i=0; $i<count($this->__atabel); $i++) {
|
||||
$a_out[] = '<style bgcolor="#D0D0D0">'.$this->__atabel[$i][0].'</style>';
|
||||
}
|
||||
$this->__avalue[] = $a_out;
|
||||
}
|
||||
|
||||
public function send($tnama_file="File_Excel") {
|
||||
$this->__wbook->fromArray($this->__avalue)->downloadAs($tnama_file);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
+13
-10
@@ -17,9 +17,7 @@ declare(strict_types=1);
|
||||
namespace siaupheng\fonia3\Data;
|
||||
|
||||
use PhpOffice\PhpSpreadsheet\IOFactory;
|
||||
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||||
//use PhpOffice\PhpSpreadsheet\Worksheet\Table as TableXLS;
|
||||
//use PhpOffice\PhpSpreadsheet\Worksheet\Table\TableStyle;
|
||||
|
||||
|
||||
final class XLS {
|
||||
private $__tnamafile = null;
|
||||
@@ -32,11 +30,12 @@ final class XLS {
|
||||
private $__astyle =[];
|
||||
private $__aheader = [];
|
||||
private $__fhead = null;
|
||||
private $__isheet = 0;
|
||||
|
||||
public function __construct($tnama_file="", $oprop=[]) {//oke
|
||||
\PhpOffice\PhpSpreadsheet\Cell\Cell::setValueBinder( new \PhpOffice\PhpSpreadsheet\Cell\AdvancedValueBinder() );
|
||||
$this->__tnamafile = $tnama_file;
|
||||
$this->__wbook = new Spreadsheet();
|
||||
$this->__wbook = new \PhpOffice\PhpSpreadsheet\Spreadsheet();
|
||||
$this->__wbook->getProperties()
|
||||
->setCreator($_SESSION['__WEB_APP']['APP_NAME']." v".$_SESSION['__WEB_APP']['APP_VER'])
|
||||
->setLastModifiedBy($_SESSION['__WEB_APP']['APP_NAME']." v".$_SESSION['__WEB_APP']['APP_VER'])
|
||||
@@ -72,7 +71,6 @@ final class XLS {
|
||||
$_tmp_style = $this->__fhead;
|
||||
}
|
||||
}
|
||||
//if ($_bline==true) $_tmp_style->setBottom(1);
|
||||
return $_tmp_style;
|
||||
}
|
||||
|
||||
@@ -88,24 +86,29 @@ final class XLS {
|
||||
|
||||
public function set_garis_bawah($bgaris=true) {}//todo: deleted
|
||||
|
||||
public function add_header($tjudul="") {
|
||||
public function add_header($tjudul="") {//oke
|
||||
if ($tjudul=="") return;
|
||||
$this->__aheader[] = $tjudul;
|
||||
}
|
||||
|
||||
public function add_empty_row($nrow=1) {
|
||||
public function add_empty_row($nrow=1) {//oke
|
||||
$this->__baris += $nrow;
|
||||
}
|
||||
|
||||
public function add_field($tnama="", $nlebar=0, $talign="L", $ffunc="") {
|
||||
public function add_field($tnama="", $nlebar=0, $talign="L", $ffunc="") {//oke
|
||||
$this->__atabel[] = [$tnama, $nlebar, $ffunc];
|
||||
$this->__astyle[] = $this->create_style($talign);
|
||||
}
|
||||
|
||||
public function add_sheet($tnama_sheet="BARU", $bw_header=true) {//not yet !!!
|
||||
$this->__wsheet = $this->__wbook->addWorksheet($tnama_sheet);
|
||||
if ($this->__isheet > 0) {
|
||||
$this->__wbook->createSheet();
|
||||
$this->__wsheet = $this->__wbook->setActiveSheetIndex(++$this->__isheet);
|
||||
}
|
||||
$this->__wsheet->setTitle($tnama_sheet);
|
||||
for ($i=0; $i<count($this->__atabel); $i++) {
|
||||
$this->__wsheet->setColumn($this->__kolom+$i,$this->__kolom+$i,$this->__atabel[$i][1]);
|
||||
//sampai disini dulu !!
|
||||
$this->__wsheet->getColumnDimension($this->__kolom+$i)->setWidth($this->__atabel[$i][1]);
|
||||
}
|
||||
$_fjudul = $this->__wbook->addFormat();
|
||||
$_fjudul->setBold();
|
||||
|
||||
Reference in New Issue
Block a user