小编aut*_*tle的帖子

PhpExcel单元格中的新行

我所做的:

  1. 从db查询数据
  2. 分解数据并插入\n
  3. 准备数组
  4. 打开模板
  5. 将数组插入到模板中
  6. 尝试用新行替换 \n

如何找到 \n 并插入新行?例如,我在 A1 中有下一个文本“One\nTwo”。我从 A1 读取文本

$ltr='A1';
$vle=$spreadsheet->getActiveSheet()->getCell($ltr);
Run Code Online (Sandbox Code Playgroud)

在此之后,我尝试在 A1 中再次在 A1 中插入文本并将 \n 替换为一个单元格中的新行

$spreadsheet->getActiveSheet()->getCell($ltr)->setValue("${vle}");
$spreadsheet->getActiveSheet()->getStyle($ltr)->getAlignment()->setWrapText(true);
Run Code Online (Sandbox Code Playgroud)

但这对我不起作用。

例如: 在此处输入图片说明

因此,如果我打开带有文本的模板,则无法替换单元格中的 \n。我能做什么?

更新。我尝试使用 char(10) 并插入公式(例如)="hello"&char(10)&"world"但仅插入="hello"&char(10)

php phpexcel phpoffice

1
推荐指数
1
解决办法
9560
查看次数

标签 统计

php ×1

phpexcel ×1

phpoffice ×1