aboutsummaryrefslogtreecommitdiffstats
path: root/src/testcases/org/apache/poi/hssf/eventusermodel
diff options
context:
space:
mode:
authorNick Burch <nick@apache.org>2008-04-09 15:36:39 +0000
committerNick Burch <nick@apache.org>2008-04-09 15:36:39 +0000
commit2b4a6011f17182709390c42cdc4e41aa983b43bc (patch)
tree24e439aa01a7edc62fdcff02019c461f56b40a00 /src/testcases/org/apache/poi/hssf/eventusermodel
parent40b5fb8af8a468a8f5583a812ccf3e7317eb9d8a (diff)
downloadpoi-2b4a6011f17182709390c42cdc4e41aa983b43bc.tar.gz
poi-2b4a6011f17182709390c42cdc4e41aa983b43bc.zip
Implement a proxy HSSFListener which tracks the format records, and lets you lookup the format string for a given cell. Convert the xls to csv example to use it
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@646405 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/testcases/org/apache/poi/hssf/eventusermodel')
-rw-r--r--src/testcases/org/apache/poi/hssf/eventusermodel/TestFormatTrackingHSSFListener.java65
1 files changed, 65 insertions, 0 deletions
diff --git a/src/testcases/org/apache/poi/hssf/eventusermodel/TestFormatTrackingHSSFListener.java b/src/testcases/org/apache/poi/hssf/eventusermodel/TestFormatTrackingHSSFListener.java
new file mode 100644
index 0000000000..e52a3bc961
--- /dev/null
+++ b/src/testcases/org/apache/poi/hssf/eventusermodel/TestFormatTrackingHSSFListener.java
@@ -0,0 +1,65 @@
+/* ====================================================================
+ 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.eventusermodel;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+import org.apache.poi.hssf.HSSFTestDataSamples;
+import org.apache.poi.hssf.record.Record;
+import org.apache.poi.poifs.filesystem.POIFSFileSystem;
+/**
+ * Tests for FormatTrackingHSSFListener
+ */
+public final class TestFormatTrackingHSSFListener extends TestCase {
+ private FormatTrackingHSSFListener listener;
+
+ public void setUp() {
+ HSSFRequest req = new HSSFRequest();
+ MockHSSFListener mockListen = new MockHSSFListener();
+ listener = new FormatTrackingHSSFListener(mockListen);
+ req.addListenerForAllRecords(listener);
+
+ HSSFEventFactory factory = new HSSFEventFactory();
+ try {
+ InputStream is = HSSFTestDataSamples.openSampleFileStream("MissingBits.xls");
+ POIFSFileSystem fs = new POIFSFileSystem(is);
+ factory.processWorkbookEvents(req, fs);
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public void testFormats() throws Exception {
+ assertEquals("_(*#,##0_);_(*(#,##0);_(* \"-\"_);_(@_)", listener.getFormatString(41));
+ assertEquals("_($*#,##0_);_($*(#,##0);_($* \"-\"_);_(@_)", listener.getFormatString(42));
+ assertEquals("_(*#,##0.00_);_(*(#,##0.00);_(*\"-\"??_);_(@_)", listener.getFormatString(43));
+ }
+
+ private static final class MockHSSFListener implements HSSFListener {
+ public MockHSSFListener() {}
+ private final List _records = new ArrayList();
+
+ public void processRecord(Record record) {
+ _records.add(record);
+ }
+ }
+} \ No newline at end of file