我正在处理一个处理Excel的复杂程序,所以我使用PHPExcel从浏览器中搜索和编辑Excel文件。我的问题出现在程序的编辑部分,所以我编写了一个基本程序来编辑现有的Excel页面。看来PHPExcel不能将在Excel中创建的文件识别为Excel文件。这是在我自己的服务器上用我用Excel创建的Excel页面完成的。文件名是062014.xlsx。在HTML端我命名文本框C3,D3和E3,所以它们的名字很容易与Excel单元格(php $ cell变量来自哪里)对应。我想要做的是在HTML文本框中取文本,并用HTML文本框中的数据重写Excel中的相应单元格。发布是我的整个代码从HTML和PHP,如果有人可以告诉我在哪里我的程序出错了,我将不胜感激。'文件名062014.xlsx不被识别为OLE文件'
<html>
<head>
<form method="POST" action="lilrevisetest.php" id="excelform">
<input type="text" value="foo" name="C3" />
<input type="text" value="foo" name="D3" />
<input type="text" value="foo" name="E3" />
<button type="submit">Submit</button>
</form>
</body>
</html>
<body>
<html>
<?php
include 'PHPExcel/IOFactory.php';
$n=1;
$x="C";
$y=1;
$file = "062014.xlsx";
$inputFileType = PHPExcel_IOFactory::identify($file);
$inputFileType = 'Excel5';
$objReader = PHPExcel_IOFactory::createReader($inputFileType);
$objReader->setReadDataOnly(false);
$objPHPExcel = $objReader->load($file);
$objWorksheet = $objPHPExcel->getActiveSheet();
$fileObj = fopen("$file", "rt");
$y = 3;
$x= "C";
for($n=1; $n<4; $n++){
$cell = $x . $y;
echo $cell;
if (isset($_POST[$cell])){
$string = ($_POST[$cell]);
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, $inputFileType);
$objWorksheet ->setCellValue("$cell","$string");
$objWriter->save($file);
}
echo "<td> <input type ='text' value= '$string' name = '$cell'/></td>";
$x= ++$x;
}
?>
</html>
</body>
马克一样简单,非常感谢你的详细explination。它现在很好用。 – Demosthenes 2015-02-25 10:51:04