请教各位高手前辈!谁做过导入Excel文件,读取、分析、然后我保存到数据库。这样一个过程。<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Excel读取</title>
</head><body>
<form id="form1" name="form1" method="post" action="passExcel.php">
<label>请选择
<input type="file" name="ExcelFile" id="ExcelFile" />
<input type="submit" name="Submit" value="提交" />
</label>
</form>
</body>
</html>
passExcel.php应该怎么写!我Excel文档很简单!
我们来测试试题 选择一 选择二 选择三 选择四 B
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Excel读取</title>
</head><body>
<form id="form1" name="form1" method="post" action="passExcel.php">
<label>请选择
<input type="file" name="ExcelFile" id="ExcelFile" />
<input type="submit" name="Submit" value="提交" />
</label>
</form>
</body>
</html>
passExcel.php应该怎么写!我Excel文档很简单!
我们来测试试题 选择一 选择二 选择三 选择四 B
$conn=new com("adodb.connection", NULL, CP_UTF8);
$connstr="Driver={Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)};DBQ=".realpath("test.xlsx");
$conn->open($connstr);
$sql="select * from [Sheet1$]"; // 查询EXCEL工作表
$rs=$conn->execute($sql);while(!$rs->eof)
{
echo trim($rs->fields(0)->value),"\r\n";
$rs->movenext;
}
Fatal error: Uncaught exception 'com_exception' with message '<b>Source:</b> Microsoft OLE DB Provider for ODBC Drivers<br/><b>Description:</b> 操作已被取消。' in D:\wamp\www\Excel\passExcel.php:4 Stack trace: #0 D:\wamp\www\Excel\passExcel.php(4): com->open('Driver={Microso...') #1 {main} thrown in D:\wamp\www\Excel\passExcel.php on line 4
<?php
require_once 'include/reader.php';
$data = new Spreadsheet_Excel_Reader();$data->setOutputEncoding('GBK');$data->read('test.xls');for ($j = 1; $j <= $data->sheets[0]['numCols']; $j++) { echo "\"".$data->sheets[0]['cells'][$i][$j]."\","; }
?>
$conn=new com("adodb.connection", NULL, CP_UTF8);
$connstr="Driver={Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)};DBQ=".realpath("test.xlsx");
$conn->open($connstr);
$sql="select * from [Sheet1$]"; // 查询EXCEL工作表
$rs=$conn->execute($sql);while(!$rs->eof)
{
echo trim($rs->fields(0)->value),"\r\n";
$rs->movenext;
}
?>
require_once 'include/reader.php';$file_name=$_REQUEST['ExcelFile'];$data = new Spreadsheet_Excel_Reader();//这里需要改变字符编码!根据实际情况改变
$data->setOutputEncoding('gb2312');//这里需要注意路径可能有中文。
$data->read(iconv("UTF-8","GB2312",$file_name));error_reporting(E_ALL ^ E_NOTICE);//具体读取Excel文件内容
for ($i = 1; $i <= $data->sheets[0]['numRows']; $i++) {
for ($j = 1; $j <= $data->sheets[0]['numCols']; $j++) {
echo "\"".$data->sheets[0]['cells'][$i][$j]."\",";
}
echo "<br>";}
还有最主要的开始我用的是Excel2007建的文档。后来我只改了一下后缀名,
把xlsx直接删除掉x,进行读取。这样是不行的。
在Excel2007里另存为存成97-2003工作簿就行了!这样读取出来就不会出错了!