2007-06-17 06:59:48 -04:00
|
|
|
/* ====================================================================
|
|
|
|
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.
|
|
|
|
==================================================================== */
|
2008-09-19 12:47:18 -04:00
|
|
|
|
2007-06-17 06:59:48 -04:00
|
|
|
package org.apache.poi.hssf.eventusermodel.examples;
|
|
|
|
|
|
|
|
import java.io.FileInputStream;
|
|
|
|
import java.io.FileNotFoundException;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.PrintStream;
|
|
|
|
|
Merged revisions 638786-638802,638805-638811,638813-638814,638816-639230,639233-639241,639243-639253,639255-639486,639488-639601,639603-639835,639837-639917,639919-640056,640058-640710,640712-641156,641158-641184,641186-641795,641797-641798,641800-641933,641935-641963,641965-641966,641968-641995,641997-642230,642232-642562,642564-642565,642568-642570,642572-642573,642576-642736,642739-642877,642879,642881-642890,642892-642903,642905-642945,642947-643624,643626-643653,643655-643669,643671,643673-643830,643832-643833,643835-644342,644344-644472,644474-644508,644510-645347,645349-645351,645353-645559,645561-645565,645568-645951,645953-646193,646195-646311,646313-646820 via svnmerge from
https://svn.apache.org:443/repos/asf/poi/trunk
........
r646405 | nick | 2008-04-09 16:36:39 +0100 (Wed, 09 Apr 2008) | 1 line
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
........
r646666 | josh | 2008-04-10 08:06:55 +0100 (Thu, 10 Apr 2008) | 1 line
bugzilla 44792 - fixed encode/decode problems in ExternalNameRecord and CRNRecord.
........
git-svn-id: https://svn.apache.org/repos/asf/poi/branches/ooxml@646826 13f79535-47bb-0310-9956-ffa450edef68
2008-04-10 10:43:24 -04:00
|
|
|
import org.apache.poi.hssf.eventusermodel.FormatTrackingHSSFListener;
|
2007-06-17 06:59:48 -04:00
|
|
|
import org.apache.poi.hssf.eventusermodel.HSSFEventFactory;
|
|
|
|
import org.apache.poi.hssf.eventusermodel.HSSFListener;
|
|
|
|
import org.apache.poi.hssf.eventusermodel.HSSFRequest;
|
|
|
|
import org.apache.poi.hssf.eventusermodel.MissingRecordAwareHSSFListener;
|
Merged revisions 638786-638802,638805-638811,638813-638814,638816-639230,639233-639241,639243-639253,639255-639486,639488-639601,639603-639835,639837-639917,639919-640056,640058-640710,640712-641156,641158-641184,641186-641795,641797-641798,641800-641933,641935-641963,641965-641966,641968-641995,641997-642230,642232-642562,642564-642565,642568-642570,642572-642573,642576-642736,642739-642877,642879,642881-642890,642892-642903,642905-642945,642947-643624,643626-643653,643655-643669,643671,643673-643830,643832-643833,643835-644342,644344-644472,644474-644508,644510-645347,645349-645351,645353-645559,645561-645565,645568-645951,645953-646193,646195-646311,646313-646404,646406-646665,646667-646853,646855-646869,646871-647151,647153-647185,647187-647277,647279-647566,647568-647573,647575,647578-647711,647714-647737,647739-647823,647825-648155,648157-648202,648204-648273,648275,648277-648302,648304-648333,648335-648588,648590-648622,648625-648673,648675-649141,649144,649146-649556,649558-649795,649799,649801-649910,649912-649913,649915-650128,650131-650132,650134-650137,650140-650914,650916-651991,651993-652284,652286-652287,652289,652291,652293-652297,652299-652328,652330-652425,652427-652445,652447-652560,652562-652933,652935,652937-652993,652995-653116,653118-653124,653126-653483,653487-653519,653522-653550,653552-653607,653609-653667,653669-653674,653676-653814,653817-653830,653832-653891,653893-653944,653946-654055,654057-654355,654357-654365,654367-654648,654651-655215,655217-655277,655279-655281,655283-655911,655913-656212,656214,656216-656251,656253-656698,656700-656756,656758-656892,656894-657135,657137-657165,657168-657179,657181-657354,657356-657357,657359-657701,657703-657874,657876-658032,658034-658284,658286,658288-658301,658303-658307,658309-658321,658323-658335,658337-658348,658351,658353-658832,658834-658983,658985,658987-659066,659068-659402,659404-659428,659430-659451,659453-659454,659456-659461,659463-659477,659479-659524,659526-659571,659574,659576-660255,660257-660262,660264-660279,660281-660343,660345-660473,660475-660827,660829-660833,660835-660888,660890-663321,663323-663435,663437-663764,663766-663854,663856-664219,664221-664489,664494-664514,664516-668013,668015-668142,668144-668152,668154,668156-668256,668258,668260-669139,669141-669455,669457-669657,669659-669808,669810-670189,670191-674287 via svnmerge from
https://svn.apache.org/repos/asf/poi/trunk
........
r671322 | nick | 2008-06-24 20:53:53 +0100 (Tue, 24 Jun 2008) | 1 line
Make a start on being able to process formulas in the eventusermodel code
........
r672230 | nick | 2008-06-27 11:12:11 +0100 (Fri, 27 Jun 2008) | 1 line
Add MethodNotFound exceptions to the faq
........
r672550 | nick | 2008-06-28 18:04:09 +0100 (Sat, 28 Jun 2008) | 1 line
Finish the EventWorkbookBuilder, now does sheet references in formulas properly
........
r672553 | nick | 2008-06-28 18:12:38 +0100 (Sat, 28 Jun 2008) | 1 line
Update changelog about EventWorkbookBuilder, and tweak XLS2CSVmra to use it if formulas required
........
r672562 | nick | 2008-06-28 19:21:21 +0100 (Sat, 28 Jun 2008) | 1 line
Avoid spurious missing lines with the MissingRecordAware event code, and odd files that contain RowRecords in the middle of the cell Records.
........
r672567 | nick | 2008-06-28 19:48:35 +0100 (Sat, 28 Jun 2008) | 1 line
Patch from dnapoletano from bug #45175 - Support for variable length operands in org.apache.poi.hwpf.sprm.SprmOperation
........
r672569 | nick | 2008-06-28 19:54:02 +0100 (Sat, 28 Jun 2008) | 1 line
Patch from N. Hira from bug #45001 - Further fix for HWPF Range.delete() and unicode characters
........
r672570 | nick | 2008-06-28 19:58:23 +0100 (Sat, 28 Jun 2008) | 1 line
Patch from N.Hira from bug #45252 - Improvement for HWPF Range.replaceText()
........
r673050 | yegor | 2008-07-01 11:32:29 +0100 (Tue, 01 Jul 2008) | 1 line
updated status of the latest release, 3.1-FINAL
........
r673853 | josh | 2008-07-03 23:20:18 +0100 (Thu, 03 Jul 2008) | 1 line
Fix for bug 45334 - formula parser needs to handle dots in identifiers
........
r673863 | josh | 2008-07-04 00:09:08 +0100 (Fri, 04 Jul 2008) | 1 line
Fix for bug 45334 - added impl for ERROR.TYPE()
........
r673987 | nick | 2008-07-04 10:58:21 +0100 (Fri, 04 Jul 2008) | 1 line
Fix bug #45336 - Fix HSSFColor.getTripletHash()
........
r673997 | nick | 2008-07-04 11:46:59 +0100 (Fri, 04 Jul 2008) | 1 line
Fix bug #45338 - Fix HSSFWorkbook to give you the same HSSFFont every time, and then fix it to find newly added fonts
........
git-svn-id: https://svn.apache.org/repos/asf/poi/branches/ooxml@674296 13f79535-47bb-0310-9956-ffa450edef68
2008-07-06 09:10:09 -04:00
|
|
|
import org.apache.poi.hssf.eventusermodel.EventWorkbookBuilder.SheetRecordCollectingListener;
|
2007-06-17 06:59:48 -04:00
|
|
|
import org.apache.poi.hssf.eventusermodel.dummyrecord.LastCellOfRowDummyRecord;
|
|
|
|
import org.apache.poi.hssf.eventusermodel.dummyrecord.MissingCellDummyRecord;
|
2008-09-19 12:47:18 -04:00
|
|
|
import org.apache.poi.hssf.model.HSSFFormulaParser;
|
Merged revisions 638786-638802,638805-638811,638813-638814,638816-639230,639233-639241,639243-639253,639255-639486,639488-639601,639603-639835,639837-639917,639919-640056,640058-640710,640712-641156,641158-641184,641186-641795,641797-641798,641800-641933,641935-641963,641965-641966,641968-641995,641997-642230,642232-642562,642564-642565,642568-642570,642572-642573,642576-642736,642739-642877,642879,642881-642890,642892-642903,642905-642945,642947-643624,643626-643653,643655-643669,643671,643673-643830,643832-643833,643835-644342,644344-644472,644474-644508,644510-645347,645349-645351,645353-645559,645561-645565,645568-645951,645953-646193,646195-646311,646313-646404,646406-646665,646667-646853,646855-646869,646871-647151,647153-647185,647187-647277,647279-647566,647568-647573,647575,647578-647711,647714-647737,647739-647823,647825-648155,648157-648202,648204-648273,648275,648277-648302,648304-648333,648335-648588,648590-648622,648625-648673,648675-649141,649144,649146-649556,649558-649795,649799,649801-649910,649912-649913,649915-650128,650131-650132,650134-650137,650140-650914,650916-651991,651993-652284,652286-652287,652289,652291,652293-652297,652299-652328,652330-652425,652427-652445,652447-652560,652562-652933,652935,652937-652993,652995-653116,653118-653124,653126-653483,653487-653519,653522-653550,653552-653607,653609-653667,653669-653674,653676-653814,653817-653830,653832-653891,653893-653944,653946-654055,654057-654355,654357-654365,654367-654648,654651-655215,655217-655277,655279-655281,655283-655911,655913-656212,656214,656216-656251,656253-656698,656700-656756,656758-656892,656894-657135,657137-657165,657168-657179,657181-657354,657356-657357,657359-657701,657703-657874,657876-658032,658034-658284,658286,658288-658301,658303-658307,658309-658321,658323-658335,658337-658348,658351,658353-658832,658834-658983,658985,658987-659066,659068-659402,659404-659428,659430-659451,659453-659454,659456-659461,659463-659477,659479-659524,659526-659571,659574,659576-660255,660257-660262,660264-660279,660281-660343,660345-660473,660475-660827,660829-660833,660835-660888,660890-663321,663323-663435,663437-663764,663766-663854,663856-664219,664221-664489,664494-664514,664516-668013,668015-668142,668144-668152,668154,668156-668256,668258,668260-669139,669141-669455,669457-669657,669659-669808,669810-670189,670191-674287 via svnmerge from
https://svn.apache.org/repos/asf/poi/trunk
........
r671322 | nick | 2008-06-24 20:53:53 +0100 (Tue, 24 Jun 2008) | 1 line
Make a start on being able to process formulas in the eventusermodel code
........
r672230 | nick | 2008-06-27 11:12:11 +0100 (Fri, 27 Jun 2008) | 1 line
Add MethodNotFound exceptions to the faq
........
r672550 | nick | 2008-06-28 18:04:09 +0100 (Sat, 28 Jun 2008) | 1 line
Finish the EventWorkbookBuilder, now does sheet references in formulas properly
........
r672553 | nick | 2008-06-28 18:12:38 +0100 (Sat, 28 Jun 2008) | 1 line
Update changelog about EventWorkbookBuilder, and tweak XLS2CSVmra to use it if formulas required
........
r672562 | nick | 2008-06-28 19:21:21 +0100 (Sat, 28 Jun 2008) | 1 line
Avoid spurious missing lines with the MissingRecordAware event code, and odd files that contain RowRecords in the middle of the cell Records.
........
r672567 | nick | 2008-06-28 19:48:35 +0100 (Sat, 28 Jun 2008) | 1 line
Patch from dnapoletano from bug #45175 - Support for variable length operands in org.apache.poi.hwpf.sprm.SprmOperation
........
r672569 | nick | 2008-06-28 19:54:02 +0100 (Sat, 28 Jun 2008) | 1 line
Patch from N. Hira from bug #45001 - Further fix for HWPF Range.delete() and unicode characters
........
r672570 | nick | 2008-06-28 19:58:23 +0100 (Sat, 28 Jun 2008) | 1 line
Patch from N.Hira from bug #45252 - Improvement for HWPF Range.replaceText()
........
r673050 | yegor | 2008-07-01 11:32:29 +0100 (Tue, 01 Jul 2008) | 1 line
updated status of the latest release, 3.1-FINAL
........
r673853 | josh | 2008-07-03 23:20:18 +0100 (Thu, 03 Jul 2008) | 1 line
Fix for bug 45334 - formula parser needs to handle dots in identifiers
........
r673863 | josh | 2008-07-04 00:09:08 +0100 (Fri, 04 Jul 2008) | 1 line
Fix for bug 45334 - added impl for ERROR.TYPE()
........
r673987 | nick | 2008-07-04 10:58:21 +0100 (Fri, 04 Jul 2008) | 1 line
Fix bug #45336 - Fix HSSFColor.getTripletHash()
........
r673997 | nick | 2008-07-04 11:46:59 +0100 (Fri, 04 Jul 2008) | 1 line
Fix bug #45338 - Fix HSSFWorkbook to give you the same HSSFFont every time, and then fix it to find newly added fonts
........
git-svn-id: https://svn.apache.org/repos/asf/poi/branches/ooxml@674296 13f79535-47bb-0310-9956-ffa450edef68
2008-07-06 09:10:09 -04:00
|
|
|
import org.apache.poi.hssf.record.BOFRecord;
|
2007-06-17 06:59:48 -04:00
|
|
|
import org.apache.poi.hssf.record.BlankRecord;
|
|
|
|
import org.apache.poi.hssf.record.BoolErrRecord;
|
|
|
|
import org.apache.poi.hssf.record.FormulaRecord;
|
|
|
|
import org.apache.poi.hssf.record.LabelRecord;
|
|
|
|
import org.apache.poi.hssf.record.LabelSSTRecord;
|
|
|
|
import org.apache.poi.hssf.record.NoteRecord;
|
|
|
|
import org.apache.poi.hssf.record.NumberRecord;
|
|
|
|
import org.apache.poi.hssf.record.RKRecord;
|
|
|
|
import org.apache.poi.hssf.record.Record;
|
2007-06-17 11:54:52 -04:00
|
|
|
import org.apache.poi.hssf.record.SSTRecord;
|
Merged revisions 638786-638802,638805-638811,638813-638814,638816-639230,639233-639241,639243-639253,639255-639486,639488-639601,639603-639835,639837-639917,639919-640056,640058-640710,640712-641156,641158-641184,641186-641795,641797-641798,641800-641933,641935-641963,641965-641966,641968-641995,641997-642230,642232-642562,642564-642565,642568-642570,642572-642573,642576-642736,642739-642877,642879,642881-642890,642892-642903,642905-642945,642947-643624,643626-643653,643655-643669,643671,643673-643830,643832-643833,643835-644342,644344-644472,644474-644508,644510-645347,645349-645351,645353-645559,645561-645565,645568-645951,645953-646193,646195-646311,646313-646404,646406-646665,646667-646853,646855-646869,646871-647151,647153-647185,647187-647579 via svnmerge from
https://svn.apache.org:443/repos/asf/poi/trunk
........
r647278 | josh | 2008-04-11 20:36:37 +0100 (Fri, 11 Apr 2008) | 1 line
fixed typo and formatting in class javadoc
........
r647567 | nick | 2008-04-13 14:16:36 +0100 (Sun, 13 Apr 2008) | 1 line
Various new bits of documentation on embeded files and text extraction
........
r647574 | nick | 2008-04-13 15:58:27 +0100 (Sun, 13 Apr 2008) | 1 line
Start on a eventusermodel based excel text extractor
........
r647576 | nick | 2008-04-13 16:09:42 +0100 (Sun, 13 Apr 2008) | 1 line
Finish off eventusermodel based Excel Extractor, and update the xls to csv converter (moved to correct place) based on discoveries for the text extractor
........
r647577 | nick | 2008-04-13 16:13:17 +0100 (Sun, 13 Apr 2008) | 1 line
Add information of EventBasedExcelExtractor to the documentation
........
git-svn-id: https://svn.apache.org/repos/asf/poi/branches/ooxml@647580 13f79535-47bb-0310-9956-ffa450edef68
2008-04-13 11:25:33 -04:00
|
|
|
import org.apache.poi.hssf.record.StringRecord;
|
Merged revisions 638786-638802,638805-638811,638813-638814,638816-639230,639233-639241,639243-639253,639255-639486,639488-639601,639603-639835,639837-639917,639919-640056,640058-640710,640712-641156,641158-641184,641186-641795,641797-641798,641800-641933,641935-641963,641965-641966,641968-641995,641997-642230,642232-642562,642564-642565,642568-642570,642572-642573,642576-642736,642739-642877,642879,642881-642890,642892-642903,642905-642945,642947-643624,643626-643653,643655-643669,643671,643673-643830,643832-643833,643835-644342,644344-644472,644474-644508,644510-645347,645349-645351,645353-645559,645561-645565,645568-645951,645953-646193,646195-646311,646313-646404,646406-646665,646667-646853,646855-646869,646871-647151,647153-647185,647187-647277,647279-647566,647568-647573,647575,647578-647711,647714-647737,647739-647823,647825-648155,648157-648202,648204-648273,648275,648277-648302,648304-648333,648335-648588,648590-648622,648625-648673,648675-649141,649144,649146-649556,649558-649795,649799,649801-649910,649912-649913,649915-650128,650131-650132,650134-650137,650140-650914,650916-651991,651993-652284,652286-652287,652289,652291,652293-652297,652299-652328,652330-652425,652427-652445,652447-652560,652562-652933,652935,652937-652993,652995-653116,653118-653124,653126-653483,653487-653519,653522-653550,653552-653607,653609-653667,653669-653674,653676-653814,653817-653830,653832-653891,653893-653944,653946-654055,654057-654355,654357-654365,654367-654648,654651-655215,655217-655277,655279-655281,655283-655911,655913-656212,656214,656216-656251,656253-656698,656700-656756,656758-656892,656894-657135,657137-657165,657168-657179,657181-657354,657356-657357,657359-657701,657703-657874,657876-658032,658034-658284,658286,658288-658301,658303-658307,658309-658321,658323-658335,658337-658348,658351,658353-658832,658834-658983,658985,658987-659066,659068-659402,659404-659428,659430-659451,659453-659454,659456-659461,659463-659477,659479-659524,659526-659571,659574,659576-660255,660257-660262,660264-660279,660281-660343,660345-660473,660475-660827,660829-660833,660835-660888,660890-663321,663323-663435,663437-663764,663766-663854,663856-664219,664221-664489,664494-664514,664516-668013,668015-668142,668144-668152,668154,668156-668256,668258,668260-669139,669141-669455,669457-669657,669659-669808,669810-670189,670191-674287 via svnmerge from
https://svn.apache.org/repos/asf/poi/trunk
........
r671322 | nick | 2008-06-24 20:53:53 +0100 (Tue, 24 Jun 2008) | 1 line
Make a start on being able to process formulas in the eventusermodel code
........
r672230 | nick | 2008-06-27 11:12:11 +0100 (Fri, 27 Jun 2008) | 1 line
Add MethodNotFound exceptions to the faq
........
r672550 | nick | 2008-06-28 18:04:09 +0100 (Sat, 28 Jun 2008) | 1 line
Finish the EventWorkbookBuilder, now does sheet references in formulas properly
........
r672553 | nick | 2008-06-28 18:12:38 +0100 (Sat, 28 Jun 2008) | 1 line
Update changelog about EventWorkbookBuilder, and tweak XLS2CSVmra to use it if formulas required
........
r672562 | nick | 2008-06-28 19:21:21 +0100 (Sat, 28 Jun 2008) | 1 line
Avoid spurious missing lines with the MissingRecordAware event code, and odd files that contain RowRecords in the middle of the cell Records.
........
r672567 | nick | 2008-06-28 19:48:35 +0100 (Sat, 28 Jun 2008) | 1 line
Patch from dnapoletano from bug #45175 - Support for variable length operands in org.apache.poi.hwpf.sprm.SprmOperation
........
r672569 | nick | 2008-06-28 19:54:02 +0100 (Sat, 28 Jun 2008) | 1 line
Patch from N. Hira from bug #45001 - Further fix for HWPF Range.delete() and unicode characters
........
r672570 | nick | 2008-06-28 19:58:23 +0100 (Sat, 28 Jun 2008) | 1 line
Patch from N.Hira from bug #45252 - Improvement for HWPF Range.replaceText()
........
r673050 | yegor | 2008-07-01 11:32:29 +0100 (Tue, 01 Jul 2008) | 1 line
updated status of the latest release, 3.1-FINAL
........
r673853 | josh | 2008-07-03 23:20:18 +0100 (Thu, 03 Jul 2008) | 1 line
Fix for bug 45334 - formula parser needs to handle dots in identifiers
........
r673863 | josh | 2008-07-04 00:09:08 +0100 (Fri, 04 Jul 2008) | 1 line
Fix for bug 45334 - added impl for ERROR.TYPE()
........
r673987 | nick | 2008-07-04 10:58:21 +0100 (Fri, 04 Jul 2008) | 1 line
Fix bug #45336 - Fix HSSFColor.getTripletHash()
........
r673997 | nick | 2008-07-04 11:46:59 +0100 (Fri, 04 Jul 2008) | 1 line
Fix bug #45338 - Fix HSSFWorkbook to give you the same HSSFFont every time, and then fix it to find newly added fonts
........
git-svn-id: https://svn.apache.org/repos/asf/poi/branches/ooxml@674296 13f79535-47bb-0310-9956-ffa450edef68
2008-07-06 09:10:09 -04:00
|
|
|
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
2007-06-17 06:59:48 -04:00
|
|
|
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A XLS -> CSV processor, that uses the MissingRecordAware
|
|
|
|
* EventModel code to ensure it outputs all columns and rows.
|
|
|
|
* @author Nick Burch
|
|
|
|
*/
|
|
|
|
public class XLS2CSVmra implements HSSFListener {
|
|
|
|
private int minColumns;
|
|
|
|
private POIFSFileSystem fs;
|
|
|
|
private PrintStream output;
|
2008-09-19 12:47:18 -04:00
|
|
|
|
2007-06-17 06:59:48 -04:00
|
|
|
private int lastRowNumber;
|
|
|
|
private int lastColumnNumber;
|
2008-09-19 12:47:18 -04:00
|
|
|
|
2007-06-17 11:54:52 -04:00
|
|
|
/** Should we output the formula, or the value it has? */
|
|
|
|
private boolean outputFormulaValues = true;
|
2008-09-19 12:47:18 -04:00
|
|
|
|
Merged revisions 638786-638802,638805-638811,638813-638814,638816-639230,639233-639241,639243-639253,639255-639486,639488-639601,639603-639835,639837-639917,639919-640056,640058-640710,640712-641156,641158-641184,641186-641795,641797-641798,641800-641933,641935-641963,641965-641966,641968-641995,641997-642230,642232-642562,642564-642565,642568-642570,642572-642573,642576-642736,642739-642877,642879,642881-642890,642892-642903,642905-642945,642947-643624,643626-643653,643655-643669,643671,643673-643830,643832-643833,643835-644342,644344-644472,644474-644508,644510-645347,645349-645351,645353-645559,645561-645565,645568-645951,645953-646193,646195-646311,646313-646404,646406-646665,646667-646853,646855-646869,646871-647151,647153-647185,647187-647277,647279-647566,647568-647573,647575,647578-647711,647714-647737,647739-647823,647825-648155,648157-648202,648204-648273,648275,648277-648302,648304-648333,648335-648588,648590-648622,648625-648673,648675-649141,649144,649146-649556,649558-649795,649799,649801-649910,649912-649913,649915-650128,650131-650132,650134-650137,650140-650914,650916-651991,651993-652284,652286-652287,652289,652291,652293-652297,652299-652328,652330-652425,652427-652445,652447-652560,652562-652933,652935,652937-652993,652995-653116,653118-653124,653126-653483,653487-653519,653522-653550,653552-653607,653609-653667,653669-653674,653676-653814,653817-653830,653832-653891,653893-653944,653946-654055,654057-654355,654357-654365,654367-654648,654651-655215,655217-655277,655279-655281,655283-655911,655913-656212,656214,656216-656251,656253-656698,656700-656756,656758-656892,656894-657135,657137-657165,657168-657179,657181-657354,657356-657357,657359-657701,657703-657874,657876-658032,658034-658284,658286,658288-658301,658303-658307,658309-658321,658323-658335,658337-658348,658351,658353-658832,658834-658983,658985,658987-659066,659068-659402,659404-659428,659430-659451,659453-659454,659456-659461,659463-659477,659479-659524,659526-659571,659574,659576-660255,660257-660262,660264-660279,660281-660343,660345-660473,660475-660827,660829-660833,660835-660888,660890-663321,663323-663435,663437-663764,663766-663854,663856-664219,664221-664489,664494-664514,664516-668013,668015-668142,668144-668152,668154,668156-668256,668258,668260-669139,669141-669455,669457-669657,669659-669808,669810-670189,670191-674287 via svnmerge from
https://svn.apache.org/repos/asf/poi/trunk
........
r671322 | nick | 2008-06-24 20:53:53 +0100 (Tue, 24 Jun 2008) | 1 line
Make a start on being able to process formulas in the eventusermodel code
........
r672230 | nick | 2008-06-27 11:12:11 +0100 (Fri, 27 Jun 2008) | 1 line
Add MethodNotFound exceptions to the faq
........
r672550 | nick | 2008-06-28 18:04:09 +0100 (Sat, 28 Jun 2008) | 1 line
Finish the EventWorkbookBuilder, now does sheet references in formulas properly
........
r672553 | nick | 2008-06-28 18:12:38 +0100 (Sat, 28 Jun 2008) | 1 line
Update changelog about EventWorkbookBuilder, and tweak XLS2CSVmra to use it if formulas required
........
r672562 | nick | 2008-06-28 19:21:21 +0100 (Sat, 28 Jun 2008) | 1 line
Avoid spurious missing lines with the MissingRecordAware event code, and odd files that contain RowRecords in the middle of the cell Records.
........
r672567 | nick | 2008-06-28 19:48:35 +0100 (Sat, 28 Jun 2008) | 1 line
Patch from dnapoletano from bug #45175 - Support for variable length operands in org.apache.poi.hwpf.sprm.SprmOperation
........
r672569 | nick | 2008-06-28 19:54:02 +0100 (Sat, 28 Jun 2008) | 1 line
Patch from N. Hira from bug #45001 - Further fix for HWPF Range.delete() and unicode characters
........
r672570 | nick | 2008-06-28 19:58:23 +0100 (Sat, 28 Jun 2008) | 1 line
Patch from N.Hira from bug #45252 - Improvement for HWPF Range.replaceText()
........
r673050 | yegor | 2008-07-01 11:32:29 +0100 (Tue, 01 Jul 2008) | 1 line
updated status of the latest release, 3.1-FINAL
........
r673853 | josh | 2008-07-03 23:20:18 +0100 (Thu, 03 Jul 2008) | 1 line
Fix for bug 45334 - formula parser needs to handle dots in identifiers
........
r673863 | josh | 2008-07-04 00:09:08 +0100 (Fri, 04 Jul 2008) | 1 line
Fix for bug 45334 - added impl for ERROR.TYPE()
........
r673987 | nick | 2008-07-04 10:58:21 +0100 (Fri, 04 Jul 2008) | 1 line
Fix bug #45336 - Fix HSSFColor.getTripletHash()
........
r673997 | nick | 2008-07-04 11:46:59 +0100 (Fri, 04 Jul 2008) | 1 line
Fix bug #45338 - Fix HSSFWorkbook to give you the same HSSFFont every time, and then fix it to find newly added fonts
........
git-svn-id: https://svn.apache.org/repos/asf/poi/branches/ooxml@674296 13f79535-47bb-0310-9956-ffa450edef68
2008-07-06 09:10:09 -04:00
|
|
|
/** For parsing Formulas */
|
|
|
|
private SheetRecordCollectingListener workbookBuildingListener;
|
|
|
|
private HSSFWorkbook stubWorkbook;
|
2008-09-19 12:47:18 -04:00
|
|
|
|
2007-06-17 11:54:52 -04:00
|
|
|
// Records we pick up as we process
|
|
|
|
private SSTRecord sstRecord;
|
Merged revisions 638786-638802,638805-638811,638813-638814,638816-639230,639233-639241,639243-639253,639255-639486,639488-639601,639603-639835,639837-639917,639919-640056,640058-640710,640712-641156,641158-641184,641186-641795,641797-641798,641800-641933,641935-641963,641965-641966,641968-641995,641997-642230,642232-642562,642564-642565,642568-642570,642572-642573,642576-642736,642739-642877,642879,642881-642890,642892-642903,642905-642945,642947-643624,643626-643653,643655-643669,643671,643673-643830,643832-643833,643835-644342,644344-644472,644474-644508,644510-645347,645349-645351,645353-645559,645561-645565,645568-645951,645953-646193,646195-646311,646313-646820 via svnmerge from
https://svn.apache.org:443/repos/asf/poi/trunk
........
r646405 | nick | 2008-04-09 16:36:39 +0100 (Wed, 09 Apr 2008) | 1 line
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
........
r646666 | josh | 2008-04-10 08:06:55 +0100 (Thu, 10 Apr 2008) | 1 line
bugzilla 44792 - fixed encode/decode problems in ExternalNameRecord and CRNRecord.
........
git-svn-id: https://svn.apache.org/repos/asf/poi/branches/ooxml@646826 13f79535-47bb-0310-9956-ffa450edef68
2008-04-10 10:43:24 -04:00
|
|
|
private FormatTrackingHSSFListener formatListener;
|
2008-09-19 12:47:18 -04:00
|
|
|
|
Merged revisions 638786-638802,638805-638811,638813-638814,638816-639230,639233-639241,639243-639253,639255-639486,639488-639601,639603-639835,639837-639917,639919-640056,640058-640710,640712-641156,641158-641184,641186-641795,641797-641798,641800-641933,641935-641963,641965-641966,641968-641995,641997-642230,642232-642562,642564-642565,642568-642570,642572-642573,642576-642736,642739-642877,642879,642881-642890,642892-642903,642905-642945,642947-643624,643626-643653,643655-643669,643671,643673-643830,643832-643833,643835-644342,644344-644472,644474-644508,644510-645347,645349-645351,645353-645559,645561-645565,645568-645951,645953-646193,646195-646311,646313-646404,646406-646665,646667-646853,646855-646869,646871-647151,647153-647185,647187-647579 via svnmerge from
https://svn.apache.org:443/repos/asf/poi/trunk
........
r647278 | josh | 2008-04-11 20:36:37 +0100 (Fri, 11 Apr 2008) | 1 line
fixed typo and formatting in class javadoc
........
r647567 | nick | 2008-04-13 14:16:36 +0100 (Sun, 13 Apr 2008) | 1 line
Various new bits of documentation on embeded files and text extraction
........
r647574 | nick | 2008-04-13 15:58:27 +0100 (Sun, 13 Apr 2008) | 1 line
Start on a eventusermodel based excel text extractor
........
r647576 | nick | 2008-04-13 16:09:42 +0100 (Sun, 13 Apr 2008) | 1 line
Finish off eventusermodel based Excel Extractor, and update the xls to csv converter (moved to correct place) based on discoveries for the text extractor
........
r647577 | nick | 2008-04-13 16:13:17 +0100 (Sun, 13 Apr 2008) | 1 line
Add information of EventBasedExcelExtractor to the documentation
........
git-svn-id: https://svn.apache.org/repos/asf/poi/branches/ooxml@647580 13f79535-47bb-0310-9956-ffa450edef68
2008-04-13 11:25:33 -04:00
|
|
|
// For handling formulas with string results
|
|
|
|
private int nextRow;
|
|
|
|
private int nextColumn;
|
|
|
|
private boolean outputNextStringRecord;
|
2007-06-17 06:59:48 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a new XLS -> CSV converter
|
|
|
|
* @param fs The POIFSFileSystem to process
|
|
|
|
* @param output The PrintStream to output the CSV to
|
|
|
|
* @param minColumns The minimum number of columns to output, or -1 for no minimum
|
|
|
|
*/
|
|
|
|
public XLS2CSVmra(POIFSFileSystem fs, PrintStream output, int minColumns) {
|
|
|
|
this.fs = fs;
|
|
|
|
this.output = output;
|
|
|
|
this.minColumns = minColumns;
|
|
|
|
}
|
2008-09-19 12:47:18 -04:00
|
|
|
|
2007-06-17 06:59:48 -04:00
|
|
|
/**
|
|
|
|
* Creates a new XLS -> CSV converter
|
|
|
|
* @param filename The file to process
|
|
|
|
* @param minColumns The minimum number of columns to output, or -1 for no minimum
|
|
|
|
* @throws IOException
|
|
|
|
* @throws FileNotFoundException
|
|
|
|
*/
|
|
|
|
public XLS2CSVmra(String filename, int minColumns) throws IOException, FileNotFoundException {
|
|
|
|
this(
|
|
|
|
new POIFSFileSystem(new FileInputStream(filename)),
|
|
|
|
System.out, minColumns
|
|
|
|
);
|
|
|
|
}
|
2008-09-19 12:47:18 -04:00
|
|
|
|
2007-06-17 06:59:48 -04:00
|
|
|
/**
|
|
|
|
* Initiates the processing of the XLS file to CSV
|
|
|
|
*/
|
|
|
|
public void process() throws IOException {
|
|
|
|
MissingRecordAwareHSSFListener listener = new MissingRecordAwareHSSFListener(this);
|
2008-09-19 12:47:18 -04:00
|
|
|
formatListener = new FormatTrackingHSSFListener(listener);
|
|
|
|
|
2007-06-17 06:59:48 -04:00
|
|
|
HSSFEventFactory factory = new HSSFEventFactory();
|
|
|
|
HSSFRequest request = new HSSFRequest();
|
2008-09-19 12:47:18 -04:00
|
|
|
|
Merged revisions 638786-638802,638805-638811,638813-638814,638816-639230,639233-639241,639243-639253,639255-639486,639488-639601,639603-639835,639837-639917,639919-640056,640058-640710,640712-641156,641158-641184,641186-641795,641797-641798,641800-641933,641935-641963,641965-641966,641968-641995,641997-642230,642232-642562,642564-642565,642568-642570,642572-642573,642576-642736,642739-642877,642879,642881-642890,642892-642903,642905-642945,642947-643624,643626-643653,643655-643669,643671,643673-643830,643832-643833,643835-644342,644344-644472,644474-644508,644510-645347,645349-645351,645353-645559,645561-645565,645568-645951,645953-646193,646195-646311,646313-646404,646406-646665,646667-646853,646855-646869,646871-647151,647153-647185,647187-647277,647279-647566,647568-647573,647575,647578-647711,647714-647737,647739-647823,647825-648155,648157-648202,648204-648273,648275,648277-648302,648304-648333,648335-648588,648590-648622,648625-648673,648675-649141,649144,649146-649556,649558-649795,649799,649801-649910,649912-649913,649915-650128,650131-650132,650134-650137,650140-650914,650916-651991,651993-652284,652286-652287,652289,652291,652293-652297,652299-652328,652330-652425,652427-652445,652447-652560,652562-652933,652935,652937-652993,652995-653116,653118-653124,653126-653483,653487-653519,653522-653550,653552-653607,653609-653667,653669-653674,653676-653814,653817-653830,653832-653891,653893-653944,653946-654055,654057-654355,654357-654365,654367-654648,654651-655215,655217-655277,655279-655281,655283-655911,655913-656212,656214,656216-656251,656253-656698,656700-656756,656758-656892,656894-657135,657137-657165,657168-657179,657181-657354,657356-657357,657359-657701,657703-657874,657876-658032,658034-658284,658286,658288-658301,658303-658307,658309-658321,658323-658335,658337-658348,658351,658353-658832,658834-658983,658985,658987-659066,659068-659402,659404-659428,659430-659451,659453-659454,659456-659461,659463-659477,659479-659524,659526-659571,659574,659576-660255,660257-660262,660264-660279,660281-660343,660345-660473,660475-660827,660829-660833,660835-660888,660890-663321,663323-663435,663437-663764,663766-663854,663856-664219,664221-664489,664494-664514,664516-668013,668015-668142,668144-668152,668154,668156-668256,668258,668260-669139,669141-669455,669457-669657,669659-669808,669810-670189,670191-674287 via svnmerge from
https://svn.apache.org/repos/asf/poi/trunk
........
r671322 | nick | 2008-06-24 20:53:53 +0100 (Tue, 24 Jun 2008) | 1 line
Make a start on being able to process formulas in the eventusermodel code
........
r672230 | nick | 2008-06-27 11:12:11 +0100 (Fri, 27 Jun 2008) | 1 line
Add MethodNotFound exceptions to the faq
........
r672550 | nick | 2008-06-28 18:04:09 +0100 (Sat, 28 Jun 2008) | 1 line
Finish the EventWorkbookBuilder, now does sheet references in formulas properly
........
r672553 | nick | 2008-06-28 18:12:38 +0100 (Sat, 28 Jun 2008) | 1 line
Update changelog about EventWorkbookBuilder, and tweak XLS2CSVmra to use it if formulas required
........
r672562 | nick | 2008-06-28 19:21:21 +0100 (Sat, 28 Jun 2008) | 1 line
Avoid spurious missing lines with the MissingRecordAware event code, and odd files that contain RowRecords in the middle of the cell Records.
........
r672567 | nick | 2008-06-28 19:48:35 +0100 (Sat, 28 Jun 2008) | 1 line
Patch from dnapoletano from bug #45175 - Support for variable length operands in org.apache.poi.hwpf.sprm.SprmOperation
........
r672569 | nick | 2008-06-28 19:54:02 +0100 (Sat, 28 Jun 2008) | 1 line
Patch from N. Hira from bug #45001 - Further fix for HWPF Range.delete() and unicode characters
........
r672570 | nick | 2008-06-28 19:58:23 +0100 (Sat, 28 Jun 2008) | 1 line
Patch from N.Hira from bug #45252 - Improvement for HWPF Range.replaceText()
........
r673050 | yegor | 2008-07-01 11:32:29 +0100 (Tue, 01 Jul 2008) | 1 line
updated status of the latest release, 3.1-FINAL
........
r673853 | josh | 2008-07-03 23:20:18 +0100 (Thu, 03 Jul 2008) | 1 line
Fix for bug 45334 - formula parser needs to handle dots in identifiers
........
r673863 | josh | 2008-07-04 00:09:08 +0100 (Fri, 04 Jul 2008) | 1 line
Fix for bug 45334 - added impl for ERROR.TYPE()
........
r673987 | nick | 2008-07-04 10:58:21 +0100 (Fri, 04 Jul 2008) | 1 line
Fix bug #45336 - Fix HSSFColor.getTripletHash()
........
r673997 | nick | 2008-07-04 11:46:59 +0100 (Fri, 04 Jul 2008) | 1 line
Fix bug #45338 - Fix HSSFWorkbook to give you the same HSSFFont every time, and then fix it to find newly added fonts
........
git-svn-id: https://svn.apache.org/repos/asf/poi/branches/ooxml@674296 13f79535-47bb-0310-9956-ffa450edef68
2008-07-06 09:10:09 -04:00
|
|
|
if(outputFormulaValues) {
|
|
|
|
request.addListenerForAllRecords(formatListener);
|
|
|
|
} else {
|
|
|
|
workbookBuildingListener = new SheetRecordCollectingListener(formatListener);
|
|
|
|
request.addListenerForAllRecords(workbookBuildingListener);
|
|
|
|
}
|
2008-09-19 12:47:18 -04:00
|
|
|
|
2007-06-17 06:59:48 -04:00
|
|
|
factory.processWorkbookEvents(request, fs);
|
|
|
|
}
|
2008-09-19 12:47:18 -04:00
|
|
|
|
2007-06-17 06:59:48 -04:00
|
|
|
/**
|
|
|
|
* Main HSSFListener method, processes events, and outputs the
|
2008-09-19 12:47:18 -04:00
|
|
|
* CSV as the file is processed.
|
2007-06-17 06:59:48 -04:00
|
|
|
*/
|
|
|
|
public void processRecord(Record record) {
|
|
|
|
int thisRow = -1;
|
|
|
|
int thisColumn = -1;
|
|
|
|
String thisStr = null;
|
2008-09-19 12:47:18 -04:00
|
|
|
|
2007-06-17 06:59:48 -04:00
|
|
|
switch (record.getSid())
|
2008-09-19 12:47:18 -04:00
|
|
|
{
|
Merged revisions 638786-638802,638805-638811,638813-638814,638816-639230,639233-639241,639243-639253,639255-639486,639488-639601,639603-639835,639837-639917,639919-640056,640058-640710,640712-641156,641158-641184,641186-641795,641797-641798,641800-641933,641935-641963,641965-641966,641968-641995,641997-642230,642232-642562,642564-642565,642568-642570,642572-642573,642576-642736,642739-642877,642879,642881-642890,642892-642903,642905-642945,642947-643624,643626-643653,643655-643669,643671,643673-643830,643832-643833,643835-644342,644344-644472,644474-644508,644510-645347,645349-645351,645353-645559,645561-645565,645568-645951,645953-646193,646195-646311,646313-646404,646406-646665,646667-646853,646855-646869,646871-647151,647153-647185,647187-647277,647279-647566,647568-647573,647575,647578-647711,647714-647737,647739-647823,647825-648155,648157-648202,648204-648273,648275,648277-648302,648304-648333,648335-648588,648590-648622,648625-648673,648675-649141,649144,649146-649556,649558-649795,649799,649801-649910,649912-649913,649915-650128,650131-650132,650134-650137,650140-650914,650916-651991,651993-652284,652286-652287,652289,652291,652293-652297,652299-652328,652330-652425,652427-652445,652447-652560,652562-652933,652935,652937-652993,652995-653116,653118-653124,653126-653483,653487-653519,653522-653550,653552-653607,653609-653667,653669-653674,653676-653814,653817-653830,653832-653891,653893-653944,653946-654055,654057-654355,654357-654365,654367-654648,654651-655215,655217-655277,655279-655281,655283-655911,655913-656212,656214,656216-656251,656253-656698,656700-656756,656758-656892,656894-657135,657137-657165,657168-657179,657181-657354,657356-657357,657359-657701,657703-657874,657876-658032,658034-658284,658286,658288-658301,658303-658307,658309-658321,658323-658335,658337-658348,658351,658353-658832,658834-658983,658985,658987-659066,659068-659402,659404-659428,659430-659451,659453-659454,659456-659461,659463-659477,659479-659524,659526-659571,659574,659576-660255,660257-660262,660264-660279,660281-660343,660345-660473,660475-660827,660829-660833,660835-660888,660890-663321,663323-663435,663437-663764,663766-663854,663856-664219,664221-664489,664494-664514,664516-668013,668015-668142,668144-668152,668154,668156-668256,668258,668260-669139,669141-669455,669457-669657,669659-669808,669810-670189,670191-674287 via svnmerge from
https://svn.apache.org/repos/asf/poi/trunk
........
r671322 | nick | 2008-06-24 20:53:53 +0100 (Tue, 24 Jun 2008) | 1 line
Make a start on being able to process formulas in the eventusermodel code
........
r672230 | nick | 2008-06-27 11:12:11 +0100 (Fri, 27 Jun 2008) | 1 line
Add MethodNotFound exceptions to the faq
........
r672550 | nick | 2008-06-28 18:04:09 +0100 (Sat, 28 Jun 2008) | 1 line
Finish the EventWorkbookBuilder, now does sheet references in formulas properly
........
r672553 | nick | 2008-06-28 18:12:38 +0100 (Sat, 28 Jun 2008) | 1 line
Update changelog about EventWorkbookBuilder, and tweak XLS2CSVmra to use it if formulas required
........
r672562 | nick | 2008-06-28 19:21:21 +0100 (Sat, 28 Jun 2008) | 1 line
Avoid spurious missing lines with the MissingRecordAware event code, and odd files that contain RowRecords in the middle of the cell Records.
........
r672567 | nick | 2008-06-28 19:48:35 +0100 (Sat, 28 Jun 2008) | 1 line
Patch from dnapoletano from bug #45175 - Support for variable length operands in org.apache.poi.hwpf.sprm.SprmOperation
........
r672569 | nick | 2008-06-28 19:54:02 +0100 (Sat, 28 Jun 2008) | 1 line
Patch from N. Hira from bug #45001 - Further fix for HWPF Range.delete() and unicode characters
........
r672570 | nick | 2008-06-28 19:58:23 +0100 (Sat, 28 Jun 2008) | 1 line
Patch from N.Hira from bug #45252 - Improvement for HWPF Range.replaceText()
........
r673050 | yegor | 2008-07-01 11:32:29 +0100 (Tue, 01 Jul 2008) | 1 line
updated status of the latest release, 3.1-FINAL
........
r673853 | josh | 2008-07-03 23:20:18 +0100 (Thu, 03 Jul 2008) | 1 line
Fix for bug 45334 - formula parser needs to handle dots in identifiers
........
r673863 | josh | 2008-07-04 00:09:08 +0100 (Fri, 04 Jul 2008) | 1 line
Fix for bug 45334 - added impl for ERROR.TYPE()
........
r673987 | nick | 2008-07-04 10:58:21 +0100 (Fri, 04 Jul 2008) | 1 line
Fix bug #45336 - Fix HSSFColor.getTripletHash()
........
r673997 | nick | 2008-07-04 11:46:59 +0100 (Fri, 04 Jul 2008) | 1 line
Fix bug #45338 - Fix HSSFWorkbook to give you the same HSSFFont every time, and then fix it to find newly added fonts
........
git-svn-id: https://svn.apache.org/repos/asf/poi/branches/ooxml@674296 13f79535-47bb-0310-9956-ffa450edef68
2008-07-06 09:10:09 -04:00
|
|
|
case BOFRecord.sid:
|
|
|
|
BOFRecord br = (BOFRecord)record;
|
|
|
|
if(br.getType() == BOFRecord.TYPE_WORKSHEET) {
|
|
|
|
// Create sub workbook if required
|
|
|
|
if(workbookBuildingListener != null && stubWorkbook == null) {
|
|
|
|
stubWorkbook = workbookBuildingListener.getStubHSSFWorkbook();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2008-09-19 12:47:18 -04:00
|
|
|
|
2007-06-17 11:54:52 -04:00
|
|
|
case SSTRecord.sid:
|
|
|
|
sstRecord = (SSTRecord) record;
|
|
|
|
break;
|
2008-09-19 12:47:18 -04:00
|
|
|
|
|
|
|
case BlankRecord.sid:
|
|
|
|
BlankRecord brec = (BlankRecord) record;
|
|
|
|
|
|
|
|
thisRow = brec.getRow();
|
|
|
|
thisColumn = brec.getColumn();
|
|
|
|
thisStr = "";
|
|
|
|
break;
|
|
|
|
case BoolErrRecord.sid:
|
|
|
|
BoolErrRecord berec = (BoolErrRecord) record;
|
|
|
|
|
|
|
|
thisRow = berec.getRow();
|
|
|
|
thisColumn = berec.getColumn();
|
|
|
|
thisStr = "";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FormulaRecord.sid:
|
|
|
|
FormulaRecord frec = (FormulaRecord) record;
|
|
|
|
|
|
|
|
thisRow = frec.getRow();
|
|
|
|
thisColumn = frec.getColumn();
|
|
|
|
|
|
|
|
if(outputFormulaValues) {
|
|
|
|
if(Double.isNaN( frec.getValue() )) {
|
|
|
|
// Formula result is a string
|
|
|
|
// This is stored in the next record
|
|
|
|
outputNextStringRecord = true;
|
|
|
|
nextRow = frec.getRow();
|
|
|
|
nextColumn = frec.getColumn();
|
|
|
|
} else {
|
|
|
|
thisStr = formatListener.formatNumberDateCell(frec);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
thisStr = '"' +
|
|
|
|
HSSFFormulaParser.toFormulaString(stubWorkbook, frec.getParsedExpression()) + '"';
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case StringRecord.sid:
|
|
|
|
if(outputNextStringRecord) {
|
|
|
|
// String for formula
|
|
|
|
StringRecord srec = (StringRecord)record;
|
|
|
|
thisStr = srec.getString();
|
|
|
|
thisRow = nextRow;
|
|
|
|
thisColumn = nextColumn;
|
|
|
|
outputNextStringRecord = false;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LabelRecord.sid:
|
|
|
|
LabelRecord lrec = (LabelRecord) record;
|
|
|
|
|
|
|
|
thisRow = lrec.getRow();
|
|
|
|
thisColumn = lrec.getColumn();
|
|
|
|
thisStr = '"' + lrec.getValue() + '"';
|
|
|
|
break;
|
|
|
|
case LabelSSTRecord.sid:
|
|
|
|
LabelSSTRecord lsrec = (LabelSSTRecord) record;
|
|
|
|
|
|
|
|
thisRow = lsrec.getRow();
|
|
|
|
thisColumn = lsrec.getColumn();
|
|
|
|
if(sstRecord == null) {
|
|
|
|
thisStr = '"' + "(No SST Record, can't identify string)" + '"';
|
|
|
|
} else {
|
|
|
|
thisStr = '"' + sstRecord.getString(lsrec.getSSTIndex()).toString() + '"';
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case NoteRecord.sid:
|
|
|
|
NoteRecord nrec = (NoteRecord) record;
|
|
|
|
|
|
|
|
thisRow = nrec.getRow();
|
|
|
|
thisColumn = nrec.getColumn();
|
|
|
|
// TODO: Find object to match nrec.getShapeId()
|
|
|
|
thisStr = '"' + "(TODO)" + '"';
|
|
|
|
break;
|
|
|
|
case NumberRecord.sid:
|
|
|
|
NumberRecord numrec = (NumberRecord) record;
|
|
|
|
|
|
|
|
thisRow = numrec.getRow();
|
|
|
|
thisColumn = numrec.getColumn();
|
|
|
|
|
|
|
|
// Format
|
|
|
|
thisStr = formatListener.formatNumberDateCell(numrec);
|
|
|
|
break;
|
|
|
|
case RKRecord.sid:
|
|
|
|
RKRecord rkrec = (RKRecord) record;
|
|
|
|
|
|
|
|
thisRow = rkrec.getRow();
|
|
|
|
thisColumn = rkrec.getColumn();
|
|
|
|
thisStr = '"' + "(TODO)" + '"';
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2007-06-17 11:54:52 -04:00
|
|
|
// Handle new row
|
|
|
|
if(thisRow != -1 && thisRow != lastRowNumber) {
|
|
|
|
lastColumnNumber = -1;
|
|
|
|
}
|
2008-09-19 12:47:18 -04:00
|
|
|
|
2007-06-17 06:59:48 -04:00
|
|
|
// Handle missing column
|
|
|
|
if(record instanceof MissingCellDummyRecord) {
|
|
|
|
MissingCellDummyRecord mc = (MissingCellDummyRecord)record;
|
|
|
|
thisRow = mc.getRow();
|
|
|
|
thisColumn = mc.getColumn();
|
|
|
|
thisStr = "";
|
|
|
|
}
|
2008-09-19 12:47:18 -04:00
|
|
|
|
2007-06-17 06:59:48 -04:00
|
|
|
// If we got something to print out, do so
|
|
|
|
if(thisStr != null) {
|
|
|
|
if(thisColumn > 0) {
|
|
|
|
output.print(',');
|
|
|
|
}
|
|
|
|
output.print(thisStr);
|
|
|
|
}
|
2008-09-19 12:47:18 -04:00
|
|
|
|
2007-06-17 06:59:48 -04:00
|
|
|
// Update column and row count
|
|
|
|
if(thisRow > -1)
|
|
|
|
lastRowNumber = thisRow;
|
|
|
|
if(thisColumn > -1)
|
|
|
|
lastColumnNumber = thisColumn;
|
2008-09-19 12:47:18 -04:00
|
|
|
|
2007-06-17 06:59:48 -04:00
|
|
|
// Handle end of row
|
|
|
|
if(record instanceof LastCellOfRowDummyRecord) {
|
|
|
|
// Print out any missing commas if needed
|
|
|
|
if(minColumns > 0) {
|
2007-06-17 11:54:52 -04:00
|
|
|
// Columns are 0 based
|
|
|
|
if(lastColumnNumber == -1) { lastColumnNumber = 0; }
|
|
|
|
for(int i=lastColumnNumber; i<(minColumns); i++) {
|
2007-06-17 06:59:48 -04:00
|
|
|
output.print(',');
|
|
|
|
}
|
|
|
|
}
|
2008-09-19 12:47:18 -04:00
|
|
|
|
2007-06-17 11:54:52 -04:00
|
|
|
// We're onto a new row
|
|
|
|
lastColumnNumber = -1;
|
2008-09-19 12:47:18 -04:00
|
|
|
|
2007-06-17 06:59:48 -04:00
|
|
|
// End the row
|
|
|
|
output.println();
|
|
|
|
}
|
|
|
|
}
|
2008-09-19 12:47:18 -04:00
|
|
|
|
2007-06-17 06:59:48 -04:00
|
|
|
public static void main(String[] args) throws Exception {
|
|
|
|
if(args.length < 1) {
|
|
|
|
System.err.println("Use:");
|
|
|
|
System.err.println(" XLS2CSVmra <xls file> [min columns]");
|
|
|
|
System.exit(1);
|
|
|
|
}
|
2008-09-19 12:47:18 -04:00
|
|
|
|
2007-06-17 06:59:48 -04:00
|
|
|
int minColumns = -1;
|
|
|
|
if(args.length >= 2) {
|
|
|
|
minColumns = Integer.parseInt(args[1]);
|
|
|
|
}
|
2008-09-19 12:47:18 -04:00
|
|
|
|
2007-06-17 06:59:48 -04:00
|
|
|
XLS2CSVmra xls2csv = new XLS2CSVmra(args[0], minColumns);
|
|
|
|
xls2csv.process();
|
|
|
|
}
|
|
|
|
}
|