使用POI事件API获取单元格样式信息(特别色) [英] Retrieving cell style information(specifically color) using POI event api
问题描述
想创建一个Web应用程序其内容的现有xls文件(我们不控制文件的创建),使用POI和Java。
Am trying to create a web application which reads an existing xls file(we do not control file creation ) using POI and java.
上传文件的大小是相当大的所以目标是使用事件驱动的Excel解析API。
The size of the uploaded file is quite large so the goal is to use event driven excel parsing APIs.
我无法找到任何API使用事件驱动的方式来访问单元格的颜色。
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?
谢谢!
推荐答案
您可能需要一个FormatTrackingHSSFListener - 因为他们去过去那种将抓住适当的格式和样式记录。当您在事件API给你一个单元格的记录,你就可以使用的格式监听得到的风格。
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.
如果你看一下ExcelExtractor来自Apache提卡,你会看到使用FormatTrackingHSSFListener基于在该单元格样式应用的格式来获取单元格样式和格式数的例子:
<一href=\"https://svn.apache.org/repos/asf/tika/trunk/tika-parsers/src/main/java/org/apache/tika/parser/microsoft/ExcelExtractor.java\" rel=\"nofollow\">https://svn.apache.org/repos/asf/tika/trunk/tika-parsers/src/main/java/org/apache/tika/parser/microsoft/ExcelExtractor.java
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
有关的颜色,你会想使用类似的东西 - 在ExtendedFormatRecords保持颜色索引
For colours you'll want to use something similar - the ExtendedFormatRecords hold the colour indexes.
这篇关于使用POI事件API获取单元格样式信息(特别色)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!