tika-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ASF GitHub Bot (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (TIKA-2479) Handle empty cells in tables uniformly
Date Tue, 30 Oct 2018 00:25:00 GMT

    [ https://issues.apache.org/jira/browse/TIKA-2479?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16667929#comment-16667929
] 

ASF GitHub Bot commented on TIKA-2479:
--------------------------------------

glb closed pull request #214: TIKA-2479 - Handle empty cells in XLSX
URL: https://github.com/apache/tika/pull/214
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/tika-parsers/src/main/java/org/apache/tika/parser/microsoft/ooxml/XSSFExcelExtractorDecorator.java
b/tika-parsers/src/main/java/org/apache/tika/parser/microsoft/ooxml/XSSFExcelExtractorDecorator.java
index c3b7285403..2264457f37 100644
--- a/tika-parsers/src/main/java/org/apache/tika/parser/microsoft/ooxml/XSSFExcelExtractorDecorator.java
+++ b/tika-parsers/src/main/java/org/apache/tika/parser/microsoft/ooxml/XSSFExcelExtractorDecorator.java
@@ -16,7 +16,6 @@
  */
 package org.apache.tika.parser.microsoft.ooxml;
 
-import javax.xml.parsers.SAXParser;
 import java.io.IOException;
 import java.io.InputStream;
 import java.util.ArrayList;
@@ -25,7 +24,8 @@
 import java.util.Locale;
 import java.util.Map;
 
-import org.apache.poi.POIXMLDocument;
+import javax.xml.parsers.SAXParser;
+
 import org.apache.poi.POIXMLTextExtractor;
 import org.apache.poi.hssf.extractor.ExcelExtractor;
 import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
@@ -39,6 +39,8 @@
 import org.apache.poi.openxml4j.opc.TargetMode;
 import org.apache.poi.ss.usermodel.DataFormatter;
 import org.apache.poi.ss.usermodel.HeaderFooter;
+import org.apache.poi.ss.util.CellAddress;
+import org.apache.poi.ss.util.CellReference;
 import org.apache.poi.xssf.eventusermodel.ReadOnlySharedStringsTable;
 import org.apache.poi.xssf.eventusermodel.XSSFReader;
 import org.apache.poi.xssf.eventusermodel.XSSFSheetXMLHandler;
@@ -400,6 +402,8 @@ public void processSheet(
         private final boolean includeHeadersFooters;
         protected List<String> headers;
         protected List<String> footers;
+        private int currentRow = -1;
+        private int currentCol = -1;
 
         protected SheetTextAsHTML(boolean includeHeaderFooters, XHTMLContentHandler xhtml)
{
             this.includeHeadersFooters = includeHeaderFooters;
@@ -408,7 +412,24 @@ protected SheetTextAsHTML(boolean includeHeaderFooters, XHTMLContentHandler
xhtm
             footers = new ArrayList<String>();
         }
 
+        private void outputMissingRows(int number) {
+            for (int i=0; i<number; i++) {
+                try {
+                    xhtml.startElement("tr");
+                    xhtml.endElement("tr");
+                } catch (SAXException e) {
+                }
+            }
+        }
+
         public void startRow(int rowNum) {
+            // If there were gaps, output the missing rows
+            outputMissingRows(rowNum-currentRow-1);
+
+            // Prepare for this row
+            currentRow = rowNum;
+            currentCol = -1;
+
             try {
                 xhtml.startElement("tr");
             } catch (SAXException e) {
@@ -423,7 +444,22 @@ public void endRow(int rowNum) {
         }
 
         public void cell(String cellRef, String formattedValue, XSSFComment comment) {
+            // gracefully handle missing CellRef here in a similar way as XSSFCell does
+            if (cellRef == null) {
+                cellRef = new CellAddress(currentRow, currentCol).formatAsString();
+            }
+
             try {
+                // Did we miss any cells?
+                int thisCol = (new CellReference(cellRef)).getCol();
+                int missedCols = thisCol - currentCol - 1;
+
+                for (int i=0; i<missedCols; i++) {
+                        xhtml.startElement("td");
+                        xhtml.endElement("td");
+                }
+                currentCol = thisCol;
+
                 xhtml.startElement("td");
 
                 // Main cell contents


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


> Handle empty cells in tables uniformly
> --------------------------------------
>
>                 Key: TIKA-2479
>                 URL: https://issues.apache.org/jira/browse/TIKA-2479
>             Project: Tika
>          Issue Type: Bug
>            Reporter: Tim Allison
>            Priority: Minor
>             Fix For: 2.0, 1.19
>
>         Attachments: patch.diff
>
>
> It looks like we output a <td/> for empty cells in xls, and tables in doc, docx
and pptx.  However, we don't retain empty cells in xlsx or tables in ppt.  We should make
this handling uniform.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Mime
View raw message