|
 |
|
PHPExcel addsheets แล้ว write ใน sheets อื่นยังไงอะครับ |
|
 |
|
|
 |
 |
|
Code (PHP)
$objPHPExcel = new PHPExcel();
$objPHPExcelAll = new PHPExcel();
$strPath = realpath(basename(getenv($_SERVER["SCRIPT_NAME"])));
$count_info3 = $db->count_info("3"); // คิวรี่ นัมโรว มาจาก db
// อันที่เขียนลง sheets หลัก โดยการ get data งานทั้งหมดมาสรุปรวมในชีทนี้ + โคลนชีท
$objPHPExcelAll->setActiveSheetIndex(0);
$newSheet = clone $objPHPExcelAll->getActiveSheet();
$row = 2;
$dirs = array_filter(glob('project_data/26-04-60/*'), 'is_dir');
$dirCount = count($dirs);
for($r = 0; $r < $dirCount; $r++){
$folderName = substr($dirs[$r], strrpos($dirs[$r], "/") + 1);
$data = $db->get_data(3, "26-04-60", $folderName);
$c = 1;
$column = 'A';
while($c <= $count_info3){
$objPHPExcelAll->getActiveSheet()->setCellValue($column . $row, $data[$c - 1]);
$c++;
$column++;
}
$row++;
}
// โคลนเสดละ ทีนี้ addsheets
$newSheet->setTitle('Sheets2');
$objPHPExcelAll->addSheet($newSheet);
// จบด้วย save file ครับ
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcelAll, 'Excel2007');
$strFileName = $directoryAll."3.0.xlsx";
$objWriter->save($strPath."/".$strFileName);
$db->reset_template($count_info3,$objPHPExcel);
เลยสงสัยว่า จะเขียนลงไปใน sheets2 ยังไงอะครับ ลูป data ก็ไม่เข้า เขียนตรงๆก็ไม่เข้า มันมาเข้าใน sheets หลักหมดเลย
Tag : PHP, MySQL, Excel (Excel.Application), Share Hosting, Bootstrap Framework, Windows

|
ประวัติการแก้ไข 2017-08-25 11:15:39
|
 |
 |
 |
 |
Date :
2017-08-25 10:58:13 |
By :
1676148892398444 |
View :
2595 |
Reply :
3 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
set active sheet ใหม่ ก่อน write ชีทใหม่
$objPHPExcelAll->setActiveSheetIndex(1);
|
 |
 |
 |
 |
Date :
2017-08-25 11:20:22 |
By :
Chaidhanan |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ทำเป็นตัวอย่าง
Book1.xlsx Sheet1:cell(A1)='TEST' สร้างเอาหน่อย ลองเอาเอง จะได้เห็น
Code (PHP)
<?php
$nfile='CloneAdd.xlsx';
if(is_file($nfile)) unlink($nfile);
require_once 'ClassExcel/PHPExcel.php';
include 'ClassExcel/PHPExcel/IOFactory.php';
$inputFileName = 'Book1.xlsx';
$inputFileType = PHPExcel_IOFactory::identify($inputFileName);
$Reader = PHPExcel_IOFactory::createReader($inputFileType);
$SheetS = $Reader->load($inputFileName);
$SheetS->setActiveSheetIndex(0);
$newSheet = clone $SheetS->getActiveSheet();
$newSheet->setTitle('Test2');
$SheetS->addSheet($newSheet);
///
// จะทำอะไรกับชีทใหม่ก็ใส่ตรงนี้
$newSheet->SetCellValue('B1', 'add new');
///
$Write = PHPExcel_IOFactory::createWriter($SheetS, 'Excel2007');
$Write->save($nfile);
|
 |
 |
 |
 |
Date :
2017-08-25 13:40:47 |
By :
Chaidhanan |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 01
|