在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
ob_end_clean(); $filePath = './123.xls'; //$filePath = './123.docx'; $savePath = './123.html'; //这里记得将文件名包含进去 //excel 转html 单个Sheet $fileType = \PHPExcel_IOFactory::identify($filePath); //文件名自动判断文件类型 $objReader = \PHPExcel_IOFactory::createReader($fileType); $objPHPExcel = $objReader->load($filePath); $objWriter = new \PHPExcel_Writer_HTML($objPHPExcel); $objPHPExcel = $objReader->load($filePath); $sheetIndex = $objPHPExcel->getSheetCount(); //dump($sheetIndex);exit; $objWriter->setSheetIndex(0); //可以将括号中的0换成需要操作的sheet索引 //$objWriter->save($savePath); //保存为html文件 $objWriter->save('php://output'); //excel 转html 多个Sheet /*$a = \PhpOffice\PhpSpreadsheet\IOFactory::load($filePath); $writer = new \PhpOffice\PhpSpreadsheet\Writer\Html($a); $writer->writeAllSheets(); $hdr = $writer->generateHTMLHeader(); $sty = $writer->generateStyles(false); // do not write <style> and </style> $newstyle = '<style type="text/css">'.$sty.'</style>'; echo preg_replace('@</head>@', "$newstyle\n</head>", $hdr); echo $writer->generateHTMLAll(); $writer->save('php://output');*/ /*word docx 转HTML输出 $objReader = \PhpOffice\PhpWord\IOFactory::createReader(); $objPHPFile = $objReader->load($filePath); $objPHPFile->setDefaultFontName('Times New Roman'); $objPHPFile->setDefaultFontSize(16); $objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($objPHPFile, 'HTML'); $html = $objWriter->getContent(); //取head标签内容 preg_match("/<head>(.*)<\/head>/si",$html,$match); $head = trim($match[0]); $count = strpos($head,"</head>"); $str = substr_replace($head,"",$count,strlen('</head>')); $str2 = $str.'<style>img{display: block;margin: 20px auto;}</style></head>'; $strer = preg_replace("/<head>(.*)<\/head>/si",$str2,$html); return $strer; //$objWriter->save('php://output');*/
|
2022-07-18
2022-08-16
2022-11-06
2022-08-18
2022-08-15
请发表评论