Return-Path: X-Original-To: apmail-tika-commits-archive@www.apache.org Delivered-To: apmail-tika-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 8C0E29FE0 for ; Tue, 20 Dec 2011 06:45:07 +0000 (UTC) Received: (qmail 29340 invoked by uid 500); 20 Dec 2011 06:45:06 -0000 Delivered-To: apmail-tika-commits-archive@tika.apache.org Received: (qmail 29300 invoked by uid 500); 20 Dec 2011 06:45:05 -0000 Mailing-List: contact commits-help@tika.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@tika.apache.org Delivered-To: mailing list commits@tika.apache.org Received: (qmail 29289 invoked by uid 99); 20 Dec 2011 06:45:03 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 20 Dec 2011 06:45:03 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 20 Dec 2011 06:45:00 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 12730238889B; Tue, 20 Dec 2011 06:44:39 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1221119 - /tika/trunk/tika-parsers/src/main/java/org/apache/tika/parser/microsoft/ExcelExtractor.java Date: Tue, 20 Dec 2011 06:44:38 -0000 To: commits@tika.apache.org From: nick@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20111220064439.12730238889B@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: nick Date: Tue Dec 20 06:44:38 2011 New Revision: 1221119 URL: http://svn.apache.org/viewvc?rev=1221119&view=rev Log: TIKA-816 The Excel (XLS) Parser should format numeric formula cell values, and handle string formula cell values Modified: tika/trunk/tika-parsers/src/main/java/org/apache/tika/parser/microsoft/ExcelExtractor.java Modified: tika/trunk/tika-parsers/src/main/java/org/apache/tika/parser/microsoft/ExcelExtractor.java URL: http://svn.apache.org/viewvc/tika/trunk/tika-parsers/src/main/java/org/apache/tika/parser/microsoft/ExcelExtractor.java?rev=1221119&r1=1221118&r2=1221119&view=diff ============================================================================== --- tika/trunk/tika-parsers/src/main/java/org/apache/tika/parser/microsoft/ExcelExtractor.java (original) +++ tika/trunk/tika-parsers/src/main/java/org/apache/tika/parser/microsoft/ExcelExtractor.java Tue Dec 20 06:44:38 2011 @@ -51,6 +51,7 @@ import org.apache.poi.hssf.record.Number import org.apache.poi.hssf.record.RKRecord; import org.apache.poi.hssf.record.Record; import org.apache.poi.hssf.record.SSTRecord; +import org.apache.poi.hssf.record.StringRecord; import org.apache.poi.hssf.record.TextObjectRecord; import org.apache.poi.hssf.record.chart.SeriesTextRecord; import org.apache.poi.hssf.record.common.UnicodeString; @@ -181,6 +182,7 @@ public class ExcelExtractor extends Abst private Exception exception = null; private SSTRecord sstRecord; + private FormulaRecord stringFormulaRecord; private short previousSid; @@ -274,6 +276,7 @@ public class ExcelExtractor extends Abst hssfRequest.addListener(formatListener, LabelSSTRecord.sid); hssfRequest.addListener(formatListener, NumberRecord.sid); hssfRequest.addListener(formatListener, RKRecord.sid); + hssfRequest.addListener(formatListener, StringRecord.sid); hssfRequest.addListener(formatListener, HyperlinkRecord.sid); hssfRequest.addListener(formatListener, TextObjectRecord.sid); hssfRequest.addListener(formatListener, SeriesTextRecord.sid); @@ -375,7 +378,22 @@ public class ExcelExtractor extends Abst case FormulaRecord.sid: // Cell value from a formula FormulaRecord formula = (FormulaRecord) record; - addCell(record, new NumberCell(formula.getValue(), format)); + if (formula.hasCachedResultString()) { + // The String itself should be the next record + stringFormulaRecord = formula; + } else { + addTextCell(record, formatListener.formatNumberDateCell(formula)); + } + break; + + case StringRecord.sid: + if (previousSid == FormulaRecord.sid) { + // Cached string value of a string formula + StringRecord sr = (StringRecord) record; + addTextCell(stringFormulaRecord, sr.getString()); + } else { + // Some other string not associated with a cell, skip + } break; case LabelRecord.sid: // strings stored directly in the cell @@ -435,6 +453,10 @@ public class ExcelExtractor extends Abst } previousSid = record.getSid(); + + if (stringFormulaRecord != record) { + stringFormulaRecord = null; + } } private void processExtraText() throws SAXException {