第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

PHPExcel如何在每周例行程序中自動創(chuàng)建新的excel文件?

PHPExcel如何在每周例行程序中自動創(chuàng)建新的excel文件?

PHP
米脂 2022-10-28 14:21:15
在我的站點(diǎn)中,用戶填寫數(shù)據(jù)時有一個表格,數(shù)據(jù)將寫入一個 .xls 文件并存儲在我的電腦中。但是,所有數(shù)據(jù)都存儲在一個 .xls 文件下,該文件最終會變得非常長且不整潔。我想讓我的系統(tǒng)每周生成一個新的 .xls 文件,以便可以按周存儲數(shù)據(jù)。這是我當(dāng)前的代碼,我想知道有沒有辦法讓它發(fā)生?謝謝你!$objPHPExcel = PHPExcel_IOFactory::load("hii.xls");$objPHPExcel->setActiveSheetIndex(0);   $objPHPExcel->getActiveSheet()->setCellValue('A1','Name of Stakeholder(s)');      $objPHPExcel->getActiveSheet()->setCellValue('B1','NRIC No./Passport No./Company No.');      $objPHPExcel->getActiveSheet()->setCellValue('C1','Email');      $objPHPExcel->getActiveSheet()->setCellValue('D1','Contact Number');      $objPHPExcel->getActiveSheet()->setCellValue('E1','CDS Account No.');      $objPHPExcel->getActiveSheet()->setCellValue('F1','Correspondence Address');      $objPHPExcel->getActiveSheet()->setCellValue('G1','Date Submitted');$row = $objPHPExcel->getActiveSheet()->getHighestRow()+1;$objPHPExcel->getActiveSheet()->SetCellValue('A'.$row, $_POST['name']);$objPHPExcel->getActiveSheet()->SetCellValue('B'.$row, $_POST['ic']);$objPHPExcel->getActiveSheet()->SetCellValue('C'.$row, $_POST['email']);$objPHPExcel->getActiveSheet()->SetCellValue('D'.$row, $_POST['phone']);$objPHPExcel->getActiveSheet()->SetCellValue('E'.$row, $_POST['cds']);$objPHPExcel->getActiveSheet()->SetCellValue('F'.$row, $_POST['address']);$objPHPExcel->getActiveSheet()->SetCellValue('G'.$row, $_POST['date']);$objWriter = new PHPExcel_Writer_Excel2007($objPHPExcel);      $from = "A1";      $to = "G1";$objPHPExcel->getActiveSheet()->getStyle("$from:$to")->getFont()->setBold(true);$objWriter->save('hii.xls'); 
查看完整描述

1 回答

?
白衣非少年

TA貢獻(xiàn)1155條經(jīng)驗(yàn) 獲得超0個贊

您可以使用它存檔DateTime()以確定一年中的當(dāng)前周。


這應(yīng)該如下所示。


// Get the current week of year

$date = new DateTime('now');

$week = $date->format("W");


// Path to the file storage (in this case the same folder as this script)

$path = __DIR__;


// Set file name for excel file and combine with the path

$file = $path . '/week-' . $week . '.xls';


// Determine if file exists

if (!is_file($file)) {

    // File doesn't exists, so we create a new file

    $objPHPExcel = new PHPExcel();

} else {

    // File exists, so we load this file

    $objPHPExcel = PHPExcel_IOFactory::load($file);

}


// Your existing code to write the data

$objPHPExcel->setActiveSheetIndex(0);

$objPHPExcel->getActiveSheet()->setCellValue('A1','Name of Stakeholder(s)');

$objPHPExcel->getActiveSheet()->setCellValue('B1','NRIC No./Passport No./Company No.');

$objPHPExcel->getActiveSheet()->setCellValue('C1','Email');

$objPHPExcel->getActiveSheet()->setCellValue('D1','Contact Number');

$objPHPExcel->getActiveSheet()->setCellValue('E1','CDS Account No.');

$objPHPExcel->getActiveSheet()->setCellValue('F1','Correspondence Address');

$objPHPExcel->getActiveSheet()->setCellValue('G1','Date Submitted');


$row = $objPHPExcel->getActiveSheet()->getHighestRow()+1;

$objPHPExcel->getActiveSheet()->SetCellValue('A'.$row, $_POST['name']);

$objPHPExcel->getActiveSheet()->SetCellValue('B'.$row, $_POST['ic']);

$objPHPExcel->getActiveSheet()->SetCellValue('C'.$row, $_POST['email']);

$objPHPExcel->getActiveSheet()->SetCellValue('D'.$row, $_POST['phone']);

$objPHPExcel->getActiveSheet()->SetCellValue('E'.$row, $_POST['cds']);

$objPHPExcel->getActiveSheet()->SetCellValue('F'.$row, $_POST['address']);

$objPHPExcel->getActiveSheet()->SetCellValue('G'.$row, $_POST['date']);

$objWriter = new PHPExcel_Writer_Excel2007($objPHPExcel);

$from = "A1";

$to = "G1";

$objPHPExcel->getActiveSheet()->getStyle("$from:$to")->getFont()->setBold(true);


// Save the excel file

$objWriter->save($file);


查看完整回答
反對 回復(fù) 2022-10-28
  • 1 回答
  • 0 關(guān)注
  • 131 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號