dr6673999 2016-04-13 11:55
浏览 261

PHPExcel xls文件读取和HTML显示

I'm losing time as hell using this PHPExcel lib. My code is widely inspired from models which are available in the lib.

+The mission is :

-To read an *.xls file with PHP

-Display it in a navigator in HTML

For the moment, I just can read the file successfully (with a "createReader" method of PHPExcel_IOFactory instance). But for the HTML display, I'm in a pretty good crap. At attempt of code correction gives me this error:

" Fatal error: Uncaught exception 'PHPExcel_Calculation_Exception' with message 'Réalisé S03!P374 -> Réalisé S03!P374 -> Formula Error: Unexpected ,' "

Here is the code :

<?phperror_reporting(E_ALL);
set_time_limit(0);
date_default_timezone_set('Europe/London');
/** Include path **/
set_include_path(get_include_path() . PATH_SEPARATOR . '../../../Classes/');

/** PHPExcel_IOFactory */
include 'PHPExcel/IOFactory.php';

?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

<title>PHPExcel Reader Example #02</title>

</head>
<body>

<h1>Chargement fichier Facturation</h1>

<?php

$inputFileName = '../Docs_PDC/FACTURATION_Janvier.xls';

echo 'Loading file ',pathinfo($inputFileName,PATHINFO_BASENAME),' using PHPExcel_Reader_Excel5<br />';
$objReader = new PHPExcel_Reader_Excel5();
//  $objReader = new PHPExcel_Reader_Excel2007();
//  $objReader = new PHPExcel_Reader_Excel2003XML();
//  $objReader = new PHPExcel_Reader_OOCalc();
//  $objReader = new PHPExcel_Reader_SYLK();
//  $objReader = new PHPExcel_Reader_Gnumeric();
//  $objReader = new PHPExcel_Reader_CSV();
$objPHPExcel = $objReader->load($inputFileName);
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'HTML'); 
$objWriter->save('Facturation.html'); 


echo '<hr />';

$sheetData = $objPHPExcel->getActiveSheet()->toArray(null,true,true,true);
var_dump($sheetData);

$filename = "DownloadReport";
$table    = $_POST['table'];

// save $table inside temporary file that will be deleted later
$tmpfile = tempnam(sys_get_temp_dir(), 'html');
file_put_contents($tmpfile, $table);

// insert $table into $objPHPExcel's Active Sheet through $excelHTMLReader
$objPHPExcel     = new PHPExcel();
$excelHTMLReader = PHPExcel_IOFactory::createReader('HTML');
$excelHTMLReader->loadIntoExisting($tmpfile, $objPHPExcel);
$objPHPExcel->getActiveSheet()->setTitle('Facturation'); // Change sheet's     title if you want

unlink($tmpfile); // delete temporary file because it isn't needed anymore

header('Content-Type: application/vnd.openxmlformats-   officedocument.spreadsheetml.sheet'); // header for .xlxs file
header('Content-Disposition: attachment;filename='.$filename); // specify  the download file name

exit;


?>
<body>

If someone has any idea I'll eternally grateful to him (or her ;) )

I dug a little more on this, and i noticed that: the exception is raised because PHPExcel tries to resolve a formula with an Excel reference value (like "P$7") in argument. And the referenced value is not a number, it's just a column name. So, Is it possible to disable PHPExcel's formula solving in some fields ? Or is there any other way to get around this ?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
    • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
    • ¥20 有关区间dp的问题求解
    • ¥15 多电路系统共用电源的串扰问题
    • ¥15 slam rangenet++配置
    • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
    • ¥15 ubuntu子系统密码忘记
    • ¥15 保护模式-系统加载-段寄存器
    • ¥15 电脑桌面设定一个区域禁止鼠标操作
    • ¥15 求NPF226060磁芯的详细资料