git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@697580 13f79535-47bb-0310-9956-ffa450edef68tags/REL_3_2_FINAL
<!-- Don't forget to update status.xml too! --> | <!-- Don't forget to update status.xml too! --> | ||||
<release version="3.2-alpha1" date="2008-??-??"> | <release version="3.2-alpha1" date="2008-??-??"> | ||||
<action dev="POI-DEVELOPERS" type="add">Include the sheet name in the output of examples.XLS2CSVmra</action> | |||||
<action dev="POI-DEVELOPERS" type="fix">45784 - Support long chart titles in SeriesTextRecords</action> | <action dev="POI-DEVELOPERS" type="fix">45784 - Support long chart titles in SeriesTextRecords</action> | ||||
<action dev="POI-DEVELOPERS" type="fix">45777 - Throw an exception if HSSF Footer or Header is attemped to be set too long, rather than having it break during writing out</action> | <action dev="POI-DEVELOPERS" type="fix">45777 - Throw an exception if HSSF Footer or Header is attemped to be set too long, rather than having it break during writing out</action> | ||||
<action dev="POI-DEVELOPERS" type="add">45844 - Addtional diagnostics for HSLF SlideShowRecordDumper</action> | <action dev="POI-DEVELOPERS" type="add">45844 - Addtional diagnostics for HSLF SlideShowRecordDumper</action> |
<!-- Don't forget to update changes.xml too! --> | <!-- Don't forget to update changes.xml too! --> | ||||
<changes> | <changes> | ||||
<release version="3.2-alpha1" date="2008-??-??"> | <release version="3.2-alpha1" date="2008-??-??"> | ||||
<action dev="POI-DEVELOPERS" type="add">Include the sheet name in the output of examples.XLS2CSVmra</action> | |||||
<action dev="POI-DEVELOPERS" type="fix">45784 - Support long chart titles in SeriesTextRecords</action> | <action dev="POI-DEVELOPERS" type="fix">45784 - Support long chart titles in SeriesTextRecords</action> | ||||
<action dev="POI-DEVELOPERS" type="fix">45777 - Throw an exception if HSSF Footer or Header is attemped to be set too long, rather than having it break during writing out</action> | <action dev="POI-DEVELOPERS" type="fix">45777 - Throw an exception if HSSF Footer or Header is attemped to be set too long, rather than having it break during writing out</action> | ||||
<action dev="POI-DEVELOPERS" type="add">45844 - Addtional diagnostics for HSLF SlideShowRecordDumper</action> | <action dev="POI-DEVELOPERS" type="add">45844 - Addtional diagnostics for HSLF SlideShowRecordDumper</action> |
import java.io.FileNotFoundException; | import java.io.FileNotFoundException; | ||||
import java.io.IOException; | import java.io.IOException; | ||||
import java.io.PrintStream; | import java.io.PrintStream; | ||||
import java.util.ArrayList; | |||||
import org.apache.poi.hssf.eventusermodel.FormatTrackingHSSFListener; | import org.apache.poi.hssf.eventusermodel.FormatTrackingHSSFListener; | ||||
import org.apache.poi.hssf.eventusermodel.HSSFEventFactory; | import org.apache.poi.hssf.eventusermodel.HSSFEventFactory; | ||||
import org.apache.poi.hssf.record.BOFRecord; | import org.apache.poi.hssf.record.BOFRecord; | ||||
import org.apache.poi.hssf.record.BlankRecord; | import org.apache.poi.hssf.record.BlankRecord; | ||||
import org.apache.poi.hssf.record.BoolErrRecord; | import org.apache.poi.hssf.record.BoolErrRecord; | ||||
import org.apache.poi.hssf.record.BoundSheetRecord; | |||||
import org.apache.poi.hssf.record.FormulaRecord; | import org.apache.poi.hssf.record.FormulaRecord; | ||||
import org.apache.poi.hssf.record.LabelRecord; | import org.apache.poi.hssf.record.LabelRecord; | ||||
import org.apache.poi.hssf.record.LabelSSTRecord; | import org.apache.poi.hssf.record.LabelSSTRecord; | ||||
// Records we pick up as we process | // Records we pick up as we process | ||||
private SSTRecord sstRecord; | private SSTRecord sstRecord; | ||||
private FormatTrackingHSSFListener formatListener; | private FormatTrackingHSSFListener formatListener; | ||||
/** So we known which sheet we're on */ | |||||
private int sheetIndex = -1; | |||||
private BoundSheetRecord[] orderedBSRs; | |||||
private ArrayList boundSheetRecords = new ArrayList(); | |||||
// For handling formulas with string results | // For handling formulas with string results | ||||
private int nextRow; | private int nextRow; | ||||
switch (record.getSid()) | switch (record.getSid()) | ||||
{ | { | ||||
case BoundSheetRecord.sid: | |||||
boundSheetRecords.add(record); | |||||
break; | |||||
case BOFRecord.sid: | case BOFRecord.sid: | ||||
BOFRecord br = (BOFRecord)record; | BOFRecord br = (BOFRecord)record; | ||||
if(br.getType() == BOFRecord.TYPE_WORKSHEET) { | if(br.getType() == BOFRecord.TYPE_WORKSHEET) { | ||||
if(workbookBuildingListener != null && stubWorkbook == null) { | if(workbookBuildingListener != null && stubWorkbook == null) { | ||||
stubWorkbook = workbookBuildingListener.getStubHSSFWorkbook(); | stubWorkbook = workbookBuildingListener.getStubHSSFWorkbook(); | ||||
} | } | ||||
// Output the worksheet name | |||||
// Works by ordering the BSRs by the location of | |||||
// their BOFRecords, and then knowing that we | |||||
// process BOFRecords in byte offset order | |||||
sheetIndex++; | |||||
if(orderedBSRs == null) { | |||||
orderedBSRs = BoundSheetRecord.orderByBofPosition(boundSheetRecords); | |||||
} | |||||
output.println(); | |||||
output.println(orderedBSRs[sheetIndex].getSheetname() + ":"); | |||||
} | } | ||||
break; | break; | ||||
package org.apache.poi.hssf.record; | package org.apache.poi.hssf.record; | ||||
import java.util.Arrays; | |||||
import java.util.Comparator; | |||||
import java.util.List; | |||||
import org.apache.poi.util.BitField; | import org.apache.poi.util.BitField; | ||||
import org.apache.poi.util.BitFieldFactory; | import org.apache.poi.util.BitFieldFactory; | ||||
import org.apache.poi.util.LittleEndian; | import org.apache.poi.util.LittleEndian; | ||||
public void setVeryHidden(boolean veryHidden) { | public void setVeryHidden(boolean veryHidden) { | ||||
field_2_option_flags = veryHiddenFlag.setShortBoolean(field_2_option_flags, veryHidden); | field_2_option_flags = veryHiddenFlag.setShortBoolean(field_2_option_flags, veryHidden); | ||||
} | } | ||||
/** | |||||
* Takes a list of BoundSheetRecords, and returns the all | |||||
* ordered by the position of their BOFs. | |||||
*/ | |||||
public static BoundSheetRecord[] orderByBofPosition(List boundSheetRecords) { | |||||
BoundSheetRecord[] bsrs = (BoundSheetRecord[])boundSheetRecords.toArray( | |||||
new BoundSheetRecord[boundSheetRecords.size()]); | |||||
// Sort | |||||
Arrays.sort(bsrs, new BOFComparator()); | |||||
// All done | |||||
return bsrs; | |||||
} | |||||
private static class BOFComparator implements Comparator { | |||||
public int compare(Object bsr1, Object bsr2) { | |||||
return compare((BoundSheetRecord)bsr1, (BoundSheetRecord)bsr2); | |||||
} | |||||
public int compare(BoundSheetRecord bsr1, BoundSheetRecord bsr2) { | |||||
if(bsr1.field_1_position_of_BOF < bsr2.field_1_position_of_BOF) | |||||
return -1; | |||||
if(bsr1.field_1_position_of_BOF == bsr2.field_1_position_of_BOF) | |||||
return 0; | |||||
return 1; | |||||
} | |||||
} | |||||
} | } |
package org.apache.poi.hssf.record; | package org.apache.poi.hssf.record; | ||||
import java.io.InputStream; | import java.io.InputStream; | ||||
import java.util.ArrayList; | |||||
import junit.framework.AssertionFailedError; | import junit.framework.AssertionFailedError; | ||||
import junit.framework.TestCase; | import junit.framework.TestCase; | ||||
throw new AssertionFailedError("Identified bug 42794"); | throw new AssertionFailedError("Identified bug 42794"); | ||||
} | } | ||||
} | } | ||||
public void testOrdering() throws Exception { | |||||
BoundSheetRecord bs1 = new BoundSheetRecord(); | |||||
BoundSheetRecord bs2 = new BoundSheetRecord(); | |||||
BoundSheetRecord bs3 = new BoundSheetRecord(); | |||||
bs1.setPositionOfBof(11); | |||||
bs2.setPositionOfBof(33); | |||||
bs3.setPositionOfBof(22); | |||||
ArrayList l = new ArrayList(); | |||||
l.add(bs1); | |||||
l.add(bs2); | |||||
l.add(bs3); | |||||
BoundSheetRecord[] r = BoundSheetRecord.orderByBofPosition(l); | |||||
assertEquals(3, r.length); | |||||
assertEquals(bs1, r[0]); | |||||
assertEquals(bs3, r[1]); | |||||
assertEquals(bs2, r[2]); | |||||
} | |||||
} | } |