【问题标题】:PHPExcel Image includePHPExcel 图像包括
【发布时间】:2017-03-15 03:45:52
【问题描述】:

我很努力,只想在 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);

【问题讨论】:

  • 我建议阅读"in memory" images with PHPExcel,而不是试图假设世界上的一切都只是html标记
  • 感谢您使用 html 编写器突出显示错误;富文本对象中的 html 标记应转义以防止其显示为 html
  • 非常感谢,但我已经得到答案了。

标签: image phpexcel barcode


【解决方案1】:

试试看:

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());

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-10-28
    • 2013-07-29
    • 2013-11-27
    • 2018-08-03
    • 2021-02-10
    • 1970-01-01
    • 2022-08-19
    相关资源
    最近更新 更多