我有一个页面,我用它来检索一些用php写的excel数据...通过使用phpexcel ...这部分为我提供公司信息
echo '<form action="final.php" method="post">';
echo "<table border='1'>";
for ($rowcount = $rowCompanyInfoStart; $rowcount <= $rowCompanyInfoEnd; $rowcount++)
{
//$data = $objWorksheet->rangeToArray('A1:' . $maxCell['column'] . $maxCell['row']);
$rangeCoordinates = $colCompanyInfoStart . $rowcount . ':' . $colCompanyInfoEnd . $rowcount;
$rowData = $sheet->rangeToArray($rangeCoordinates, NULL, TRUE, FALSE);
echo "<tr>";
$companyname=$worksheet->getCell($column.$row)->getValue();
// echo $companyname;
foreach($rowData[0] as $result)
{
echo "<td>".$result." </td>";
}
echo "</tr>";
}
echo "</table>";
echo "<br />";
echo '<input type="submit" name="sub" value="Convert into PDF" />';
// echo '<input type="text" name="resName" value="$result">';
function getdatan()
{
global $result; // declare as global
return $result;
}
echo '</form>';
这部分是我获取公司信息的地方......它看起来像下方的表格区域......
我检索信息并能够显示为&#34; $ result&#34;变量和名为&#34的提交按钮;将其转换为pdf&#34;我把它发送到我使用TCPDF的其他php页面....
通常,第二页的这一部分
$pdf->SetFont('times', 'BI', 12);
// add a page
$pdf->AddPage('L', 'A4');
if(isset($_POST['submit']))
{
$result = $_GET['resName'];
$pdf->Write(20, $result, '', 0, 'C', true, 0, false, false, 0);
}
// set some text to print
$txt = <<<EOD
TCPDF Example 003
Custom page header and footer are defined by extending the TCPDF class and overriding the Header() and Footer() methods.
EOD;
// print a block of text using Write()
// $pdf->Write(20, $resultt, '', 0, 'C', true, 0, false, false, 0);
// ---------------------------------------------------------
ob_end_clean();
//Close and output PDF document
$pdf->Output('example.pdf', 'I');
但是,我无法打印&#34; $ result&#34;在第二页......你能帮我讲解如何在pdf上打印这张表......
PS:请澄清你的帮助......
答案 0 :(得分:0)
试试这个
更改:
echo '<input type="submit" name="sub" value="Convert into PDF" />';
要:
echo '<input type="submit" name="resName" value="Convert into PDF" />';
修改强>
将它放在第二页的开头:
var_dump($_POST);
只是检查您从第一页接收的内容。
同样改变:
$result = $_GET['resName'];
到此:
$result = $_POST['resName'];
答案 1 :(得分:0)
session_start();
//rest of your code and then...
if($_SERVER['REQUEST_METHOD'] == 'POST') {
echo '<form action="final.php" method="POST">';
$tablo="<br />";
$tablo = $tablo."<table border=\"1\" cellpadding=\"2\" cellspacing=\"2\" align='center'>";
for ($rowcount = $rowCompanyInfoStart; $rowcount <= $rowCompanyInfoEnd; $rowcount++)
{
//$data = $objWorksheet->rangeToArray('A1:' . $maxCell['column'] . $maxCell['row']);
$rangeCoordinates = $colCompanyInfoStart . $rowcount . ':' . $colCompanyInfoEnd . $rowcount;
$rowData = $sheet->rangeToArray($rangeCoordinates, NULL, TRUE, FALSE);
//fazla bosluk olursa bunları aç ya da hucre bos mu kontrol et (cellExists ile)
//rowData = array_map('array_filter', $rowData);
//$rowData = array_filter($rowData);
$tablo= $tablo."<tr >";
$companyname=$worksheet->getCell($column.$row)->getValue();
// echo $companyname;
foreach($rowData[0] as $result)
{
$tablo= $tablo. "<td>".$result. " </td>";
}
$tablo= $tablo. "</tr>";
}
$tablo= $tablo. "</table>";
echo $tablo;
echo "<br />";
if($_SERVER['REQUEST_METHOD'] != 'POST') {
echo "SESSION Not AVAIL. first run.";
}
else{
$_SESSION['varname'] = $tablo;
}
echo '<input type="submit" name="resName" value="Convert into PDF" />';
}
所以我在这里使用了&#34; POST请求&#34;而不只是&#34; POST&#34;。它发送&#34; REQUEST&#34;没有任何&#34; POST DATA&#34; ...然后为了发送数据,我创建了一个名为&#34; $ table&#34;的变量。我将所有行和单元格信息放入其中并创建了一个会话,以便第二个PHP可以检索它....
在第二个PHP页面上,我回答&#34;请求&#34;并打开&#34;会话&#34;就像那样
session_start();
//rest of your code and then...
if($_SERVER['REQUEST_METHOD'] != 'POST') {
echo "SESSION Not AVAIL. first run.";
$tablo = $_SESSION['varname'];
echo "SESSION now set.";
}
else{
$tablo = $_SESSION['varname'];
//echo "SESSION SET, value: " .$_SESSION['varname']. " and ". $_SESSION['color'];
}
if (isset($_SESSION['varname'])){
$tablo = $_SESSION['varname'];
// print_r($_SESSION);
//echo "Session Set: <br/>" . $tablo;
}
else{
echo "Session not set. Tablo is empty";
// echo "Session Set: <br/>" . $tablo;
}
这样就可以了!