You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@poi.apache.org by gl...@apache.org on 2004/02/10 23:00:28 UTC
cvs commit: jakarta-poi/src/java/org/apache/poi/hssf/usermodel DummyGraphics2d.java EscherGraphics.java EscherGraphics2d.java FontDetails.java HSSFAnchor.java HSSFChildAnchor.java HSSFClientAnchor.java HSSFPatriarch.java HSSFPolygon.java HSSFRichTextString.java HSSFShape.java HSSFShapeContainer.java HSSFShapeGroup.java HSSFSimpleShape.java HSSFTextbox.java StaticFontMetrics.java HSSFFont.java HSSFPalette.java HSSFSheet.java HSSFWorkbook.java
glens 2004/02/10 14:00:28
Modified: src/java/org/apache/poi/hssf/usermodel Tag: REL_2_BRANCH
HSSFFont.java HSSFPalette.java HSSFSheet.java
HSSFWorkbook.java
Added: src/java/org/apache/poi/hssf/usermodel Tag: REL_2_BRANCH
DummyGraphics2d.java EscherGraphics.java
EscherGraphics2d.java FontDetails.java
HSSFAnchor.java HSSFChildAnchor.java
HSSFClientAnchor.java HSSFPatriarch.java
HSSFPolygon.java HSSFRichTextString.java
HSSFShape.java HSSFShapeContainer.java
HSSFShapeGroup.java HSSFSimpleShape.java
HSSFTextbox.java StaticFontMetrics.java
Log:
User model for drawing format support
Revision Changes Path
No revision
No revision
1.3.2.2 +11 -2 jakarta-poi/src/java/org/apache/poi/hssf/usermodel/HSSFFont.java
Index: HSSFFont.java
===================================================================
RCS file: /home/cvs/jakarta-poi/src/java/org/apache/poi/hssf/usermodel/HSSFFont.java,v
retrieving revision 1.3.2.1
retrieving revision 1.3.2.2
diff -u -r1.3.2.1 -r1.3.2.2
--- HSSFFont.java 27 Oct 2003 02:40:12 -0000 1.3.2.1
+++ HSSFFont.java 10 Feb 2004 22:00:27 -0000 1.3.2.2
@@ -165,7 +165,7 @@
/**
* set the name for the font (i.e. Arial)
- * @param String representing the name of the font to use
+ * @param name String representing the name of the font to use
* @see #FONT_ARIAL
*/
@@ -359,7 +359,7 @@
/**
* set type of text underlining to use
- * @param underlining type
+ * @param underline type
* @see #U_NONE
* @see #U_SINGLE
* @see #U_DOUBLE
@@ -386,4 +386,13 @@
{
return font.getUnderline();
}
+
+ public String toString()
+ {
+ return "org.apache.poi.hssf.usermodel.HSSFFont{" +
+ font +
+ "}";
+ }
+
+
}
1.2.2.2 +55 -2 jakarta-poi/src/java/org/apache/poi/hssf/usermodel/HSSFPalette.java
Index: HSSFPalette.java
===================================================================
RCS file: /home/cvs/jakarta-poi/src/java/org/apache/poi/hssf/usermodel/HSSFPalette.java,v
retrieving revision 1.2.2.1
retrieving revision 1.2.2.2
diff -u -r1.2.2.1 -r1.2.2.2
--- HSSFPalette.java 1 Jul 2003 15:07:59 -0000 1.2.2.1
+++ HSSFPalette.java 10 Feb 2004 22:00:27 -0000 1.2.2.2
@@ -110,7 +110,35 @@
}
return null;
}
-
+
+ /**
+ * Finds the closest matching color in the custom palette. The
+ * method for finding the distance between the colors is fairly
+ * primative.
+ *
+ * @param red The red component of the color to match.
+ * @param green The green component of the color to match.
+ * @param blue The blue component of the color to match.
+ * @return The closest color or null if there are no custom
+ * colors currently defined.
+ */
+ public HSSFColor findSimilarColor(byte red, byte green, byte blue)
+ {
+ HSSFColor result = null;
+ int minColorDistance = Integer.MAX_VALUE;
+ byte[] b = palette.getColor(PaletteRecord.FIRST_COLOR_INDEX);
+ for (short i = (short) PaletteRecord.FIRST_COLOR_INDEX; b != null;
+ b = palette.getColor(++i))
+ {
+ int colorDistance = red - b[0] + green - b[1] + blue - b[2];
+ if (colorDistance < minColorDistance)
+ {
+ result = getColor(i);
+ }
+ }
+ return result;
+ }
+
/**
* Sets the color at the given offset
*
@@ -123,7 +151,32 @@
{
palette.setColor(index, red, green, blue);
}
-
+
+ /**
+ * Adds a new color into an empty color slot.
+ * @param red The red component
+ * @param green The green component
+ * @param blue The blue component
+ *
+ * @return The new custom color.
+ *
+ * @throws RuntimeException if there are more more free color indexes.
+ */
+ public HSSFColor addColor( byte red, byte green, byte blue )
+ {
+ byte[] b = palette.getColor(PaletteRecord.FIRST_COLOR_INDEX);
+ short i;
+ for (i = (short) PaletteRecord.FIRST_COLOR_INDEX; i < PaletteRecord.STANDARD_PALETTE_SIZE + PaletteRecord.FIRST_COLOR_INDEX; b = palette.getColor(++i))
+ {
+ if (b == null)
+ {
+ setColorAtIndex( i, red, green, blue );
+ return getColor(i);
+ }
+ }
+ throw new RuntimeException("Could not find free color index");
+ }
+
private static class CustomColor extends HSSFColor
{
private short byteOffset;
1.21.2.5 +71 -35 jakarta-poi/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java
Index: HSSFSheet.java
===================================================================
RCS file: /home/cvs/jakarta-poi/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java,v
retrieving revision 1.21.2.4
retrieving revision 1.21.2.5
diff -u -r1.21.2.4 -r1.21.2.5
--- HSSFSheet.java 9 Feb 2004 22:41:27 -0000 1.21.2.4
+++ HSSFSheet.java 10 Feb 2004 22:00:27 -0000 1.21.2.5
@@ -59,26 +59,20 @@
*/
package org.apache.poi.hssf.usermodel;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-import java.util.TreeMap;
-
+import org.apache.poi.ddf.EscherRecord;
import org.apache.poi.hssf.model.Sheet;
import org.apache.poi.hssf.model.Workbook;
-import org.apache.poi.hssf.record.CellValueRecordInterface;
-import org.apache.poi.hssf.record.HCenterRecord;
-import org.apache.poi.hssf.record.PageBreakRecord;
-import org.apache.poi.hssf.record.Record;
-import org.apache.poi.hssf.record.RowRecord;
-import org.apache.poi.hssf.record.SCLRecord;
-import org.apache.poi.hssf.record.VCenterRecord;
-import org.apache.poi.hssf.record.WSBoolRecord;
-import org.apache.poi.hssf.record.WindowTwoRecord;
+import org.apache.poi.hssf.record.*;
import org.apache.poi.hssf.util.Region;
import org.apache.poi.util.POILogFactory;
import org.apache.poi.util.POILogger;
+import java.io.PrintWriter;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.TreeMap;
+
/**
* High level representation of a worksheet.
* @author Andrew C. Oliver (acoliver at apache dot org)
@@ -874,13 +868,13 @@
{
getSheet().setMargin( margin, size );
}
-
+
/**
* Answer whether protection is enabled or disabled
* @return true => protection enabled; false => protection disabled
*/
public boolean getProtect() {
- return getSheet().getProtect().getProtect();
+ return getSheet().getProtect().getProtect();
}
/**
@@ -888,7 +882,7 @@
* @param protect true => protection enabled; false => protection disabled
*/
public void setProtect(boolean protect) {
- getSheet().getProtect().setProtect(protect);
+ getSheet().getProtect().setProtect(protect);
}
/**
@@ -926,34 +920,34 @@
//move merged regions completely if they fall within the new region boundaries when they are shifted
for (int i = 0; i < this.getNumMergedRegions(); i++) {
Region merged = this.getMergedRegionAt(i);
-
+
boolean inStart = (merged.getRowFrom() >= startRow || merged.getRowTo() >= startRow);
boolean inEnd = (merged.getRowTo() <= endRow || merged.getRowFrom() <= endRow);
-
+
//dont check if it's not within the shifted area
if (! (inStart && inEnd)) continue;
-
- //only shift if the region outside the shifted rows is not merged too
+
+ //only shift if the region outside the shifted rows is not merged too
if (!merged.contains(startRow-1, (short)0) && !merged.contains(endRow+1, (short)0)){
- merged.setRowFrom(merged.getRowFrom()+n);
+ merged.setRowFrom(merged.getRowFrom()+n);
merged.setRowTo(merged.getRowTo()+n);
//have to remove/add it back
shiftedRegions.add(merged);
this.removeMergedRegion(i);
i = i -1; // we have to back up now since we removed one
-
+
}
-
+
}
-
+
//readd so it doesn't get shifted again
Iterator iterator = shiftedRegions.iterator();
while (iterator.hasNext()) {
Region region = (Region)iterator.next();
-
+
this.addMergedRegion(region);
}
-
+
}
/**
@@ -978,7 +972,7 @@
* Shifts rows between startRow and endRow n number of rows.
* If you use a negative number, it will shift rows up.
* Code ensures that rows don't wrap around
- *
+ *
* <p>
* Additionally shifts merged regions that are completely defined in these
* rows (ie. merged 2 cells on a row to be shifted).
@@ -1006,19 +1000,19 @@
inc = -1;
}
- shiftMerged(startRow, endRow, n, true);
- sheet.shiftRowBreaks(startRow, endRow, n);
+ shiftMerged(startRow, endRow, n, true);
+ sheet.shiftRowBreaks(startRow, endRow, n);
for ( int rowNum = s; rowNum >= startRow && rowNum <= endRow && rowNum >= 0 && rowNum < 65536; rowNum += inc )
{
HSSFRow row = getRow( rowNum );
- HSSFRow row2Replace = getRow( rowNum + n );
+ HSSFRow row2Replace = getRow( rowNum + n );
if ( row2Replace == null )
row2Replace = createRow( rowNum + n );
-
+
HSSFCell cell;
-
+
// Removes the cells before over writting them.
@@ -1033,10 +1027,10 @@
if (copyRowHeight) {
row2Replace.setHeight(row.getHeight());
}
-
+
if (resetOriginalRowHeight) {
row.setHeight((short)0xff);
- }
+ }
}
for ( short col = row.getFirstCellNum(); col <= row.getLastCellNum(); col++ )
{
@@ -1255,4 +1249,46 @@
if (column > 255) throw new IllegalArgumentException("Maximum column number is 255");
if (column < 0) throw new IllegalArgumentException("Minimum column number is 0");
}
+
+ /**
+ * Aggregates the drawing records and dumps the escher record hierarchy
+ * to the standard output.
+ */
+ public void dumpDrawingRecords()
+ {
+ sheet.aggregateDrawingRecords(book.getDrawingManager());
+
+ EscherAggregate r = (EscherAggregate) getSheet().findFirstRecordBySid(EscherAggregate.sid);
+ List escherRecords = r.getEscherRecords();
+ for ( Iterator iterator = escherRecords.iterator(); iterator.hasNext(); )
+ {
+ EscherRecord escherRecord = (EscherRecord) iterator.next();
+ PrintWriter w = new PrintWriter(System.out);
+ escherRecord.display(w, 0);
+ w.close();
+ }
+ }
+
+ /**
+ * Creates the toplevel drawing patriarch. This will have the effect of
+ * removing any existing drawings on this sheet.
+ *
+ * @return The new patriarch.
+ */
+ public HSSFPatriarch createDrawingPatriarch()
+ {
+ // Create the drawing group if it doesn't already exist.
+ book.createDrawingGroup();
+
+ sheet.aggregateDrawingRecords(book.getDrawingManager());
+ EscherAggregate agg = (EscherAggregate) sheet.findFirstRecordBySid(EscherAggregate.sid);
+ HSSFPatriarch patriarch = new HSSFPatriarch(this);
+ agg.clear(); // Initially the behaviour will be to clear out any existing shapes in the sheet when
+ // creating a new patriarch.
+ agg.setPatriarch(patriarch);
+ return patriarch;
+ }
+
+
+
}
1.24.2.5 +129 -93 jakarta-poi/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java
Index: HSSFWorkbook.java
===================================================================
RCS file: /home/cvs/jakarta-poi/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java,v
retrieving revision 1.24.2.4
retrieving revision 1.24.2.5
diff -u -r1.24.2.4 -r1.24.2.5
--- HSSFWorkbook.java 13 Oct 2003 16:45:01 -0000 1.24.2.4
+++ HSSFWorkbook.java 10 Feb 2004 22:00:27 -0000 1.24.2.5
@@ -71,14 +71,7 @@
import org.apache.poi.hssf.eventmodel.EventRecordFactory;
import org.apache.poi.hssf.model.Sheet;
import org.apache.poi.hssf.model.Workbook;
-import org.apache.poi.hssf.record.BackupRecord;
-import org.apache.poi.hssf.record.ExtendedFormatRecord;
-import org.apache.poi.hssf.record.FontRecord;
-import org.apache.poi.hssf.record.NameRecord;
-import org.apache.poi.hssf.record.RecordFactory;
-import org.apache.poi.hssf.record.SSTRecord;
-import org.apache.poi.hssf.record.UnknownRecord;
-import org.apache.poi.hssf.record.WindowTwoRecord;
+import org.apache.poi.hssf.record.*;
import org.apache.poi.hssf.record.formula.Area3DPtg;
import org.apache.poi.hssf.record.formula.MemFuncPtg;
import org.apache.poi.hssf.record.formula.UnionPtg;
@@ -90,6 +83,8 @@
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.util.POILogFactory;
import org.apache.poi.util.POILogger;
+import org.apache.poi.util.HexDump;
+import org.apache.poi.ddf.*;
/**
* High level representation of a workbook. This is the first object most users
@@ -129,16 +124,16 @@
*/
private ArrayList sheets;
-
+
/**
* this holds the HSSFName objects attached to this workbook
*/
private ArrayList names;
-
+
/**
* holds whether or not to preserve other nodes in the POIFS. Used
- * for macros and embedded objects.
+ * for macros and embedded objects.
*/
private boolean preserveNodes;
@@ -155,7 +150,7 @@
* someplace else.
*/
private HSSFDataFormat formatter;
-
+
private static POILogger log = POILogFactory.getLogger(HSSFWorkbook.class);
/**
@@ -179,7 +174,7 @@
* low level models. If you're reading in a workbook...start here.
*
* @param fs the POI filesystem that contains the Workbook stream.
- * @param preserveNodes whether to preseve other nodes, such as
+ * @param preserveNodes whether to preseve other nodes, such as
* macros. This takes more memory, so only say yes if you
* need to.
* @see org.apache.poi.poifs.filesystem.POIFSFileSystem
@@ -190,20 +185,20 @@
throws IOException
{
this.preserveNodes = preserveNodes;
-
+
if (preserveNodes) {
- this.poifs = fs;
+ this.poifs = fs;
}
sheets = new ArrayList(INITIAL_CAPACITY);
names = new ArrayList(INITIAL_CAPACITY);
-
+
InputStream stream = fs.createDocumentInputStream("Workbook");
-
+
EventRecordFactory factory = new EventRecordFactory();
-
-
-
+
+
+
List records = RecordFactory.createRecords(stream);
workbook = Workbook.createWorkbook(records);
@@ -224,7 +219,7 @@
// workbook.setSheetName(sheets.size() -1, "Sheet"+sheets.size());
}
-
+
for (int i = 0 ; i < workbook.getNumNames() ; ++i){
HSSFName name = new HSSFName(workbook, workbook.getNameRecord(i));
names.add(name);
@@ -240,7 +235,7 @@
* inputstream.
*
* @param s the POI filesystem that contains the Workbook stream.
- * @param preserveNodes whether to preseve other nodes, such as
+ * @param preserveNodes whether to preseve other nodes, such as
* macros. This takes more memory, so only say yes if you
* need to.
* @see org.apache.poi.poifs.filesystem.POIFSFileSystem
@@ -264,22 +259,22 @@
// none currently
}
-
+
/**
* sets the order of appearance for a given sheet.
*
* @param sheetname the name of the sheet to reorder
* @param pos the position that we want to insert the sheet into (0 based)
*/
-
+
public void setSheetOrder(String sheetname, int pos ) {
workbook.setSheetOrder(sheetname, pos);
}
-
+
public final static byte ENCODING_COMPRESSED_UNICODE = 0;
public final static byte ENCODING_UTF_16 = 1;
-
-
+
+
/**
* set the sheet name.
* Will throw IllegalArgumentException if the name is greater than 31 chars
@@ -299,17 +294,17 @@
{
throw new RuntimeException("Sheet out of bounds");
}
-
+
switch ( encoding ) {
case ENCODING_COMPRESSED_UNICODE:
case ENCODING_UTF_16:
break;
-
+
default:
// TODO java.io.UnsupportedEncodingException
throw new RuntimeException( "Unsupported encoding" );
}
-
+
workbook.setSheetName( sheet, name, encoding );
}
@@ -337,14 +332,14 @@
/** Returns the index of the sheet by his name
* @param name the sheet name
* @return index of the sheet (0 based)
- */
+ */
public int getSheetIndex(String name)
{
int retval = workbook.getSheetIndex(name);
-
+
return retval;
}
-
+
/**
* create an HSSFSheet for this HSSFWorkbook, adds it to the sheets and returns
* the high level representation. Use this to create new sheets.
@@ -561,7 +556,7 @@
//does a lot of the house keeping for builtin records, like setting lengths to zero etc
isNewRecord = true;
}
-
+
short definitionTextLength = settingRowAndColumn ? (short)0x001a : (short)0x000b;
nameRecord.setDefinitionTextLength(definitionTextLength);
@@ -664,6 +659,40 @@
}
/**
+ * Finds a font that matches the one with the supplied attributes
+ */
+ public HSSFFont findFont(short boldWeight, short color, short fontHeight,
+ String name, boolean italic, boolean strikeout,
+ short typeOffset, byte underline)
+ {
+// System.out.println( boldWeight + ", " + color + ", " + fontHeight + ", " + name + ", " + italic + ", " + strikeout + ", " + typeOffset + ", " + underline );
+ for (short i = 0; i < workbook.getNumberOfFontRecords(); i++)
+ {
+ if (i == 4)
+ continue;
+
+ FontRecord font = workbook.getFontRecordAt(i);
+ HSSFFont hssfFont = new HSSFFont(i, font);
+// System.out.println( hssfFont.getBoldweight() + ", " + hssfFont.getColor() + ", " + hssfFont.getFontHeight() + ", " + hssfFont.getFontName() + ", " + hssfFont.getItalic() + ", " + hssfFont.getStrikeout() + ", " + hssfFont.getTypeOffset() + ", " + hssfFont.getUnderline() );
+ if (hssfFont.getBoldweight() == boldWeight
+ && hssfFont.getColor() == color
+ && hssfFont.getFontHeight() == fontHeight
+ && hssfFont.getFontName().equals(name)
+ && hssfFont.getItalic() == italic
+ && hssfFont.getStrikeout() == strikeout
+ && hssfFont.getTypeOffset() == typeOffset
+ && hssfFont.getUnderline() == underline)
+ {
+// System.out.println( "Found font" );
+ return hssfFont;
+ }
+ }
+
+// System.out.println( "No font found" );
+ return null;
+ }
+
+ /**
* get the number of fonts in the font table
* @return number of fonts
*/
@@ -741,10 +770,10 @@
{
byte[] bytes = getBytes();
POIFSFileSystem fs = new POIFSFileSystem();
-
+
fs.createDocument(new ByteArrayInputStream(bytes), "Workbook");
- if (preserveNodes) {
+ if (preserveNodes) {
List excepts = new ArrayList(1);
excepts.add("Workbook");
copyNodes(this.poifs,fs,excepts);
@@ -768,6 +797,12 @@
public byte[] getBytes()
{
log.log(DEBUG, "HSSFWorkbook.getBytes()");
+
+ // before getting the workbook size we must tell the sheets that
+ // serialization is about to occur.
+ for (int k = 0; k < sheets.size(); k++)
+ ((HSSFSheet) sheets.get(k)).getSheet().preSerialize();
+
int wbsize = workbook.getSize();
// log.debug("REMOVEME: old sizing method "+workbook.serialize().length);
@@ -777,10 +812,10 @@
for (int k = 0; k < sheets.size(); k++)
{
workbook.setSheetBof(k, totalsize);
-
- // sheetbytes.add((( HSSFSheet ) sheets.get(k)).getSheet().getSize());
totalsize += ((HSSFSheet) sheets.get(k)).getSheet().getSize();
}
+
+
/* if (totalsize < 4096)
{
totalsize = 4096;
@@ -818,58 +853,58 @@
{
return workbook;
}
-
+
/** gets the total number of named ranges in the workboko
* @return number of named ranges
- */
+ */
public int getNumberOfNames(){
int result = names.size();
return result;
}
-
+
/** gets the Named range
* @param index position of the named range
* @return named range high level
- */
+ */
public HSSFName getNameAt(int index){
HSSFName result = (HSSFName) names.get(index);
-
+
return result;
}
-
+
/** gets the named range name
* @param index the named range index (0 based)
* @return named range name
- */
+ */
public String getNameName(int index){
String result = getNameAt(index).getNameName();
-
+
return result;
}
-
+
/**
* Sets the printarea for the sheet provided
* <p>
* i.e. Reference = $A$1:$B$2
* @param sheetIndex Zero-based sheet index (0 Represents the first sheet to keep consistent with java)
- * @param reference Valid name Reference for the Print Area
+ * @param reference Valid name Reference for the Print Area
*/
public void setPrintArea(int sheetIndex, String reference)
{
NameRecord name = workbook.getSpecificBuiltinRecord(NameRecord.BUILTIN_PRINT_AREA, sheetIndex+1);
-
+
if (name == null)
name = workbook.createBuiltInName(NameRecord.BUILTIN_PRINT_AREA, sheetIndex+1);
//adding one here because 0 indicates a global named region; doesnt make sense for print areas
-
+
short externSheetIndex = getWorkbook().checkExternSheet(sheetIndex);
- name.setExternSheetNumber(externSheetIndex);
+ name.setExternSheetNumber(externSheetIndex);
name.setAreaReference(reference);
-
-
+
+
}
-
+
/**
* For the Convenience of Java Programmers maintaining pointers.
* @see setPrintArea(int, String)
@@ -881,57 +916,57 @@
*/
public void setPrintArea(int sheetIndex, int startColumn, int endColumn,
int startRow, int endRow) {
-
- //using absolute references because they dont get copied and pasted anyway
+
+ //using absolute references because they dont get copied and pasted anyway
CellReference cell = new CellReference(startRow, startColumn, true, true);
String reference = cell.toString();
-
+
cell = new CellReference(endRow, endColumn, true, true);
reference = reference+":"+cell.toString();
-
- setPrintArea(sheetIndex, reference);
+
+ setPrintArea(sheetIndex, reference);
}
-
-
+
+
/**
* Retrieves the reference for the printarea of the specified sheet, the sheet name is appended to the reference even if it was not specified.
- * @param sheetIndex Zero-based sheet index (0 Represents the first sheet to keep consistent with java)
+ * @param sheetIndex Zero-based sheet index (0 Represents the first sheet to keep consistent with java)
* @return String Null if no print area has been defined
- */
+ */
public String getPrintArea(int sheetIndex)
{
- NameRecord name = workbook.getSpecificBuiltinRecord(NameRecord.BUILTIN_PRINT_AREA, sheetIndex+1);
+ NameRecord name = workbook.getSpecificBuiltinRecord(NameRecord.BUILTIN_PRINT_AREA, sheetIndex+1);
if (name == null) return null;
//adding one here because 0 indicates a global named region; doesnt make sense for print areas
-
+
return name.getAreaReference(workbook);
- }
-
+ }
+
/**
* Delete the printarea for the sheet specified
* @param sheetIndex Zero-based sheet index (0 = First Sheet)
*/
public void removePrintArea(int sheetIndex) {
- getWorkbook().removeBuiltinRecord(NameRecord.BUILTIN_PRINT_AREA, sheetIndex+1);
+ getWorkbook().removeBuiltinRecord(NameRecord.BUILTIN_PRINT_AREA, sheetIndex+1);
}
-
+
/** creates a new named range and add it to the model
* @return named range high level
- */
+ */
public HSSFName createName(){
NameRecord nameRecord = workbook.createName();
-
+
HSSFName newName = new HSSFName(workbook, nameRecord);
-
+
names.add(newName);
-
- return newName;
+
+ return newName;
}
-
+
/** gets the named range index by his name
* @param name named range name
- * @return named range index
- */
+ * @return named range index
+ */
public int getNameIndex(String name)
{
int retval = -1;
@@ -952,10 +987,10 @@
/** remove the named range by his index
* @param index named range index (0 based)
- */
+ */
public void removeName(int index){
names.remove(index);
- workbook.removeName(index);
+ workbook.removeName(index);
}
/**
@@ -969,29 +1004,29 @@
formatter = new HSSFDataFormat(workbook);
return formatter;
}
-
+
/** remove the named range by his name
* @param name named range name
- */
+ */
public void removeName(String name){
int index = getNameIndex(name);
-
- removeName(index);
-
+
+ removeName(index);
+
}
public HSSFPalette getCustomPalette()
{
return new HSSFPalette(workbook.getCustomPalette());
}
-
+
/**
* Copies nodes from one POIFS to the other minus the excepts
* @param source is the source POIFS to copy from
- * @param target is the target POIFS to copy to
- * @param excepts is a list of Strings specifying what nodes NOT to copy
+ * @param target is the target POIFS to copy to
+ * @param excepts is a list of Strings specifying what nodes NOT to copy
*/
- private void copyNodes(POIFSFileSystem source, POIFSFileSystem target,
+ private void copyNodes(POIFSFileSystem source, POIFSFileSystem target,
List excepts) throws IOException {
//System.err.println("CopyNodes called");
@@ -999,13 +1034,13 @@
DirectoryEntry newRoot = target.getRoot();
Iterator entries = root.getEntries();
-
+
while (entries.hasNext()) {
Entry entry = (Entry)entries.next();
if (!isInList(entry.getName(), excepts)) {
copyNodeRecursively(entry,newRoot);
}
- }
+ }
}
private boolean isInList(String entry, List list) {
@@ -1017,18 +1052,18 @@
return false;
}
- private void copyNodeRecursively(Entry entry, DirectoryEntry target)
+ private void copyNodeRecursively(Entry entry, DirectoryEntry target)
throws IOException {
//System.err.println("copyNodeRecursively called with "+entry.getName()+
// ","+target.getName());
- DirectoryEntry newTarget = null;
+ DirectoryEntry newTarget = null;
if (entry.isDirectoryEntry()) {
newTarget = target.createDirectory(entry.getName());
Iterator entries = ((DirectoryEntry)entry).getEntries();
while (entries.hasNext()) {
copyNodeRecursively((Entry)entries.next(),newTarget);
- }
+ }
} else {
DocumentEntry dentry = (DocumentEntry)entry;
DocumentInputStream dstream = new DocumentInputStream(dentry);
@@ -1037,6 +1072,7 @@
}
}
+ /** Test only. Do not use */
public void insertChartRecord()
{
int loc = workbook.findFirstRecordLocBySid(SSTRecord.sid);
No revision
Index: HSSFWorkbook.java
===================================================================
RCS file: /home/cvs/jakarta-poi/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java,v
retrieving revision 1.24.2.4
retrieving revision 1.24.2.5
diff -u -r1.24.2.4 -r1.24.2.5
--- HSSFWorkbook.java 13 Oct 2003 16:45:01 -0000 1.24.2.4
+++ HSSFWorkbook.java 10 Feb 2004 22:00:27 -0000 1.24.2.5
@@ -71,14 +71,7 @@
import org.apache.poi.hssf.eventmodel.EventRecordFactory;
import org.apache.poi.hssf.model.Sheet;
import org.apache.poi.hssf.model.Workbook;
-import org.apache.poi.hssf.record.BackupRecord;
-import org.apache.poi.hssf.record.ExtendedFormatRecord;
-import org.apache.poi.hssf.record.FontRecord;
-import org.apache.poi.hssf.record.NameRecord;
-import org.apache.poi.hssf.record.RecordFactory;
-import org.apache.poi.hssf.record.SSTRecord;
-import org.apache.poi.hssf.record.UnknownRecord;
-import org.apache.poi.hssf.record.WindowTwoRecord;
+import org.apache.poi.hssf.record.*;
import org.apache.poi.hssf.record.formula.Area3DPtg;
import org.apache.poi.hssf.record.formula.MemFuncPtg;
import org.apache.poi.hssf.record.formula.UnionPtg;
@@ -90,6 +83,8 @@
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.util.POILogFactory;
import org.apache.poi.util.POILogger;
+import org.apache.poi.util.HexDump;
+import org.apache.poi.ddf.*;
/**
* High level representation of a workbook. This is the first object most users
@@ -129,16 +124,16 @@
*/
private ArrayList sheets;
-
+
/**
* this holds the HSSFName objects attached to this workbook
*/
private ArrayList names;
-
+
/**
* holds whether or not to preserve other nodes in the POIFS. Used
- * for macros and embedded objects.
+ * for macros and embedded objects.
*/
private boolean preserveNodes;
@@ -155,7 +150,7 @@
* someplace else.
*/
private HSSFDataFormat formatter;
-
+
private static POILogger log = POILogFactory.getLogger(HSSFWorkbook.class);
/**
@@ -179,7 +174,7 @@
* low level models. If you're reading in a workbook...start here.
*
* @param fs the POI filesystem that contains the Workbook stream.
- * @param preserveNodes whether to preseve other nodes, such as
+ * @param preserveNodes whether to preseve other nodes, such as
* macros. This takes more memory, so only say yes if you
* need to.
* @see org.apache.poi.poifs.filesystem.POIFSFileSystem
@@ -190,20 +185,20 @@
throws IOException
{
this.preserveNodes = preserveNodes;
-
+
if (preserveNodes) {
- this.poifs = fs;
+ this.poifs = fs;
}
sheets = new ArrayList(INITIAL_CAPACITY);
names = new ArrayList(INITIAL_CAPACITY);
-
+
InputStream stream = fs.createDocumentInputStream("Workbook");
-
+
EventRecordFactory factory = new EventRecordFactory();
-
-
-
+
+
+
List records = RecordFactory.createRecords(stream);
workbook = Workbook.createWorkbook(records);
@@ -224,7 +219,7 @@
// workbook.setSheetName(sheets.size() -1, "Sheet"+sheets.size());
}
-
+
for (int i = 0 ; i < workbook.getNumNames() ; ++i){
HSSFName name = new HSSFName(workbook, workbook.getNameRecord(i));
names.add(name);
@@ -240,7 +235,7 @@
* inputstream.
*
* @param s the POI filesystem that contains the Workbook stream.
- * @param preserveNodes whether to preseve other nodes, such as
+ * @param preserveNodes whether to preseve other nodes, such as
* macros. This takes more memory, so only say yes if you
* need to.
* @see org.apache.poi.poifs.filesystem.POIFSFileSystem
@@ -264,22 +259,22 @@
// none currently
}
-
+
/**
* sets the order of appearance for a given sheet.
*
* @param sheetname the name of the sheet to reorder
* @param pos the position that we want to insert the sheet into (0 based)
*/
-
+
public void setSheetOrder(String sheetname, int pos ) {
workbook.setSheetOrder(sheetname, pos);
}
-
+
public final static byte ENCODING_COMPRESSED_UNICODE = 0;
public final static byte ENCODING_UTF_16 = 1;
-
-
+
+
/**
* set the sheet name.
* Will throw IllegalArgumentException if the name is greater than 31 chars
@@ -299,17 +294,17 @@
{
throw new RuntimeException("Sheet out of bounds");
}
-
+
switch ( encoding ) {
case ENCODING_COMPRESSED_UNICODE:
case ENCODING_UTF_16:
break;
-
+
default:
// TODO java.io.UnsupportedEncodingException
throw new RuntimeException( "Unsupported encoding" );
}
-
+
workbook.setSheetName( sheet, name, encoding );
}
@@ -337,14 +332,14 @@
/** Returns the index of the sheet by his name
* @param name the sheet name
* @return index of the sheet (0 based)
- */
+ */
public int getSheetIndex(String name)
{
int retval = workbook.getSheetIndex(name);
-
+
return retval;
}
-
+
/**
* create an HSSFSheet for this HSSFWorkbook, adds it to the sheets and returns
* the high level representation. Use this to create new sheets.
@@ -561,7 +556,7 @@
//does a lot of the house keeping for builtin records, like setting lengths to zero etc
isNewRecord = true;
}
-
+
short definitionTextLength = settingRowAndColumn ? (short)0x001a : (short)0x000b;
nameRecord.setDefinitionTextLength(definitionTextLength);
@@ -664,6 +659,40 @@
}
/**
+ * Finds a font that matches the one with the supplied attributes
+ */
+ public HSSFFont findFont(short boldWeight, short color, short fontHeight,
+ String name, boolean italic, boolean strikeout,
+ short typeOffset, byte underline)
+ {
+// System.out.println( boldWeight + ", " + color + ", " + fontHeight + ", " + name + ", " + italic + ", " + strikeout + ", " + typeOffset + ", " + underline );
+ for (short i = 0; i < workbook.getNumberOfFontRecords(); i++)
+ {
+ if (i == 4)
+ continue;
+
+ FontRecord font = workbook.getFontRecordAt(i);
+ HSSFFont hssfFont = new HSSFFont(i, font);
+// System.out.println( hssfFont.getBoldweight() + ", " + hssfFont.getColor() + ", " + hssfFont.getFontHeight() + ", " + hssfFont.getFontName() + ", " + hssfFont.getItalic() + ", " + hssfFont.getStrikeout() + ", " + hssfFont.getTypeOffset() + ", " + hssfFont.getUnderline() );
+ if (hssfFont.getBoldweight() == boldWeight
+ && hssfFont.getColor() == color
+ && hssfFont.getFontHeight() == fontHeight
+ && hssfFont.getFontName().equals(name)
+ && hssfFont.getItalic() == italic
+ && hssfFont.getStrikeout() == strikeout
+ && hssfFont.getTypeOffset() == typeOffset
+ && hssfFont.getUnderline() == underline)
+ {
+// System.out.println( "Found font" );
+ return hssfFont;
+ }
+ }
+
+// System.out.println( "No font found" );
+ return null;
+ }
+
+ /**
* get the number of fonts in the font table
* @return number of fonts
*/
@@ -741,10 +770,10 @@
{
byte[] bytes = getBytes();
POIFSFileSystem fs = new POIFSFileSystem();
-
+
fs.createDocument(new ByteArrayInputStream(bytes), "Workbook");
- if (preserveNodes) {
+ if (preserveNodes) {
List excepts = new ArrayList(1);
excepts.add("Workbook");
copyNodes(this.poifs,fs,excepts);
@@ -768,6 +797,12 @@
public byte[] getBytes()
{
log.log(DEBUG, "HSSFWorkbook.getBytes()");
+
+ // before getting the workbook size we must tell the sheets that
+ // serialization is about to occur.
+ for (int k = 0; k < sheets.size(); k++)
+ ((HSSFSheet) sheets.get(k)).getSheet().preSerialize();
+
int wbsize = workbook.getSize();
// log.debug("REMOVEME: old sizing method "+workbook.serialize().length);
@@ -777,10 +812,10 @@
for (int k = 0; k < sheets.size(); k++)
{
workbook.setSheetBof(k, totalsize);
-
- // sheetbytes.add((( HSSFSheet ) sheets.get(k)).getSheet().getSize());
totalsize += ((HSSFSheet) sheets.get(k)).getSheet().getSize();
}
+
+
/* if (totalsize < 4096)
{
totalsize = 4096;
@@ -818,58 +853,58 @@
{
return workbook;
}
-
+
/** gets the total number of named ranges in the workboko
* @return number of named ranges
- */
+ */
public int getNumberOfNames(){
int result = names.size();
return result;
}
-
+
/** gets the Named range
* @param index position of the named range
* @return named range high level
- */
+ */
public HSSFName getNameAt(int index){
HSSFName result = (HSSFName) names.get(index);
-
+
return result;
}
-
+
/** gets the named range name
* @param index the named range index (0 based)
* @return named range name
- */
+ */
public String getNameName(int index){
String result = getNameAt(index).getNameName();
-
+
return result;
}
-
+
/**
* Sets the printarea for the sheet provided
* <p>
* i.e. Reference = $A$1:$B$2
* @param sheetIndex Zero-based sheet index (0 Represents the first sheet to keep consistent with java)
- * @param reference Valid name Reference for the Print Area
+ * @param reference Valid name Reference for the Print Area
*/
public void setPrintArea(int sheetIndex, String reference)
{
NameRecord name = workbook.getSpecificBuiltinRecord(NameRecord.BUILTIN_PRINT_AREA, sheetIndex+1);
-
+
if (name == null)
name = workbook.createBuiltInName(NameRecord.BUILTIN_PRINT_AREA, sheetIndex+1);
//adding one here because 0 indicates a global named region; doesnt make sense for print areas
-
+
short externSheetIndex = getWorkbook().checkExternSheet(sheetIndex);
- name.setExternSheetNumber(externSheetIndex);
+ name.setExternSheetNumber(externSheetIndex);
name.setAreaReference(reference);
-
-
+
+
}
-
+
/**
* For the Convenience of Java Programmers maintaining pointers.
* @see setPrintArea(int, String)
@@ -881,57 +916,57 @@
*/
public void setPrintArea(int sheetIndex, int startColumn, int endColumn,
int startRow, int endRow) {
-
- //using absolute references because they dont get copied and pasted anyway
+
+ //using absolute references because they dont get copied and pasted anyway
CellReference cell = new CellReference(startRow, startColumn, true, true);
String reference = cell.toString();
-
+
cell = new CellReference(endRow, endColumn, true, true);
reference = reference+":"+cell.toString();
-
- setPrintArea(sheetIndex, reference);
+
+ setPrintArea(sheetIndex, reference);
}
-
-
+
+
/**
* Retrieves the reference for the printarea of the specified sheet, the sheet name is appended to the reference even if it was not specified.
- * @param sheetIndex Zero-based sheet index (0 Represents the first sheet to keep consistent with java)
+ * @param sheetIndex Zero-based sheet index (0 Represents the first sheet to keep consistent with java)
* @return String Null if no print area has been defined
- */
+ */
public String getPrintArea(int sheetIndex)
{
- NameRecord name = workbook.getSpecificBuiltinRecord(NameRecord.BUILTIN_PRINT_AREA, sheetIndex+1);
+ NameRecord name = workbook.getSpecificBuiltinRecord(NameRecord.BUILTIN_PRINT_AREA, sheetIndex+1);
if (name == null) return null;
//adding one here because 0 indicates a global named region; doesnt make sense for print areas
-
+
return name.getAreaReference(workbook);
- }
-
+ }
+
/**
* Delete the printarea for the sheet specified
* @param sheetIndex Zero-based sheet index (0 = First Sheet)
*/
public void removePrintArea(int sheetIndex) {
- getWorkbook().removeBuiltinRecord(NameRecord.BUILTIN_PRINT_AREA, sheetIndex+1);
+ getWorkbook().removeBuiltinRecord(NameRecord.BUILTIN_PRINT_AREA, sheetIndex+1);
}
-
+
/** creates a new named range and add it to the model
* @return named range high level
- */
+ */
public HSSFName createName(){
NameRecord nameRecord = workbook.createName();
-
+
HSSFName newName = new HSSFName(workbook, nameRecord);
-
+
names.add(newName);
-
- return newName;
+
+ return newName;
}
-
+
/** gets the named range index by his name
* @param name named range name
- * @return named range index
- */
+ * @return named range index
+ */
public int getNameIndex(String name)
{
int retval = -1;
@@ -952,10 +987,10 @@
/** remove the named range by his index
* @param index named range index (0 based)
- */
+ */
public void removeName(int index){
names.remove(index);
- workbook.removeName(index);
+ workbook.removeName(index);
}
/**
@@ -969,29 +1004,29 @@
formatter = new HSSFDataFormat(workbook);
return formatter;
}
-
+
/** remove the named range by his name
* @param name named range name
- */
+ */
public void removeName(String name){
int index = getNameIndex(name);
-
- removeName(index);
-
+
+ removeName(index);
+
}
public HSSFPalette getCustomPalette()
{
return new HSSFPalette(workbook.getCustomPalette());
}
-
+
/**
* Copies nodes from one POIFS to the other minus the excepts
* @param source is the source POIFS to copy from
- * @param target is the target POIFS to copy to
- * @param excepts is a list of Strings specifying what nodes NOT to copy
+ * @param target is the target POIFS to copy to
+ * @param excepts is a list of Strings specifying what nodes NOT to copy
*/
- private void copyNodes(POIFSFileSystem source, POIFSFileSystem target,
+ private void copyNodes(POIFSFileSystem source, POIFSFileSystem target,
List excepts) throws IOException {
//System.err.println("CopyNodes called");
@@ -999,13 +1034,13 @@
DirectoryEntry newRoot = target.getRoot();
Iterator entries = root.getEntries();
-
+
while (entries.hasNext()) {
Entry entry = (Entry)entries.next();
if (!isInList(entry.getName(), excepts)) {
copyNodeRecursively(entry,newRoot);
}
- }
+ }
}
private boolean isInList(String entry, List list) {
@@ -1017,18 +1052,18 @@
return false;
}
- private void copyNodeRecursively(Entry entry, DirectoryEntry target)
+ private void copyNodeRecursively(Entry entry, DirectoryEntry target)
throws IOException {
//System.err.println("copyNodeRecursively called with "+entry.getName()+
// ","+target.getName());
- DirectoryEntry newTarget = null;
+ DirectoryEntry newTarget = null;
if (entry.isDirectoryEntry()) {
newTarget = target.createDirectory(entry.getName());
Iterator entries = ((DirectoryEntry)entry).getEntries();
while (entries.hasNext()) {
copyNodeRecursively((Entry)entries.next(),newTarget);
- }
+ }
} else {
DocumentEntry dentry = (DocumentEntry)entry;
DocumentInputStream dstream = new DocumentInputStream(dentry);
@@ -1037,6 +1072,7 @@
}
}
+ /** Test only. Do not use */
public void insertChartRecord()
{
int loc = workbook.findFirstRecordLocBySid(SSTRecord.sid);
No revision
Index: HSSFWorkbook.java
===================================================================
RCS file: /home/cvs/jakarta-poi/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java,v
retrieving revision 1.24.2.4
retrieving revision 1.24.2.5
diff -u -r1.24.2.4 -r1.24.2.5
--- HSSFWorkbook.java 13 Oct 2003 16:45:01 -0000 1.24.2.4
+++ HSSFWorkbook.java 10 Feb 2004 22:00:27 -0000 1.24.2.5
@@ -71,14 +71,7 @@
import org.apache.poi.hssf.eventmodel.EventRecordFactory;
import org.apache.poi.hssf.model.Sheet;
import org.apache.poi.hssf.model.Workbook;
-import org.apache.poi.hssf.record.BackupRecord;
-import org.apache.poi.hssf.record.ExtendedFormatRecord;
-import org.apache.poi.hssf.record.FontRecord;
-import org.apache.poi.hssf.record.NameRecord;
-import org.apache.poi.hssf.record.RecordFactory;
-import org.apache.poi.hssf.record.SSTRecord;
-import org.apache.poi.hssf.record.UnknownRecord;
-import org.apache.poi.hssf.record.WindowTwoRecord;
+import org.apache.poi.hssf.record.*;
import org.apache.poi.hssf.record.formula.Area3DPtg;
import org.apache.poi.hssf.record.formula.MemFuncPtg;
import org.apache.poi.hssf.record.formula.UnionPtg;
@@ -90,6 +83,8 @@
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.util.POILogFactory;
import org.apache.poi.util.POILogger;
+import org.apache.poi.util.HexDump;
+import org.apache.poi.ddf.*;
/**
* High level representation of a workbook. This is the first object most users
@@ -129,16 +124,16 @@
*/
private ArrayList sheets;
-
+
/**
* this holds the HSSFName objects attached to this workbook
*/
private ArrayList names;
-
+
/**
* holds whether or not to preserve other nodes in the POIFS. Used
- * for macros and embedded objects.
+ * for macros and embedded objects.
*/
private boolean preserveNodes;
@@ -155,7 +150,7 @@
* someplace else.
*/
private HSSFDataFormat formatter;
-
+
private static POILogger log = POILogFactory.getLogger(HSSFWorkbook.class);
/**
@@ -179,7 +174,7 @@
* low level models. If you're reading in a workbook...start here.
*
* @param fs the POI filesystem that contains the Workbook stream.
- * @param preserveNodes whether to preseve other nodes, such as
+ * @param preserveNodes whether to preseve other nodes, such as
* macros. This takes more memory, so only say yes if you
* need to.
* @see org.apache.poi.poifs.filesystem.POIFSFileSystem
@@ -190,20 +185,20 @@
throws IOException
{
this.preserveNodes = preserveNodes;
-
+
if (preserveNodes) {
- this.poifs = fs;
+ this.poifs = fs;
}
sheets = new ArrayList(INITIAL_CAPACITY);
names = new ArrayList(INITIAL_CAPACITY);
-
+
InputStream stream = fs.createDocumentInputStream("Workbook");
-
+
EventRecordFactory factory = new EventRecordFactory();
-
-
-
+
+
+
List records = RecordFactory.createRecords(stream);
workbook = Workbook.createWorkbook(records);
@@ -224,7 +219,7 @@
// workbook.setSheetName(sheets.size() -1, "Sheet"+sheets.size());
}
-
+
for (int i = 0 ; i < workbook.getNumNames() ; ++i){
HSSFName name = new HSSFName(workbook, workbook.getNameRecord(i));
names.add(name);
@@ -240,7 +235,7 @@
* inputstream.
*
* @param s the POI filesystem that contains the Workbook stream.
- * @param preserveNodes whether to preseve other nodes, such as
+ * @param preserveNodes whether to preseve other nodes, such as
* macros. This takes more memory, so only say yes if you
* need to.
* @see org.apache.poi.poifs.filesystem.POIFSFileSystem
@@ -264,22 +259,22 @@
// none currently
}
-
+
/**
* sets the order of appearance for a given sheet.
*
* @param sheetname the name of the sheet to reorder
* @param pos the position that we want to insert the sheet into (0 based)
*/
-
+
public void setSheetOrder(String sheetname, int pos ) {
workbook.setSheetOrder(sheetname, pos);
}
-
+
public final static byte ENCODING_COMPRESSED_UNICODE = 0;
public final static byte ENCODING_UTF_16 = 1;
-
-
+
+
/**
* set the sheet name.
* Will throw IllegalArgumentException if the name is greater than 31 chars
@@ -299,17 +294,17 @@
{
throw new RuntimeException("Sheet out of bounds");
}
-
+
switch ( encoding ) {
case ENCODING_COMPRESSED_UNICODE:
case ENCODING_UTF_16:
break;
-
+
default:
// TODO java.io.UnsupportedEncodingException
throw new RuntimeException( "Unsupported encoding" );
}
-
+
workbook.setSheetName( sheet, name, encoding );
}
@@ -337,14 +332,14 @@
/** Returns the index of the sheet by his name
* @param name the sheet name
* @return index of the sheet (0 based)
- */
+ */
public int getSheetIndex(String name)
{
int retval = workbook.getSheetIndex(name);
-
+
return retval;
}
-
+
/**
* create an HSSFSheet for this HSSFWorkbook, adds it to the sheets and returns
* the high level representation. Use this to create new sheets.
@@ -561,7 +556,7 @@
//does a lot of the house keeping for builtin records, like setting lengths to zero etc
isNewRecord = true;
}
-
+
short definitionTextLength = settingRowAndColumn ? (short)0x001a : (short)0x000b;
nameRecord.setDefinitionTextLength(definitionTextLength);
@@ -664,6 +659,40 @@
}
/**
+ * Finds a font that matches the one with the supplied attributes
+ */
+ public HSSFFont findFont(short boldWeight, short color, short fontHeight,
+ String name, boolean italic, boolean strikeout,
+ short typeOffset, byte underline)
+ {
+// System.out.println( boldWeight + ", " + color + ", " + fontHeight + ", " + name + ", " + italic + ", " + strikeout + ", " + typeOffset + ", " + underline );
+ for (short i = 0; i < workbook.getNumberOfFontRecords(); i++)
+ {
+ if (i == 4)
+ continue;
+
+ FontRecord font = workbook.getFontRecordAt(i);
+ HSSFFont hssfFont = new HSSFFont(i, font);
+// System.out.println( hssfFont.getBoldweight() + ", " + hssfFont.getColor() + ", " + hssfFont.getFontHeight() + ", " + hssfFont.getFontName() + ", " + hssfFont.getItalic() + ", " + hssfFont.getStrikeout() + ", " + hssfFont.getTypeOffset() + ", " + hssfFont.getUnderline() );
+ if (hssfFont.getBoldweight() == boldWeight
+ && hssfFont.getColor() == color
+ && hssfFont.getFontHeight() == fontHeight
+ && hssfFont.getFontName().equals(name)
+ && hssfFont.getItalic() == italic
+ && hssfFont.getStrikeout() == strikeout
+ && hssfFont.getTypeOffset() == typeOffset
+ && hssfFont.getUnderline() == underline)
+ {
+// System.out.println( "Found font" );
+ return hssfFont;
+ }
+ }
+
+// System.out.println( "No font found" );
+ return null;
+ }
+
+ /**
* get the number of fonts in the font table
* @return number of fonts
*/
@@ -741,10 +770,10 @@
{
byte[] bytes = getBytes();
POIFSFileSystem fs = new POIFSFileSystem();
-
+
fs.createDocument(new ByteArrayInputStream(bytes), "Workbook");
- if (preserveNodes) {
+ if (preserveNodes) {
List excepts = new ArrayList(1);
excepts.add("Workbook");
copyNodes(this.poifs,fs,excepts);
@@ -768,6 +797,12 @@
public byte[] getBytes()
{
log.log(DEBUG, "HSSFWorkbook.getBytes()");
+
+ // before getting the workbook size we must tell the sheets that
+ // serialization is about to occur.
+ for (int k = 0; k < sheets.size(); k++)
+ ((HSSFSheet) sheets.get(k)).getSheet().preSerialize();
+
int wbsize = workbook.getSize();
// log.debug("REMOVEME: old sizing method "+workbook.serialize().length);
@@ -777,10 +812,10 @@
for (int k = 0; k < sheets.size(); k++)
{
workbook.setSheetBof(k, totalsize);
-
- // sheetbytes.add((( HSSFSheet ) sheets.get(k)).getSheet().getSize());
totalsize += ((HSSFSheet) sheets.get(k)).getSheet().getSize();
}
+
+
/* if (totalsize < 4096)
{
totalsize = 4096;
@@ -818,58 +853,58 @@
{
return workbook;
}
-
+
/** gets the total number of named ranges in the workboko
* @return number of named ranges
- */
+ */
public int getNumberOfNames(){
int result = names.size();
return result;
}
-
+
/** gets the Named range
* @param index position of the named range
* @return named range high level
- */
+ */
public HSSFName getNameAt(int index){
HSSFName result = (HSSFName) names.get(index);
-
+
return result;
}
-
+
/** gets the named range name
* @param index the named range index (0 based)
* @return named range name
- */
+ */
public String getNameName(int index){
String result = getNameAt(index).getNameName();
-
+
return result;
}
-
+
/**
* Sets the printarea for the sheet provided
* <p>
* i.e. Reference = $A$1:$B$2
* @param sheetIndex Zero-based sheet index (0 Represents the first sheet to keep consistent with java)
- * @param reference Valid name Reference for the Print Area
+ * @param reference Valid name Reference for the Print Area
*/
public void setPrintArea(int sheetIndex, String reference)
{
NameRecord name = workbook.getSpecificBuiltinRecord(NameRecord.BUILTIN_PRINT_AREA, sheetIndex+1);
-
+
if (name == null)
name = workbook.createBuiltInName(NameRecord.BUILTIN_PRINT_AREA, sheetIndex+1);
//adding one here because 0 indicates a global named region; doesnt make sense for print areas
-
+
short externSheetIndex = getWorkbook().checkExternSheet(sheetIndex);
- name.setExternSheetNumber(externSheetIndex);
+ name.setExternSheetNumber(externSheetIndex);
name.setAreaReference(reference);
-
-
+
+
}
-
+
/**
* For the Convenience of Java Programmers maintaining pointers.
* @see setPrintArea(int, String)
@@ -881,57 +916,57 @@
*/
public void setPrintArea(int sheetIndex, int startColumn, int endColumn,
int startRow, int endRow) {
-
- //using absolute references because they dont get copied and pasted anyway
+
+ //using absolute references because they dont get copied and pasted anyway
CellReference cell = new CellReference(startRow, startColumn, true, true);
String reference = cell.toString();
-
+
cell = new CellReference(endRow, endColumn, true, true);
reference = reference+":"+cell.toString();
-
- setPrintArea(sheetIndex, reference);
+
+ setPrintArea(sheetIndex, reference);
}
-
-
+
+
/**
* Retrieves the reference for the printarea of the specified sheet, the sheet name is appended to the reference even if it was not specified.
- * @param sheetIndex Zero-based sheet index (0 Represents the first sheet to keep consistent with java)
+ * @param sheetIndex Zero-based sheet index (0 Represents the first sheet to keep consistent with java)
* @return String Null if no print area has been defined
- */
+ */
public String getPrintArea(int sheetIndex)
{
- NameRecord name = workbook.getSpecificBuiltinRecord(NameRecord.BUILTIN_PRINT_AREA, sheetIndex+1);
+ NameRecord name = workbook.getSpecificBuiltinRecord(NameRecord.BUILTIN_PRINT_AREA, sheetIndex+1);
if (name == null) return null;
//adding one here because 0 indicates a global named region; doesnt make sense for print areas
-
+
return name.getAreaReference(workbook);
- }
-
+ }
+
/**
* Delete the printarea for the sheet specified
* @param sheetIndex Zero-based sheet index (0 = First Sheet)
*/
public void removePrintArea(int sheetIndex) {
- getWorkbook().removeBuiltinRecord(NameRecord.BUILTIN_PRINT_AREA, sheetIndex+1);
+ getWorkbook().removeBuiltinRecord(NameRecord.BUILTIN_PRINT_AREA, sheetIndex+1);
}
-
+
/** creates a new named range and add it to the model
* @return named range high level
- */
+ */
public HSSFName createName(){
NameRecord nameRecord = workbook.createName();
-
+
HSSFName newName = new HSSFName(workbook, nameRecord);
-
+
names.add(newName);
-
- return newName;
+
+ return newName;
}
-
+
/** gets the named range index by his name
* @param name named range name
- * @return named range index
- */
+ * @return named range index
+ */
public int getNameIndex(String name)
{
int retval = -1;
@@ -952,10 +987,10 @@
/** remove the named range by his index
* @param index named range index (0 based)
- */
+ */
public void removeName(int index){
names.remove(index);
- workbook.removeName(index);
+ workbook.removeName(index);
}
/**
@@ -969,29 +1004,29 @@
formatter = new HSSFDataFormat(workbook);
return formatter;
}
-
+
/** remove the named range by his name
* @param name named range name
- */
+ */
public void removeName(String name){
int index = getNameIndex(name);
-
- removeName(index);
-
+
+ removeName(index);
+
}
public HSSFPalette getCustomPalette()
{
return new HSSFPalette(workbook.getCustomPalette());
}
-
+
/**
* Copies nodes from one POIFS to the other minus the excepts
* @param source is the source POIFS to copy from
- * @param target is the target POIFS to copy to
- * @param excepts is a list of Strings specifying what nodes NOT to copy
+ * @param target is the target POIFS to copy to
+ * @param excepts is a list of Strings specifying what nodes NOT to copy
*/
- private void copyNodes(POIFSFileSystem source, POIFSFileSystem target,
+ private void copyNodes(POIFSFileSystem source, POIFSFileSystem target,
List excepts) throws IOException {
//System.err.println("CopyNodes called");
@@ -999,13 +1034,13 @@
DirectoryEntry newRoot = target.getRoot();
Iterator entries = root.getEntries();
-
+
while (entries.hasNext()) {
Entry entry = (Entry)entries.next();
if (!isInList(entry.getName(), excepts)) {
copyNodeRecursively(entry,newRoot);
}
- }
+ }
}
private boolean isInList(String entry, List list) {
@@ -1017,18 +1052,18 @@
return false;
}
- private void copyNodeRecursively(Entry entry, DirectoryEntry target)
+ private void copyNodeRecursively(Entry entry, DirectoryEntry target)
throws IOException {
//System.err.println("copyNodeRecursively called with "+entry.getName()+
// ","+target.getName());
- DirectoryEntry newTarget = null;
+ DirectoryEntry newTarget = null;
if (entry.isDirectoryEntry()) {
newTarget = target.createDirectory(entry.getName());
Iterator entries = ((DirectoryEntry)entry).getEntries();
while (entries.hasNext()) {
copyNodeRecursively((Entry)entries.next(),newTarget);
- }
+ }
} else {
DocumentEntry dentry = (DocumentEntry)entry;
DocumentInputStream dstream = new DocumentInputStream(dentry);
@@ -1037,6 +1072,7 @@
}
}
+ /** Test only. Do not use */
public void insertChartRecord()
{
int loc = workbook.findFirstRecordLocBySid(SSTRecord.sid);
1.1.2.1 +773 -0 jakarta-poi/src/java/org/apache/poi/hssf/usermodel/Attic/DummyGraphics2d.java
1.1.2.1 +450 -0 jakarta-poi/src/java/org/apache/poi/hssf/usermodel/Attic/EscherGraphics.java
1.1.2.1 +567 -0 jakarta-poi/src/java/org/apache/poi/hssf/usermodel/Attic/EscherGraphics2d.java
1.1.2.1 +143 -0 jakarta-poi/src/java/org/apache/poi/hssf/usermodel/Attic/FontDetails.java
1.1.2.1 +40 -0 jakarta-poi/src/java/org/apache/poi/hssf/usermodel/Attic/HSSFAnchor.java
1.1.2.1 +37 -0 jakarta-poi/src/java/org/apache/poi/hssf/usermodel/Attic/HSSFChildAnchor.java
1.1.2.1 +207 -0 jakarta-poi/src/java/org/apache/poi/hssf/usermodel/Attic/HSSFClientAnchor.java
1.1.2.1 +159 -0 jakarta-poi/src/java/org/apache/poi/hssf/usermodel/Attic/HSSFPatriarch.java
1.1.2.1 +66 -0 jakarta-poi/src/java/org/apache/poi/hssf/usermodel/Attic/HSSFPolygon.java
1.1.2.1 +179 -0 jakarta-poi/src/java/org/apache/poi/hssf/usermodel/Attic/HSSFRichTextString.java
1.1.2.1 +195 -0 jakarta-poi/src/java/org/apache/poi/hssf/usermodel/Attic/HSSFShape.java
1.1.2.1 +17 -0 jakarta-poi/src/java/org/apache/poi/hssf/usermodel/Attic/HSSFShapeContainer.java
1.1.2.1 +148 -0 jakarta-poi/src/java/org/apache/poi/hssf/usermodel/Attic/HSSFShapeGroup.java
1.1.2.1 +64 -0 jakarta-poi/src/java/org/apache/poi/hssf/usermodel/Attic/HSSFSimpleShape.java
1.1.2.1 +107 -0 jakarta-poi/src/java/org/apache/poi/hssf/usermodel/Attic/HSSFTextbox.java
1.1.2.1 +81 -0 jakarta-poi/src/java/org/apache/poi/hssf/usermodel/Attic/StaticFontMetrics.java
---------------------------------------------------------------------
To unsubscribe, e-mail: poi-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: poi-dev-help@jakarta.apache.org