我想xlsx
用 PHP 打开一个文件,application/vnd.openxmlformats- officedocument.spreadsheetml.sheet
因为 COM 在服务器上不起作用。
有人知道该怎么做吗?
评论部分是我要替换的部分。我这样做是为了强制 excel 计算公式中的值,因为 phpexcel 没有得到正确的值。
如果有办法配置 COM 在服务器中运行,请告诉我。
这是我的代码:
$inputFileName = 'FORMATO PEDIDO.xlsx';
$inputFileType = PHPExcel_IOFactory::identify($inputFileName);
$objPHPexcel = PHPExcel_IOFactory::load($inputFileName);
$objWorksheet = $objPHPexcel->setActiveSheetIndex(0);
$objWorksheet = $objPHPexcel->getActiveSheet();
$claves = $_POST['claves'];
$checked = $_POST['productos'];
$cantidades = $_POST['pallet'];
$id_sucursal_seleccionada = $_POST['recibe_sucursal'];
$sql_query = mysql_query("SELECT * FROM sucursal WHERE Id_Sucursal = '$id_sucursal_seleccionada'");
$sql_array = mysql_fetch_array($sql_query);
$nombre_sucursal = $sql_array['Nombre'];
$i=0;
$j=22;
foreach($claves as $clave_producto)
{
if($checked[$i])
{
$cantidad = $cantidades[$i];
$objWorksheet->getCell('B'.$j)->setValue($clave_producto);
$objWorksheet->getCell('F'.$j)->setValue($cantidad);
$j++;
}
$i++;
}
$objWriter = PHPExcel_IOFactory::createWriter($objPHPexcel,$inputFileType);
$objWriter->setPreCalculateFormulas(false);
$objWriter->save($inputFileName);
$workbook = "C:/Documents and Settings/sosam1/My Documents/Dropbox/htdocs/Merdiz/inventarios/FORMATO PEDIDO.xlsx";
$ex = new COM("Excel.application") or Die ("Did not connect");
$wkb = $ex->application->Workbooks->Open($workbook) or Die ("Did not open");
$ex->Application->ActiveWorkbook->Save();
$ex->application->ActiveWorkbook->Close("False");
$objPHPexcel = PHPExcel_IOFactory::load($inputFileName);
$objWorksheet = $objPHPexcel->setActiveSheetIndex(0);
$objWorksheet = $objPHPexcel->getActiveSheet();