How does Thinkphp5 store the exported excel table in the specified directory of the project directory on the server?

/ *

  • excel table export
  • @ param string $fileName file name
  • @ param array $headArr header name
  • @ param array $data data to be exported
  • @ author static7 * /

function excelExport ($fileName ="", $headArr = [], $data = []) {

$fileName .= "_" . date("Y_m_d", Request::instance()->time()) . ".xls";

$objPHPExcel = new \PHPExcel();

$objPHPExcel->getProperties();

$key = ord("A"); // 

foreach ($headArr as $v) {

    $colum = chr($key);

    $objPHPExcel->setActiveSheetIndex(0)->setCellValue($colum . "1", $v);

    $objPHPExcel->setActiveSheetIndex(0)->setCellValue($colum . "1", $v);

    $key += 1;

}

$column = 2;

$objActSheet = $objPHPExcel->getActiveSheet();

foreach ($data as $key => $rows) { // 

    $span = ord("A");

    foreach ($rows as $keyName => $value) { // 

        $objActSheet->setCellValue(chr($span) . $column, $value);

        $spanPP;

    }

    $columnPP;

}

$fileName = iconv("utf-8", "gb2312", $fileName); // 

$objPHPExcel->setActiveSheetIndex(0); // ,Excel

header("Content-Type: application/vnd.ms-excel");

header("Content-Disposition: attachment;filename="$fileName"");

header("Cache-Control: max-age=0");

$objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, "Excel5");

$objWriter->save("php://output"); // 

exit();

}
/ / this is to tell the browser to download the excel file, so how to generate the excel file to the specified directory without telling the browser to download it locally?

Jun.01,2021

has been solved. You can write the server absolute path directly at save
public function get_test ()

.
{
$file = '456.xls';
  $file_path = ROOT_PATH.'uploads/Tmp/'.$file;
$PHPExcel = new \PHPExcel();
$PHPSheet = $PHPExcel->getActiveSheet();
$PHPSheet->setTitle("demo"); //sheet
$PHPSheet->setCellValue("A1","")->setCellValue("B1","");//
$PHPSheet->setCellValue("A2","")->setCellValue("B2","2121");//
$objWriter = \PHPExcel_IOFactory::createWriter($PHPExcel, 'Excel2007');
$objWriter->save($file_path); //
}
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1bf2b97-31e33.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1bf2b97-31e33.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?