【问题标题】:Changing length of column to fit entire string in fpdf更改列的长度以适合 fpdf 中的整个字符串
【发布时间】:2016-05-01 10:23:15
【问题描述】:

如何更改列的长度以适合每个单元格的所有字符?

尝试使用动态长度,但没有太大帮助,

使用FPDF函数获取此表,表内容来自数据库..

创建表格的代码

function LoadData($file)
{
// Read file lines
/*$lines = file($file);
$data = array();
foreach($lines as $line)*/
while($row=mysqli_fetch_assoc($file))
$data[] =array_values($row);
return $data;
}
// Simple table
function BasicTable($header, $data)
{
// Header
foreach($header as $col)
    $this->Cell(40,7,$col,1);
$this->Ln();
// Data
foreach($data as $row)
{
    foreach($row as $col)
        $this->Cell(40,6,$col,1);
    $this->Ln();
}
//The first parameter of Cell() is the width of the cell.
}

调用sn-p

$sql="select `station`,`Category`,`Agency`,`startyear` from station";
$res=mysqli_query($conn,$sql);
$data = $pdf->LoadData($res);
$pdf->AddPage();
$pdf->BasicTable($header,$data);

【问题讨论】:

  • 请向我们展示您正在使用的代码,以便在您的解决方案中建立答案。
  • @etalon11 ,我已经提供了代码

标签: php html html-table fpdf


【解决方案1】:

FPDF 有一个函数“GetStringWidth”。使用该功能,您可以测量每列的最长文本,并相应地调整列的大小。

你会在这里找到一个很好的例子: http://fpdf.de/downloads/addons/62/

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-05-17
    • 2019-01-01
    • 2010-11-08
    • 1970-01-01
    • 2021-11-14
    • 2014-11-04
    • 1970-01-01
    相关资源
    最近更新 更多