我的目的是读取一个excel(.xls)文件并将其存储在数据库中,并在浏览器中显示excel文件的输入。
我在阅读文件时遇到问题。我已经整合了Excelfilereader.php
程序读取excel文件,但在浏览器中打印输出(excel文件内容)时,数据以锯齿形方式打印。
示例:
studentid 名称 班级 学校 课程 地址 [字段名称]
在浏览器中,打印相同的字段,但 studentID 的数据打印在名称下,名称的数据打印在< strong> class ,但所有的都是按原样打印的。前两列未对齐打印。
用于调用Excelreader.php的代码:
[mysql_query("insert into submit_form(parent_id,name,lab,submission,title,sampletype,file) values('','".$_POST['name']."','".$_POST['lab']."','".$_POST['submission']."','".$_POST['title']."','".$_POST['sampletype']."','".$uploadfile."')");
$insertid=mysql_insert_id();
$data = new Spreadsheet_Excel_Reader($_FILES['uploadfile']['name']);
//echo "Total Sheets in this xls file: ".count($data->sheets)."<br /><br />";
$html="<table border='1'>";
for($i=0;$i<count($data->sheets);$i++) // Loop to get all sheets in a file.
{
if(count($data->sheets[$i][cells])>0) // checking sheet not empty
{
//echo "Sheet $i:<br /><br />Total rows in sheet $i ".count($data->sheets[$i][cells])."<br />";
for($j=2;$j<=count($data->sheets[$i][cells]);$j++) // loop used to get each row of the sheet
{
$html.="<tr>";
for($k=1;$k<=count($data->sheets[$i][cells][$j]);$k++) // This loop is created to get data in a table format.
{
$html.="<td>";
$html.=$data->sheets[$i][cells][$j][$k];
$html.="</td>";
}
$data->sheets[$i][cells][$j][1];
$eid = $eid = mysqli_real_escape_string($connection,$data->sheets[$i][cells][$j][1]);
$age = mysqli_real_escape_string($connection,$data->sheets[$i][cells][$j][2]);
$gender = mysqli_real_escape_string($connection,$data->sheets[$i][cells][$j][3]);
$ethnic = mysqli_real_escape_string($connection,$data->sheets[$i][cells][$j][4]);
$cancer = mysqli_real_escape_string($connection,$data->sheets[$i][cells][$j][5]);
$sample = mysqli_real_escape_string($connection,$data->sheets[$i][cells][$j][6]);
$instrument = mysqli_real_escape_string($connection,$data->sheets[$i][cells][$j][7]);
$instrumenttype = mysqli_real_escape_string($connection,$data->sheets[$i][cells][$j][8]);
$query = "insert into submit_form(parent_id,name,lab,submission,title,patient,age,gender,ethnic,cancer,sample,instrument,instrumenttype,attach,sampletype,file) values('".$insertid."','".$_POST['name']."','".$_POST['lab']."','".$_POST['submission']."','".$_POST['title']."','".$eid."','".$age."','".$gender."','".$ethnic."','".$cancer."','".$sample."','".$instrument."','".$instrumenttype."','1','".$_POST['sampletype']."','".$uploadfile."')";
mysqli_query($connection,$query);
$html.="</tr>";
}
}][2]
答案 0 :(得分:0)
您通过mysql_*
电话进行了混合mysqli_*
来电。仅使用 mysqli_*
来电。
(你也应该逃离$_POST[]
列。他们很容易受黑客攻击。)