PHPexcel无法从xls读取样式 [英] PHPexcel cannot reads styles from xls

查看:278
本文介绍了PHPexcel无法从xls读取样式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法通过PHPexcel从xls读取样式.我浏览了很多解决方案,但是到处都有写xls的解决方案,但是我喜欢阅读. 我特别喜欢删除线,但是它既不读取此样式信息也不读取任何其他样式信息. 我的代码如下,它可以正确读取所有数据,仅此而已.我一定要在xls中设置文本样式.

I cannot read styles from xls by PHPexcel. I browsing for a solution a lot but everywhere writes solutions for write xls but I like it to read. I like especially strikethrough but it cannot reads neither this nor any other style informations. My code is the following, this reads all data correctly but nothing more. Im sure to make text styled in the xls.

require_once 'PHPExcel.php';
$filepath = "path/to/your/xls/file.xls";
$inputFileType = PHPExcel_IOFactory::identify($filepath);

$objReader = PHPExcel_IOFactory::createReader($inputFileType);
$objPHPExcel = $objReader->load($filepath);

$total_sheets = $objPHPExcel->getSheetCount();
$allSheetName = $objPHPExcel->getSheetNames(); 
$objWorksheet = $objPHPExcel->setActiveSheetIndex(0) ;
$highestRow = $objWorksheet->getHighestRow();
$highestColumn = $objWorksheet->getHighestColumn();
$highestColumnIndex = PHPExcel_Cell::columnIndexFromString($highestColumn);

$headingsArray = $objWorksheet->rangeToArray('A1:' . $highestColumn . '1', null, true, true, true);
$headingsArray = $headingsArray[1];

print_r( $objWorksheet->toArray() );

有人有主意吗?

thx

推荐答案

PHPExcel完全能够从xls文件读取样式:您是否真的尝试过从单元格获取样式详细信息,因为此处的代码未显示任何测试检查样式是否已阅读?

PHPExcel is perfectly capable of reading styles from xls files: have you actually tried getting the style details from a cell, because your code here doesn't show any tests to check that styles have been read?

$objWorksheet->toArray()

从单元格中读取内容作为简单的PHP标量值.

reads the content from cells as simple PHP scalar values.

要确定单元格的样式,您需要阅读该单元格的样式详细信息.

To determin the styling of a cell, you need to read that cell's style details.

例如

$cellHasStrikeThrough = $objPHPExcel->getActiveSheet()->getStyle('B2')
    ->getFont()->getStrikethrough();

API文档显示了读取样式信息的所有详细信息,例如颜色,填充,字体,边框等

The API documentation shows all the details for reading style information such as colours, fills, fonts, borders, etc

编辑

一个单元格的包含也可能是富文本,内容的不同部分具有不同的样式.如果您使用

A cell's contain may also be rich text, with different parts of the content having different styles. If you retrieve a rich text value from a cell using

$objPHPExcel->getActiveSheet()->getCellValue('B2');

富文本对象将被返回.然后可以遍历RichText对象的每个块(或运行),检查该块的样式

a richtext object will be returned. It is then possible to iterate through each block (or run) of the richtext object checking the style for that block

这篇关于PHPexcel无法从xls读取样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆