使用 POI 事件 api 检索单元格样式信息(特别是颜色) [英] Retrieving cell style information(specifically color) using POI event api

查看:28
本文介绍了使用 POI 事件 api 检索单元格样式信息(特别是颜色)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个使用 POI 和 java 读取现有 xls 文件(我们不控制文件创建)的 Web 应用程序.

上传的文件很大,所以目标是使用事件驱动的 excel 解析 API.

我找不到任何 API 来使用事件驱动方法访问单元格颜色.

然而,上传的 excel 有一些基于单元格颜色的逻辑.

有人知道我该怎么做吗?

谢谢!

解决方案

您可能需要一个 FormatTrackingHSSFListener - 它会在记录经过时抓取适当的格式和样式记录.当事件 API 为您提供单元格记录时,您将能够使用格式化侦听器来获取样式.

如果您查看来自 Apache Tika 的 ExcelExtractor,您将看到一个示例,该示例使用 FormatTrackingHSSFListener 根据该单元格样式中应用的格式获取单元格样式和格式编号:https://svn.apache.org/repos/asf/tika/trunk/tika-parsers/src/main/java/org/apache/tika/parser/microsoft/ExcelExtractor.java>

对于颜色,您需要使用类似的东西 - ExtendedFormatRecords 保存颜色索引.

Am trying to create a web application which reads an existing xls file(we do not control file creation ) using POI and java.

The size of the uploaded file is quite large so the goal is to use event driven excel parsing APIs.

I was not able to find any API to access cell colors using the event driven approach.

However the uploaded excels have some logic based on the cell colors.

Any one has an idea how I can go about it?

Thanks!

解决方案

You probably want a FormatTrackingHSSFListener - that will grab the appropriate formatting and style records as they go past. When you the event API gives you a cell record, you'll be able to use the formatting listener to get at the style.

If you look at ExcelExtractor from Apache Tika, you'll see an example of using a FormatTrackingHSSFListener to get the cell style and format numbers based on the format applied in that cell style: https://svn.apache.org/repos/asf/tika/trunk/tika-parsers/src/main/java/org/apache/tika/parser/microsoft/ExcelExtractor.java

For colours you'll want to use something similar - the ExtendedFormatRecords hold the colour indexes.

这篇关于使用 POI 事件 api 检索单元格样式信息(特别是颜色)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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