doujiao9574 2014-09-17 21:34
浏览 386
已采纳

PHP:使用换行符处理Excel单元格

I'm building Excel template to get data about products from our users. The problem is that there are certain fields number of which can vary.

For example, product can have 1 contributor or 12 contributors. Each contributor have the following fields:

  • key name
  • name before key
  • role
  • biography

I don't think is good idea to include 12 * 4 columns to Excel template, because on the next day user can send product which has 13 contributors.

I decided that I will include data about all contributors in one cell, for example in cell "Contributor Key Name" I will have name of all product contributors, in cell "Contributor Role" I will have roles of all contributors etc.

I wanted to divide contributors data by new line symbol. I created Excel table with the following data:

enter image description here

The problem is that when I read value of these cells ("Contributor Key Name" for example) in PHP I don't see new line symbol. Instead I receive string with strange characters:

enter image description here

I tried to do

explode('
',$cellValue);

but it doesn't work.

I use PHPExcel library for working with table.

My question is - how new line symbol is encoded in Excel? What would you recommend to use as delimiter in Excel cells?

UPD:

So, in order to divide strings by new line character you should use " " as delimiter.

I think, that strange symbols appeared in my string because initially I created table in Numbers app and then export to xslx format. (Numbers has some problem with new line character during export)

  • 写回答

1条回答 默认 最新

  • douhui1630 2014-09-17 22:02
    关注

    In PHP, ' ' (in single quotes) is a literal \ character followed by a literal n character. " " (in double quotes) is a newline character

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失
  • ¥15 统计大规模图中的完全子图问题
  • ¥15 使用LM2596制作降压电路,一个能运行,一个不能
  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗
  • ¥15 ikuai客户端l2tp协议链接报终止15信号和无法将p.p.p6转换为我的l2tp线路
  • ¥15 phython读取excel表格报错 ^7个 SyntaxError: invalid syntax 语句报错
  • ¥20 @microsoft/fetch-event-source 流式响应问题