我一直试图将一个数据数组打印到fpdf的表中。 这是我继教程: http://www.fpdf.org/en/tutorial/tuto5.htmFPDF -PHP -Call to undefined method
除了它口口声声说:
Fatal error: Uncaught Error: Call to undefined method FPDF::FancyTable() in ...
我见过很多这样的其他问题,但他们都不固定我的。
我觉得这应该是一个非常简单的解决方案,我正在做一些愚蠢的事情。
任何帮助将不胜感激。
<?php
require('../fpdf/fpdf.php');
class PDF extends FPDF
{
// Colored table
function FancyTable($header, $data)
{
// Colors, line width and bold font
$this->SetFillColor(255,0,0);
$this->SetTextColor(255);
$this->SetDrawColor(128,0,0);
$this->SetLineWidth(.3);
$this->SetFont('','B');
// Header
$w = array(40, 35, 40, 45);
for($i=0;$i<count($header);$i++)
$this->Cell($w[$i],7,$header[$i],1,0,'C',true);
$this->Ln();
// Color and font restoration
$this->SetFillColor(224,235,255);
$this->SetTextColor(0);
$this->SetFont('');
// Data
$fill = false;
foreach($data as $row)
{
$this->Cell($w[0],6,$row[0],'LR',0,'L',$fill);
$this->Cell($w[1],6,$row[1],'LR',0,'L',$fill);
$this->Cell($w[2],6,number_format($row[2]),'LR',0,'R',$fill);
$this->Cell($w[3],6,number_format($row[3]),'LR',0,'R',$fill);
$this->Ln();
$fill = !$fill;
}
// Closing line
$this->Cell(array_sum($w),0,'','T');
}
}
$csv = array();
$lines = file('../data/StaffData.csv', FILE_IGNORE_NEW_LINES);
foreach ($lines as $key => $value)
{
$csv[$key] = str_getcsv($value);
}
$pdf = new FPDF();
// Column headings
$header = array('Country', 'Capital', 'Area (sq km)', 'Pop. ');
$data = $csv;
$pdf->AddPage();
$pdf->FancyTable($header,$data);
$pdf->Output();
?>
**更新**
-Thanks的帮助。 我确实改变了字体并没有改变。我改变它:
$this->SetFont('','B');
到
$this->SetFont('Arial','',14);
(在花式球台功能)
但这些错误的堆出现:
Warning: number_format() expects parameter 1 to be float, string given in /Applications/XAMPP/xamppfiles...
Notice: A non well formed numeric value encountered in /Applications/XAMPP/xamppfiles...
Fatal error: Uncaught Exception: FPDF error: Some data has already been output, can't send PDF file in /Applications/XAMPP/xamppfiles...
我对不起,但我真的不知道该怎么办。
但是,我通过删除number_format行来显示一些表格。 I.E我删除了这两行:
$this->Cell($w[2],6,number_format($row[2]),'LR',0,'R',$fill);
$this->Cell($w[3],6,number_format($row[3]),'LR',0,'R',$fill);
任何原因为什么?它显示前两列,但不显示其余部分。
错误是告诉你'$行[2]'和'$行[3]'是扩展FPDF字符串而不是数字,所以你不能使用'number_format',除非你先将它们从一个字符串中转换出来。 – hcoat
噢,好的。我呼应它们,行将所有数据保存在一个字符串中。我将如何将字符串转换为数字?在删除number_format并离开行之后,它好像工作正常。 感谢您的帮助hcoat。无论如何,我会接受答案。 :-) –