PHPExcel图像包括

时间:2017-03-15 03:45:52

标签: image phpexcel barcode

我努力了,只想在A1单元格中显示条形码图像。它在html中运行良好。但不是在PhpExcel中。提前谢谢。

$generator = new BarcodeGeneratorPNG();
$wizard = new PHPExcel_Helper_HTML();
$cellText = '<img src="data:image/png;base64,' . base64_encode($generator->getBarcode('081231723837', $generator::TYPE_CODE_128)) . '">';
$richText = $wizard->toRichTextObject($cellText);
$objPHPExcel->setActiveSheetIndex(0)->setCellValue('A1', $richText);

1 个答案:

答案 0 :(得分:0)

尝试一下:

  

https://github.com/davidscotttufts/php-barcode

生成条形码.png

    $filepath = 'barcode.png';
    $text = '1234567890123';
    $size = "80";
    $orientation = "horizontal";
    $code_type = "code128";
    $print = "true";
    $sizefactor = "0.8";
    barcode( $filepath,$text, $size, $orientation, $code_type, $print, $sizefactor );

报告:

    $imgBarcode = imagecreatefrompng('bar_code.png');
    $objDrawing = new PHPExcel_Worksheet_MemoryDrawing();
    $objDrawing->setDescription('barcode');
    $objDrawing->setImageResource($imgBarcode);
    $objDrawing->setHeight(100);
    $objDrawing->setCoordinates('A1');
    $objDrawing->setWorksheet($objPHPExcel->getActiveSheet());