I want to open a xlsx
file with PHP using application/vnd.openxmlformats- officedocument.spreadsheetml.sheet
because COM does not work on the server.
Does someone know how to do this?
The commented section is the one I want to replace. I am doing this to force excel to calculate the values in the formulas because phpexcel is not getting the correct values.
If there a way to configure the COM to run in the server please let me know.
This is my code:
$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();