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 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?