首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >当内容比单元格宽时,防止单元格重叠

当内容比单元格宽时,防止单元格重叠
EN

Stack Overflow用户
提问于 2013-11-18 07:10:10
回答 2查看 1.4K关注 0票数 0

我有这个。

代码语言:javascript
复制
for($i=0; $i < $longArreglo; $i++) {    
        $this->Cell($w[0],6, $final_array[$i][0],'LR',0,'L', $fill);
        $this->Cell($w[1],6, $final_array[$i][2],'LR',0,'C', $fill);
        $this->Cell($w[2],6, $final_array[$i][3],'LR',0,'L', $fill);
        $this->Cell($w[3],6, $final_array[$i][5],'LR',0,'C', $fill);
        $this->Cell($w[4],6, $final_array[$i][6],'LR',0,'C', $fill);
        $this->Cell($w[5],6, $final_array[$i][12],'LR',0,'C', $fill);
        $this->Cell($w[6],6, $final_array[$i][13],'LR',0,'C', $fill);
        $this->Cell($w[7],6, $final_array[$i][14],'LR',0,'C', $fill);
        $this->Cell($w[8],6, $final_array[$i][15],'LR',0,'C', $fill);
        $this->Cell($w[9],6, $final_array[$i][16],'LR',0,'C', $fill);
        $this->Cell($w[10],6, $final_array[$i][17],'LR',0,'C', $fill);
        $this->Cell($w[11],6, $final_array[$i][18],'LR',0,'C', $fill);
        $this->Cell($w[12],6, $final_array[$i][19],'LR',0,'C', $fill);
        $this->Cell($w[13],6, $final_array[$i][20],'LR',0,'C', $fill);
        $this->Ln();

    }

在这里:$this->Cell($w[2],6, $final_array[$i][3],'LR',0,'L', $fill);是一个人名,单元格的宽度是15,如果这个名字比单元格大,它会这样做:

我需要细胞不合并。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2020-09-26 12:33:51

这篇文章可能很旧,但我在网上找不到任何其他解决方案。我已经修改了雨果的职位,我希望有一天这会对某人有所帮助。为了便于使用,我在fpdf类中创建了一个新方法。

代码语言:javascript
复制
function pdfText($cellWidth, $text, $pdf){
    $textWidth = $pdf->getstringwidth($text);
    while($textWidth > $cellWidth -1){
        $text       = substr($text,0,-1);
        $textWidth  = $pdf->getstringwidth($text);
    }
    return $text;
}

require_once('fpdf/fpdf.php');
$pdf = new FPDF();
$pdf->AddPage();

$text = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit. Sint esse quia repellat cupiditate excepturi exercitationem asperiores eligendi iusto. Blanditiis sequi suscipit assumenda quibusdam aliquid quas eligendi soluta ab fugit ad.';

$pdf->setFont('Arial', '', 10);
$cellWidth = 180;
$text = pdfText($cellWidth, $text, $pdf);
$pdf->Cell($cellWidth,6,$text,1,1,'L',0);

$pdf->setFont('Arial', '', 12);
$cellWidth = 160;
$text = pdfText($cellWidth, $text, $pdf);
$pdf->Cell($cellWidth,7,$text,1,1,'L',0);

$pdf->setFont('Arial', '', 14);
$cellWidth = 140;
$text = pdfText($cellWidth, $text, $pdf);
$pdf->Cell($cellWidth,8,$text,1,1,'L',0);

$pdf->setFont('Arial', '', 16);
$cellWidth = 120;
$text = pdfText($cellWidth, $text, $pdf);
$pdf->Cell($cellWidth,9,$text,1,1,'L',0);

$pdf->Output('I');
票数 1
EN

Stack Overflow用户

发布于 2014-05-29 09:47:08

因此,例子应该是:

代码语言:javascript
复制
// width - width of cell
// text to be put into cell
// pdf - pdf object of fpdf
// fill - how to fill cell?
function putField($width,$text,$pdf,$fill){     
 $textwidth = $pdf->getstringwidth($text); 
 while($textwidth>$width){              // loop until textwidth is shorter than cell width
  $text=substr($text,0,-1);             // strip last char
  $textwidth = $pdf->getstringwidth($text); // read text width again
 }

 $pdf->Cell($width,6, $text,'LR',0,'L', $fill); // put the cell
}

for($i=0; $i < $longArreglo; $i++) {    
   putField($w[0],$final_array[$i][0],$this,$fill);        
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20042051

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档