我想帮助我的代码,因为在我单击提交按钮(执行)以执行我的PHPExcel代码后无法执行。
相反,它只会刷新页面而不会生成Excel报告,没有任何反应。任何人都可以帮我解决。
我目前的代码:
<?php
if(isset($_POST['execute'])){
mysql_connect("localhost","root","") or die("cant connect!");
mysql_select_db("klayton") or die("cant find database!");
require_once '../Classes\PHPExcel\IOFactory.php';
$filename = 'final_worksheet.xlsx';
$title = 'title';
$objReader = PHPExcel_IOFactory::createReader('Excel2007');
$objReader->setReadDataOnly(true);
$objPHPExcel = $objReader->load($filename);
$objWorksheet = $objPHPExcel->getActiveSheet();
$objWorksheet = $objPHPExcel->setActiveSheetIndex(0);
$result = array();
for ( $n = 1; $n <=10; $n++ )
{
$aic = isset($_POST['aic'.$n]) ? $_POST['aic'.$n] : "";
$name = isset($_POST['name'.$n]) ? $_POST['name'.$n] : "";
$optA = isset($_POST['optA'.$n]) ? $_POST['optA'.$n] : "";
$optB = isset($_POST['optB'.$n]) ? $_POST['optB'.$n] : "";
$optC = isset($_POST['optC'.$n]) ? $_POST['optC'.$n] : "";
$optD = isset($_POST['optD'.$n]) ? $_POST['optD'.$n] : "";
$other_qual = isset($_POST['other_qual'.$n]) ? $_POST['other_qual'.$n] : "";
$interview = isset($_POST['interview'.$n]) ? $_POST['interview'.$n] : "";
$total = isset($_POST['total'.$n]) ? $_POST['total'.$n] : "";
$remarks = 'N/A';
$result[] = array(
$aic,
$name,
$optA,
$optB,
$optC,
$optD,
$other_qual,
$interview,
$total,
$remarks );
}
$headings = array(array('PNP-NUP FINAL WORKSHEET'),array(
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL),array(
'AIC',
'Name of Candidates',
'Educational Attainment',
'Experience',
'In-Service Trainings & Seminars Attended',
'Eligibility',
'Other Qualifications',
'Interview',
'Total',
'Remarks')
);
$fone = "___________________________";
$ftwo = "Signature of Rater";
$footer = array(array($fone),array($ftwo));
$points = array(
' ',
' ',
'(20 pts)',
'(20 pts)',
'(20 pts)',
'(20 pts)',
'(10 pts)',
'(10 pts)',
'(100 pts)',
' '
);
$objPHPExcel->getActiveSheet()->getColumnDimension('A')->setAutoSize(true);
$objPHPExcel->getActiveSheet()->getColumnDimension('B')->setAutoSize(true);
$objPHPExcel->getActiveSheet()->getColumnDimension('C')->setAutoSize(true);
$objPHPExcel->getActiveSheet()->getColumnDimension('D')->setAutoSize(true);
$objPHPExcel->getActiveSheet()->getColumnDimension('E')->setAutoSize(true);
$objPHPExcel->getActiveSheet()->getColumnDimension('F')->setAutoSize(true);
$objPHPExcel->getActiveSheet()->getColumnDimension('G')->setAutoSize(true);
$objPHPExcel->getActiveSheet()->getColumnDimension('H')->setAutoSize(true);
$objPHPExcel->getActiveSheet()->getColumnDimension('I')->setAutoSize(true);
$objPHPExcel->getActiveSheet()->getColumnDimension('J')->setAutoSize(true);
$objPHPExcel->getActiveSheet()
->getStyle('A1:J19')
->getAlignment()
->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$objPHPExcel->getDefaultStyle()
->getBorders()
->getTop()
->setBorderStyle(PHPExcel_Style_Border::BORDER_THICK);
$objPHPExcel->getDefaultStyle()
->getBorders()
->getBottom()
->setBorderStyle(PHPExcel_Style_Border::BORDER_THICK);
$objPHPExcel->getDefaultStyle()
->getBorders()
->getLeft()
->setBorderStyle(PHPExcel_Style_Border::BORDER_THICK);
$objPHPExcel->getDefaultStyle()
->getBorders()
->getRight()
->setBorderStyle(PHPExcel_Style_Border::BORDER_THICK);
$objPHPExcel->getActiveSheet()->getStyle('A1:I1')->getFont()->setSize(22);
$objPHPExcel->getActiveSheet()->mergeCells('A1:I2');
$objPHPExcel->getActiveSheet()->getStyle('A16:I16')->getFont()->setSize(17);
$objPHPExcel->getActiveSheet()->getStyle('A17:I17')->getFont()->setSize(13);
$objPHPExcel->getActiveSheet()->mergeCells('A16:I16');
$objPHPExcel->getActiveSheet()->mergeCells('A17:I17');
$objPHPExcel->getActiveSheet()->getStyle('A3:I3')->applyFromArray(
array(
'font' => array(
'bold' => true
),
'alignment' => array(
'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
),
'borders' => array(
'top' => array(
'style' => PHPExcel_Style_Border::BORDER_THIN
)
),
'fill' => array(
'type' => PHPExcel_Style_Fill::FILL_GRADIENT_LINEAR,
'rotation' => 90,
'startcolor' => array(
'argb' => 'FFA0A0A0'
),
'endcolor' => array(
'argb' => 'FFFFFFFF'
)
)
)
);
$objPHPExcel->getActiveSheet()->fromArray($headings, null, 'A1');
$objPHPExcel->getActiveSheet()->fromArray($footer, null, 'A16');
$objPHPExcel->getActiveSheet()->fromArray($points, null, 'A4');
$row = 5;
foreach($result as $rows){
if (!empty($rows[4])) {
$objPHPExcel->getActiveSheet()->fromArray($rows, null, 'A' . $row);
$row++;
}
}
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header(sprintf('Content-Disposition: attachment;filename="%s.xlsx"',preg_replace('/\\r\\n?|\\n/', '', $title)));
header('Cache-Control: max-age=0');
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter->save('php://output');
exit;
}?>
html代码:
<form>
<table width="100%" bgcolor="#FFFFFF">
<tr>
<td width="28%"><b><font color="#000000"> Batch #: </font><font color="#993300"><label id="batchcode" class="empty_batchcode"></label></font></b></td>
<td width="45%" rowspan="2"></td>
<td width="27%" rowspan="2">
<br />
<p><center><font size="+2" color="#990033"><b>Time:</b> <label id="startTime"></label></font></center></p>
</td>
</tr>
<tr>
<td>
<table width="100%">
<tr>
<td width="70%" ><input type="text" name="search" id="query" placeholder="search for batchcode here!" /></td>
<td width="3%" ><input id="send_search_form" type="button" value="Go" name="search" width="100%" /></td>
</tr>
</table>
</td>
</tr>
</table>
<p><hr></p>
<Font color="#000000">
<table bgcolor="#FFFFFF" width="100%">
<tr>
<td>
<p>
<center>
<a href="../logout.php" id="logout" class="right"><b>LOG-OUT </b></a>
<h1> PNP-NUP FINAL WORKSHEET</h1>
</center></p>
<table border="1" width="100%" bgcolor="#FFFFFF">
<tr>
<th width="12%" rowspan="3">Name of Candidates</th>
<th colspan="4">Minimum Requirements</th>
<th width="12%" rowspan="2">Other Qualifications</th>
<th width="9%" rowspan="2">Interview</th>
<th width="8%" rowspan="2">Total</th>
<th width="9%" rowspan="3">Remarks</th>
</tr>
<tr>
<th width="14%">Educational Attainment</th>
<th width="10%">Experience</th>
<th width="17%">In-Service Trainings & Seminars Attended</th>
<th width="9%">Eligibility</th>
</tr>
<tr>
<td><center>(20 pts)</center></td>
<td><center>(20 pts)</center></td>
<td><center>(20 pts)</center></td>
<td><center>(20 pts)</center></td>
<td><center>(10 pts)</center></td>
<td><center>(10 pts)</center></td>
<td><center>(100 pts)</center></td>
</tr>
<tr>
<!--opt1-->
<input class="search_form_input" type="hidden" name="id1" id="id1" readonly />
<td><input class="search_form_input" name="name1" id="name1" readonly type="text" /></td>
<td><input class="search_form_input" name="optA1" id="optA1" onkeypress="return isnumeric(event)" type="text" onchange="optTotal1()" maxlength="2" /></td>
<td><input class="search_form_input" name="optB1" id="optB1" onkeypress="return isnumeric(event)" type="text" onchange="optTotal1()" maxlength="2" /></td>
<td><input class="search_form_input" name="optC1" id="optC1" onkeypress="return isnumeric(event)" type="text" onchange="optTotal1()" maxlength="2" /></td>
<td><input class="search_form_input" name="optD1" id="optD1" onkeypress="return isnumeric(event)" type="text" onchange="optTotal1()" maxlength="2" /></td>
<td><input class="search_form_input" readonly name="other_qual1" id="other_qual1" type="text" /></td>
<td><input class="search_form_input" readonly name="interview1" id="interview1" type="text" /></td>
<td><input class="search_form_input" name="total1" id="total1" onkeypress="return isnumeric(event)" readonly type="text" onKeyUp="optTotal1()" /></td>
<td><input class="search_form_input" name="remarks1" id="remarks1" onkeypress="return isnumeric(event)" readonly type="text"></td>
</tr>
<tr>
<!--opt2-->
<input class="search_form_input" type="hidden" name="id2" id="id2" readonly />
<td><input class="search_form_input" name="name2" id="name2" readonly type="text" /></td>
<td><input class="search_form_input" name="optA2" id="optA2" onkeypress="return isnumeric(event)" type="text" onchange="optTotal2()" maxlength="2" /></td>
<td><input class="search_form_input" name="optB2" id="optB2" onkeypress="return isnumeric(event)" type="text" onchange="optTotal2()" maxlength="2" /></td>
<td><input class="search_form_input" name="optC2" id="optC2" onkeypress="return isnumeric(event)" type="text" onchange="optTotal2()" maxlength="2" /></td>
<td><input class="search_form_input" name="optD2" id="optD2" onkeypress="return isnumeric(event)" type="text" onchange="optTotal1()" maxlength="2" /></td>
<td><input class="search_form_input" readonly name="other_qual2" id="other_qual2" type="text" /></td>
<td><input class="search_form_input" readonly name="interview2" id="interview2" type="text" /></td>
<td><input class="search_form_input" name="total2" id="total2" onkeypress="return isnumeric(event)" readonly type="text" onKeyUp="optTotal2()" /></td>
<td><input class="search_form_input" name="remarks2" id="remarks2" onkeypress="return isnumeric(event)" readonly type="text"></td>
</tr>
<tr>
<!--opt3-->
<input class="search_form_input" type="hidden" name="id3" id="id3" readonly />
<td><input class="search_form_input" name="name3" id="name3" readonly type="text" /></td>
<td><input class="search_form_input" name="optA3" id="optA3" onkeypress="return isnumeric(event)" type="text" onchange="optTotal3()" maxlength="2" /></td>
<td><input class="search_form_input" name="optB3" id="optB3" onkeypress="return isnumeric(event)" type="text" onchange="optTotal3()" maxlength="2" /></td>
<td><input class="search_form_input" name="optC3" id="optC3" onkeypress="return isnumeric(event)" type="text" onchange="optTotal3()" maxlength="2" /></td>
<td><input class="search_form_input" name="optD3" id="optD3" onkeypress="return isnumeric(event)" type="text" onchange="optTotal3()" maxlength="2" /></td>
<td><input class="search_form_input" readonly name="other_qual3" id="other_qual3" type="text" /></td>
<td><input class="search_form_input" readonly name="interview3" id="interview3" type="text" /></td>
<td><input class="search_form_input" name="total3" id="total3" onkeypress="return isnumeric(event)" readonly type="text" onKeyUp="optTotal3()" /></td>
<td><input class="search_form_input" name="remarks3" id="remarks3" onkeypress="return isnumeric(event)" readonly type="text"></td>
</tr>
<tr>
<!--opt4-->
<input class="search_form_input" type="hidden" name="id4" id="id4" readonly />
<td><input class="search_form_input" name="name4" id="name4" readonly type="text" /></td>
<td><input class="search_form_input" name="optA4" id="optA4" onkeypress="return isnumeric(event)" type="text" onchange="optTotal4()" maxlength="2" /></td>
<td><input class="search_form_input" name="optB4" id="optB4" onkeypress="return isnumeric(event)" type="text" onchange="optTotal4()" maxlength="2" /></td>
<td><input class="search_form_input" name="optC4" id="optC4" onkeypress="return isnumeric(event)" type="text" onchange="optTotal4()" maxlength="2" /></td>
<td><input class="search_form_input" name="optD4" id="optD4" onkeypress="return isnumeric(event)" type="text" onchange="optTotal4()" maxlength="2" /></td>
<td><input class="search_form_input" readonly name="other_qual4" id="other_qual4" type="text" /></td>
<td><input class="search_form_input" readonly name="interview4" id="interview4" type="text" /></td>
<td><input class="search_form_input" name="total4" id="total4" onkeypress="return isnumeric(event)" readonly type="text" onKeyUp="optTotal4()" /></td>
<td><input class="search_form_input" name="remarks4" id="remarks4" onkeypress="return isnumeric(event)" readonly type="text"></td>
</tr>
<tr>
<!--opt5-->
<input class="search_form_input" type="hidden" name="id5" id="id5" readonly />
<td><input class="search_form_input" name="name5" id="name5" readonly type="text" /></td>
<td><input class="search_form_input" name="optA5" id="optA5" onkeypress="return isnumeric(event)" type="text" onchange="optTotal5()" maxlength="2" /></td>
<td><input class="search_form_input" name="optB5" id="optB5" onkeypress="return isnumeric(event)" type="text" onchange="optTotal5()" maxlength="2" /></td>
<td><input class="search_form_input" name="optC5" id="optC5" onkeypress="return isnumeric(event)" type="text" onchange="optTotal5()" maxlength="2" /></td>
<td><input class="search_form_input" name="optD5" id="optD5" onkeypress="return isnumeric(event)" type="text" onchange="optTotal5()" maxlength="2" /></td>
<td><input class="search_form_input" readonly name="other_qual5" id="other_qual5" type="text" /></td>
<td><input class="search_form_input" readonly name="interview5" id="interview5" type="text" /></td>
<td><input class="search_form_input" name="total5" id="total5" onkeypress="return isnumeric(event)" readonly type="text" onKeyUp="optTotal5()" /></td>
<td><input class="search_form_input" name="remarks5" id="remarks5" onkeypress="return isnumeric(event)" readonly type="text"></td>
</tr>
<tr>
<!--opt6-->
<input class="search_form_input" type="hidden" name="id6" id="id6" readonly />
<td><input class="search_form_input" name="name6" id="name6" readonly type="text" /></td>
<td><input class="search_form_input" name="optA6" id="optA6" onkeypress="return isnumeric(event)" type="text" onchange="optTotal6()" maxlength="2" /></td>
<td><input class="search_form_input" name="optB6" id="optB6" onkeypress="return isnumeric(event)" type="text" onchange="optTotal6()" maxlength="2" /></td>
<td><input class="search_form_input" name="optC6" id="optC6" onkeypress="return isnumeric(event)" type="text" onchange="optTotal6()" maxlength="2" /></td>
<td><input class="search_form_input" name="optD6" id="optD6" onkeypress="return isnumeric(event)" type="text" onchange="optTotal6()" maxlength="2" /></td>
<td><input class="search_form_input" readonly name="other_qual6" id="other_qual6" type="text" /></td>
<td><input class="search_form_input" readonly name="interview6" id="interview6" type="text" /></td>
<td><input class="search_form_input" name="total6" id="total6" onkeypress="return isnumeric(event)" readonly type="text" onKeyUp="optTotal6()" /></td>
<td><input class="search_form_input" name="remarks6" id="remarks6" onkeypress="return isnumeric(event)" readonly type="text"></td>
</tr>
<tr>
<!--opt7-->
<input class="search_form_input" type="hidden" name="id7" id="id7" readonly />
<td><input class="search_form_input" name="name7" id="name7" readonly type="text" /></td>
<td><input class="search_form_input" name="optA7" id="optA7" onkeypress="return isnumeric(event)" type="text" onchange="optTotal7()" maxlength="2" /></td>
<td><input class="search_form_input" name="optB7" id="optB7" onkeypress="return isnumeric(event)" type="text" onchange="optTotal7()" maxlength="2" /></td>
<td><input class="search_form_input" name="optC7" id="optC7" onkeypress="return isnumeric(event)" type="text" onchange="optTotal7()" maxlength="2" /></td>
<td><input class="search_form_input" name="optD7" id="optD7" onkeypress="return isnumeric(event)" type="text" onchange="optTotal7()" maxlength="2" /></td>
<td><input class="search_form_input" readonly name="other_qual7" id="other_qual7" type="text" /></td>
<td><input class="search_form_input" readonly name="interview7" id="interview7" type="text" /></td>
<td><input class="search_form_input" name="total7" id="total7" onkeypress="return isnumeric(event)" readonly type="text" onKeyUp="optTotal7()" /></td>
<td><input class="search_form_input" name="remarks7" id="remarks7" onkeypress="return isnumeric(event)" readonly type="text"></td>
</tr>
<tr>
<!--opt8-->
<input class="search_form_input" type="hidden" name="id8" id="id8" readonly />
<td><input class="search_form_input" name="name8" id="name8" readonly type="text" /></td>
<td><input class="search_form_input" name="optA8" id="optA8" onkeypress="return isnumeric(event)" type="text" onchange="optTotal8()" maxlength="2" /></td>
<td><input class="search_form_input" name="optB8" id="optB8" onkeypress="return isnumeric(event)" type="text" onchange="optTotal8()" maxlength="2" /></td>
<td><input class="search_form_input" name="optC8" id="optC8" onkeypress="return isnumeric(event)" type="text" onchange="optTotal8()" maxlength="2" /></td>
<td><input class="search_form_input" name="optD8" id="optD8" onkeypress="return isnumeric(event)" type="text" onchange="optTotal8()" maxlength="2" /></td>
<td><input class="search_form_input" readonly name="other_qual8" id="other_qual8" type="text" /></td>
<td><input class="search_form_input" readonly name="interview8" id="interview8" type="text" /></td>
<td><input class="search_form_input" name="total8" id="total8" onkeypress="return isnumeric(event)" readonly type="text" onKeyUp="optTotal8()" /></td>
<td><input class="search_form_input" name="remarks8" id="remarks8" onkeypress="return isnumeric(event)" readonly type="text"></td>
</tr>
<tr>
<!--opt9-->
<input class="search_form_input" type="hidden" name="id9" id="id9" readonly />
<td><input class="search_form_input" name="name9" id="name9" readonly type="text" /></td>
<td><input class="search_form_input" name="optA9" id="optA9" onkeypress="return isnumeric(event)" type="text" onchange="optTotal9()" maxlength="2" /></td>
<td><input class="search_form_input" name="optB9" id="optB9" onkeypress="return isnumeric(event)" type="text" onchange="optTotal9()" maxlength="2" /></td>
<td><input class="search_form_input" name="optC9" id="optC9" onkeypress="return isnumeric(event)" type="text" onchange="optTotal9()" maxlength="2" /></td>
<td><input class="search_form_input" name="optD9" id="optD9" onkeypress="return isnumeric(event)" type="text" onchange="optTotal9()" maxlength="2" /></td>
<td><input class="search_form_input" readonly name="other_qual9" id="other_qual9" type="text" /></td>
<td><input class="search_form_input" readonly name="interview9" id="interview9" type="text" /></td>
<td><input class="search_form_input" name="total9" id="total9" onkeypress="return isnumeric(event)" readonly type="text" onKeyUp="optTotal9()" /></td>
<td><input class="search_form_input" name="remarks9" id="remarks9" onkeypress="return isnumeric(event)" readonly type="text"></td>
</tr>
<tr>
<!--opt10-->
<input class="search_form_input" type="hidden" name="id10" id="id10" readonly />
<td><input class="search_form_input" name="name10" id="name10" readonly type="text" /></td>
<td><input class="search_form_input" name="optA10" id="optA10" onkeypress="return isnumeric(event)" type="text" onchange="optTotal10()" maxlength="2" /></td>
<td><input class="search_form_input" name="optB10" id="optB10" onkeypress="return isnumeric(event)" type="text" onchange="optTotal10()" maxlength="2" /></td>
<td><input class="search_form_input" name="optC10" id="optC10" onkeypress="return isnumeric(event)" type="text" onchange="optTotal10()" maxlength="2" /></td>
<td><input class="search_form_input" name="optD10" id="optD10" onkeypress="return isnumeric(event)" type="text" onchange="optTotal10()" maxlength="2" /></td>
<td><input class="search_form_input" readonly name="other_qual10" id="other_qual10" type="text" /></td>
<td><input class="search_form_input" readonly name="interview10" id="interview10" type="text" /></td>
<td><input class="search_form_input" name="total10" id="total10" onkeypress="return isnumeric(event)" readonly type="text" onKeyUp="optTotal10()" /></td>
<td><input class="search_form_input" name="remarks10" id="remarks10" onkeypress="return isnumeric(event)" readonly type="text"></td>
</tr>
<!--fetch table starts here-->
<!--fetch table ends here-->
</table>
</td>
</tr>
</table>
<input type="hidden" name="username" id="username" value="<?php echo $_SESSION['username']; ?>" />
<input type="hidden" name="repcode" id="repcode" value="<?php echo $_SESSION['repcode']; ?>" />
</font>
<input type="submit" name="execute" id="execute" value="Send to Excel" style="width:123px;height:30px" formnovalidate /><input type="submit" style="width:849px;height:30px" value="CLICK ME TO UPDATE" name="updates" id="updates" formnovalidate disabled />
</form>
答案 0 :(得分:1)
...
$result = array();
for ( $n = 1; $n <=10; $n++ )
{
$aic = isset($_POST['aic'.$n]) ? $_POST['aic'.$n] : "";
$name = isset($_POST['name'.$n]) ? $_POST['name'.$n] : "";
$optA = isset($_POST['optA'.$n]) ? $_POST['optA'.$n] : "";
$optB = isset($_POST['optB'.$n]) ? $_POST['optB'.$n] : "";
$optC = isset($_POST['optC'.$n]) ? $_POST['optC'.$n] : "";
$optD = isset($_POST['optD'.$n]) ? $_POST['optD'.$n] : "";
$other_qual = isset($_POST['other_qual'.$n]) ? $_POST['other_qual'.$n] : "";
$interview = isset($_POST['interview'.$n]) ? $_POST['interview'.$n] : "";
$total = isset($_POST['total'.$n]) ? $_POST['total'.$n] : "";
$remarks = 'N/A';
$result[] = array(
$aic,
$name,
$optA,
$optB,
$optC,
$optD,
$other_qual,
$interview,
$total,
$remarks );
}
...
答案 1 :(得分:1)
标准是GET
,因此if(isset($_POST['execute'])){
始终为false,而不是执行
任何东西。变化:
<form method="POST">
<table width="100%" bgcolor="#FFFFFF">
....