<?
require_once '../Classes/PHPExcel.php';
require_once '../Classes/PHPExcel/IOFactory.php';
require_once '../Classes/PHPExcel/Writer/Excel2007.php';
$objPHPExcel = PHPExcel_IOFactory::load("../../ruw/myfile.xlsx");
$objPHPExcel->setActiveSheetIndex(0);
$row = $objPHPExcel->getActiveSheet()->getHighestRow()+1;
$objPHPExcel->getActiveSheet()->SetCellValue("A5",$m5);
$objPHPExcel->getActiveSheet()->SetCellValue("B5",$m1);
$objPHPExcel->getActiveSheet()->getStyle('A1:L300')->
getProtection()->setHidden(PHPExcel_Style_Protection::OTECTION_PROTECTED);
$objPHPExcel->getActiveSheet()->getProtection()->setSheet(true);
$objPHPExcel->getActiveSheet()->getProtection()->setSort(true);
$objPHPExcel->getActiveSheet()->getProtection()->setInsertRows(true);
$objPHPExcel->getActiveSheet()->getProtection()->setInsertColumns(true);
$objPHPExcel->getActiveSheet()->getProtection()->setFormatCells(true);
$objPHPExcel->getActiveSheet()->getProtection()->setFormatColumns(true);
$objPHPExcel->getActiveSheet()->getProtection()->setDeleteColumns(true);
$objPHPExcel->getActiveSheet()->getProtection()->setDeleteRows(true);
$objPHPExcel->getActiveSheet()->getProtection()->setSelectLockedCells(true);
$objPHPExcel->getActiveSheet()->getProtection()->setPassword($passy);
$objDrawing->setWorksheet($objPHPExcel->getActiveSheet());
$objWriter = new PHPExcel_Writer_Excel2007($objPHPExcel);
$d =$m1;
$d = preg_replace('/[^a-zA-Z0-9%$#@*&^-_()]/','',$m1);
$fil = "../../ruw/".$d.".xlsx";
$objWriter->save($fil);
echo "<label style='font:Verdana, Geneva, sans-serif; font-size:20px; color:#CE0000'>
File download start automatically if not click here to </label> ";
echo "<a style='font:Verdana, Geneva, sans-serif; color:#000; font-weight:bold;' href='$fil'>Download</a> ";
echo "<script type='text/javascript'>" ;
echo "reply_click(".$_SESSION['mid'].",'$fil')";
echo "</script>";
?>
此代码可以正常写入“.xlsx”但不能写入“.xls”
如果我尝试编写并打开.xls,我将获得不同的格式,不可读的内容和xml解析错误
我想写.xls 97-2003并将其保存为.xls 97-2003格式
提前致谢
答案 0 :(得分:4)
您使用了错误的Writer
实例,需要将PHPExcel_Writer_Excel2007
更改为PHPExcel_Writer_Excel5()
$objWriter = new PHPExcel_Writer_Excel5($objPHPExcel);
$objWriter->save("myfile.xls");
注意:您需要相应地更新包含路径。