public function excelContents($data, $columnWidth)
{
$objExcel = new \PHPExcel();
$writer = new \PHPExcel_Writer_Excel2007($objExcel);
$writer->setPreCalculateFormulas(false);
$sheet = $objExcel->setActiveSheetIndex(0);
foreach ($data as $key => $v) {
$key ++;
$sheet->fromArray($v, null, 'A' . $key);
}
$sheet->getStyle("A1:AB1")
->getFont()
->setBold(true);
$sheet->getDefaultColumnDimension()->setWidth($columnWidth);
ob_start();
$writer->save('php://output');
$excelContents = ob_get_contents();
ob_end_clean();
return base64_encode($excelContents);
}
phpexcel写入数据
最新推荐文章于 2022-09-09 19:23:25 发布