diff options
author | Nick Burch <nick@apache.org> | 2007-10-27 21:57:10 +0000 |
---|---|---|
committer | Nick Burch <nick@apache.org> | 2007-10-27 21:57:10 +0000 |
commit | 6a72c5656aa8a5e70ead0c4a00d41c9c81b171cc (patch) | |
tree | 2c1df72a8ea77148a2b332fce89fef79343833f7 /src/testcases | |
parent | 6a4d5c5a7536699b652c098e77e667b95471f741 (diff) | |
download | poi-6a72c5656aa8a5e70ead0c4a00d41c9c81b171cc.tar.gz poi-6a72c5656aa8a5e70ead0c4a00d41c9c81b171cc.zip |
Implement an Excel text extractor, and put all the existing text extractors under a common superclass, so they're easier to find and use
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@589224 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/testcases')
-rw-r--r-- | src/testcases/org/apache/poi/hssf/extractor/TestExcelExtractor.java | 101 |
1 files changed, 101 insertions, 0 deletions
diff --git a/src/testcases/org/apache/poi/hssf/extractor/TestExcelExtractor.java b/src/testcases/org/apache/poi/hssf/extractor/TestExcelExtractor.java new file mode 100644 index 0000000000..027495a1b0 --- /dev/null +++ b/src/testcases/org/apache/poi/hssf/extractor/TestExcelExtractor.java @@ -0,0 +1,101 @@ +/* ==================================================================== + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +==================================================================== */ +package org.apache.poi.hssf.extractor; + +import java.io.File; +import java.io.FileInputStream; + +import org.apache.poi.poifs.filesystem.POIFSFileSystem; + +import junit.framework.TestCase; + +public class TestExcelExtractor extends TestCase { + public void testSimple() throws Exception { + String path = System.getProperty("HSSF.testdata.path"); + FileInputStream fin = new FileInputStream(path + File.separator + "Simple.xls"); + + ExcelExtractor extractor = new ExcelExtractor(new POIFSFileSystem(fin)); + + assertEquals("Sheet1\nreplaceMe\nSheet2\nSheet3\n", extractor.getText()); + + // Now turn off sheet names + extractor.setIncludeSheetNames(false); + assertEquals("replaceMe\n", extractor.getText()); + } + + public void testNumericFormula() throws Exception { + String path = System.getProperty("HSSF.testdata.path"); + FileInputStream fin = new FileInputStream(path + File.separator + "sumifformula.xls"); + + ExcelExtractor extractor = new ExcelExtractor(new POIFSFileSystem(fin)); + + assertEquals( + "Sheet1\n" + + "1000.0\t1.0\t5.0\n" + + "2000.0\t2.0\t\n" + + "3000.0\t3.0\t\n" + + "4000.0\t4.0\t\n" + + "5000.0\t5.0\t\n" + + "Sheet2\nSheet3\n", + extractor.getText() + ); + + extractor.setFormulasNotResults(true); + + assertEquals( + "Sheet1\n" + + "1000.0\t1.0\tSUMIF(A1:A5,\">4000\",B1:B5)\n" + + "2000.0\t2.0\t\n" + + "3000.0\t3.0\t\n" + + "4000.0\t4.0\t\n" + + "5000.0\t5.0\t\n" + + "Sheet2\nSheet3\n", + extractor.getText() + ); + } + + + public void testStringConcat() throws Exception { + String path = System.getProperty("HSSF.testdata.path"); + FileInputStream fin = new FileInputStream(path + File.separator + "SimpleWithFormula.xls"); + + ExcelExtractor extractor = new ExcelExtractor(new POIFSFileSystem(fin)); + + // Comes out as NaN if treated as a number + // And as XYZ if treated as a string + assertEquals("Sheet1\nreplaceme\nreplaceme\nreplacemereplaceme\nSheet2\nSheet3\n", extractor.getText()); + + extractor.setFormulasNotResults(true); + + assertEquals("Sheet1\nreplaceme\nreplaceme\nCONCATENATE(A1,A2)\nSheet2\nSheet3\n", extractor.getText()); + } + + public void testStringFormula() throws Exception { + String path = System.getProperty("HSSF.testdata.path"); + FileInputStream fin = new FileInputStream(path + File.separator + "StringFormulas.xls"); + + ExcelExtractor extractor = new ExcelExtractor(new POIFSFileSystem(fin)); + + // Comes out as NaN if treated as a number + // And as XYZ if treated as a string + assertEquals("Sheet1\nXYZ\nSheet2\nSheet3\n", extractor.getText()); + + extractor.setFormulasNotResults(true); + + assertEquals("Sheet1\nUPPER(\"xyz\")\nSheet2\nSheet3\n", extractor.getText()); + } +} |