gpt4 book ai didi

php - 使用 PHPExcel_RichText() 不显示换行符

转载 作者:行者123 更新时间:2023-12-04 20:26:21 28 4
gpt4 key购买 nike

我正在使用 PHPExcel 导出到一个 excel 文件中,并且在我需要使用 PHPExcel_RichText() 之前,新行效果很好。在同一个单元格中获得不同的格式。有没有办法解决? (我知道 PHPspreadsheet 可用,但我必须使用 PHPExcel)。我发现了一些关于类似问题的线程,但不幸的是没有解决方案。

$objRichText = new PHPExcel_RichText();

$run1 = $objRichText->createTextRun("Line one\n this does not work");
$run1->getFont()->applyFromArray(array( "bold" => true, "size" => 24, "name" => "Calibri", "color" => array("rgb" => "333333")));

$objRichText->createText("\n this does not work either \r\n and not this");

$run2 = $objRichText->createTextRun("Line two");
$run2->getFont()->applyFromArray(array( "bold" => true, "size" => 16, "name" => "Calibri", "color" => array("rgb" => "333333")));

$objWorksheet->setCellValueByColumnAndRow(0, 1, $objRichText);

最佳答案

试用 PHP_EOL而不是 '\n' 为我解决了这个问题

$objRichText->createText(PHP_EOL);
  • DOS - 使用 CR+LF(即 ASCII 13 后跟 ASCII 10,或 \r\n)来表示新行。
  • Unix - 使用 LF(即 ASCII 10,或 \n)来表示新行。
  • Mac (pre-OS X) - 使用 CR(即 ASCII 13 或 \r )来表示新行。
  • Mac (OS X) - 与 Unix 一样,使用 LF 来表示新行。
  • PHP_EOL将自动为平台选择正确的字符,以便您的新行与平台无关。

    关于php - 使用 PHPExcel_RichText() 不显示换行符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59328377/

    28 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com