dpfz27768 2017-05-07 17:10
浏览 30
已采纳

PhpExcel新细胞系

What I do:

  1. query data from db
  2. explode data and insert
  3. prepare array
  4. open tamplate
  5. insert array into tamplate
  6. try to replace with new line

How can I found and insert new line? For example I have in A1 next text "One Two". I read text from A1

$ltr='A1';
$vle=$spreadsheet->getActiveSheet()->getCell($ltr);

After this I try to insert text in A1 again in A1 and replace with new line in one cell

$spreadsheet->getActiveSheet()->getCell($ltr)->setValue("${vle}");
$spreadsheet->getActiveSheet()->getStyle($ltr)->getAlignment()->setWrapText(true);

But it does not work for my.

For example: enter image description here

So, if I open tamplate with text I can't replace in cells. What can I do?

Upd. I try use char(10) and insert formula (for example) ="hello"&char(10)&"world" But inserted only ="hello"&char(10)

  • 写回答

3条回答 默认 最新

  • duanmao9918 2017-05-08 08:58
    关注

    If you're asking about this issue on the PHPspreadsheet github issues log then this is a problem with your understanding of PHP strings.

    $dataArray = [
        ['2010', 'Q1', 'United
    States', 790],
        ['2010', 'Q2', 'United States', 730],
        ['2010', 'Q3', 'United States', 860]
    ]
    

    A ' ' in single quotes is treated as a literal ; a " " in double quotes is treated as a new line character. So either build your array using double quotes:

    $dataArray = [
        ['2010', 'Q1', "United
    States", 790],
        ['2010', 'Q2', "United States", 730],
        ['2010', 'Q3', "United States", 860]
    ]
    

    or convert the literal to a new line using str_replace:

    $modified = str_replace('
    ', "
    ", $original);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 unity第一人称射击小游戏,有demo,在原脚本的基础上进行修改以达到要求
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染