 |
|
พอดีผมเขียนในส่วนของการออกรายงานครับ
พอผมออกรายงานและเปปิดไฟล์ ได้รุปแบบแนี้ครับ

แต่ผมต้องการประมาณนี้

ต้องปรับโค๊ดยังไหงครับจากที่มีอยู่ตอนนี้
Code (PHP)
public function report()
{
// LOAD SESSION DATA
$session_data = $this->session->userdata('userLogData');
$session_search = $this->session->userdata('searchData');
$key = array($session_search['category_id'],$session_search['sub_category_id'],$session_search['keyword']);
// LOAD DATA
$assetObj = $this->productModel->getAssetReportList($key);
$this->myexcel->setActiveSheetIndex(0);
// HEADER
$this->myexcel->getActiveSheet()->setCellValue('A1', 'ลำดับ');
$this->myexcel->getActiveSheet()->setCellValue('B1', 'หมวด');
$this->myexcel->getActiveSheet()->setCellValue('C1', 'ประเภทหลัก');
$this->myexcel->getActiveSheet()->setCellValue('D1', 'ประเภทย่อย');
$this->myexcel->getActiveSheet()->setCellValue('E1', 'รายละเอียด');
$this->myexcel->getActiveSheet()->setCellValue('F1', 'รหัสครุภัณฑ์');
$this->myexcel->getActiveSheet()->setCellValue('G1', 'ราคา');
$this->myexcel->getActiveSheet()->setCellValue('H1', 'วันที่จัดซื้อ');
$this->myexcel->getActiveSheet()->setCellValue('I1', 'วันที่เริ่มประกัน');
$this->myexcel->getActiveSheet()->setCellValue('J1', 'วันที่หมดประกัน');
$this->myexcel->getActiveSheet()->setCellValue('K1', 'ผู้รับผิดชอบ');
$this->myexcel->getActiveSheet()->setCellValue('L1', 'แผนกที่รับผิดชอบ');
$this->myexcel->getActiveSheet()->setCellValue('M1', 'สถานที่จัดเก็บ');
$this->myexcel->getActiveSheet()->setCellValue('N1', 'สถานะ');
$this->myexcel->getActiveSheet()->setCellValue('O1', 'หมายเหตุ');
// SET COLUMN WIDTH
$this->myexcel->getActiveSheet()->getColumnDimension('A')->setWidth(10);
$this->myexcel->getActiveSheet()->getColumnDimension('B')->setWidth(15);
$this->myexcel->getActiveSheet()->getColumnDimension('C')->setWidth(20);
$this->myexcel->getActiveSheet()->getColumnDimension('D')->setWidth(20);
$this->myexcel->getActiveSheet()->getColumnDimension('E')->setAutoSize(true);
$this->myexcel->getActiveSheet()->getColumnDimension('F')->setWidth(20);
$this->myexcel->getActiveSheet()->getColumnDimension('G')->setWidth(20);
$this->myexcel->getActiveSheet()->getColumnDimension('H')->setWidth(20);
$this->myexcel->getActiveSheet()->getColumnDimension('I')->setWidth(20);
$this->myexcel->getActiveSheet()->getColumnDimension('J')->setWidth(20);
$this->myexcel->getActiveSheet()->getColumnDimension('K')->setWidth(20);
$this->myexcel->getActiveSheet()->getColumnDimension('L')->setWidth(20);
$this->myexcel->getActiveSheet()->getColumnDimension('M')->setWidth(20);
$this->myexcel->getActiveSheet()->getColumnDimension('N')->setWidth(20);
$this->myexcel->getActiveSheet()->getColumnDimension('O')->setAutoSize(true);
// SET ALIGNMENT
$this->myexcel->getActiveSheet()->getStyle('A1:O1')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$i = 2;
foreach ($assetObj as $assetList) {
// CONFIG SOLD DATE
$txtSoldDate = $assetList->soldDate > '0000-00-00 00:00:00'?$this->mydatesystem->thaiDate($assetList->soldDate, 1):'';
// CONFIG WARRNTY DATE
$txtStartDate = $assetList->startDate > '0000-00-00'?$this->mydatesystem->thaiDate($assetList->startDate, 1):'';
$txtEndDate = $assetList->endDate > '0000-00-00'?$this->mydatesystem->thaiDate($assetList->endDate, 1):'';
$value = !empty($assetList->value)?$assetList->value:0;
$this->myexcel->getActiveSheet()->setCellValue('A' . $i, $assetList->asset_id);
$this->myexcel->getActiveSheet()->setCellValue('B' . $i, $assetList->catType);
$this->myexcel->getActiveSheet()->setCellValue('C' . $i, $assetList->catName);
$this->myexcel->getActiveSheet()->setCellValue('D' . $i, $assetList->subTypeName);
$this->myexcel->getActiveSheet()->setCellValue('E' . $i, $assetList->detail);
$this->myexcel->getActiveSheet()->setCellValue('F' . $i, $assetList->code);
$this->myexcel->getActiveSheet()->setCellValue('G' . $i, number_format($value, 2));
$this->myexcel->getActiveSheet()->setCellValue('H' . $i, $txtSoldDate);
$this->myexcel->getActiveSheet()->setCellValue('I' . $i, $txtStartDate);
$this->myexcel->getActiveSheet()->setCellValue('J' . $i, $txtEndDate);
$this->myexcel->getActiveSheet()->setCellValue('K' . $i, $assetList->owner);
$this->myexcel->getActiveSheet()->setCellValue('L' . $i, $assetList->depName);
$this->myexcel->getActiveSheet()->setCellValue('M' . $i, $assetList->location);
$this->myexcel->getActiveSheet()->setCellValue('N' . $i, $assetList->statName);
$this->myexcel->getActiveSheet()->setCellValue('O' . $i, $assetList->remark);
$this->myexcel->getActiveSheet()->getStyle('A'.$i.':C'.$i)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$this->myexcel->getActiveSheet()->getStyle('D'.$i.':O'.$i)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$i++;
}
// RENAME WORKSHEET
$this->myexcel->getActiveSheet()->setTitle('dpAssetReport');
// Redirect output to a client’s web browser (Excel2007)
$filename = date('YmdHis').rand(000000, 999999);
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="'.$filename.'.xls"');
header('Cache-Control: max-age=0');
$objWriter = PHPExcel_IOFactory::createWriter($this->myexcel, 'Excel5');
$objWriter->save('php://output');
exit;
}
// ==================================================================
// AJAX FUNCTION TO LOAD DYNAMIC DATA TO PAGE
// ==================================================================
ขอบคุณครับ
อย่างเช่นส่วนหัวจะใส่ยังไหงครับ

Tag : PHP, MySQL, Excel (Excel.Application), Report Others, Laravel Framework
|
ประวัติการแก้ไข 2019-09-01 08:21:03
|
 |
 |
 |
 |
Date :
2019-09-01 08:18:30 |
By :
685799958284179 |
View :
1197 |
Reply :
2 |
|
 |
 |
 |
 |
|
|
|
 |