Nailed the sheet selection bug. Woohoo.
git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@352170 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
32c4ba9864
commit
5b54c6186d
@ -1,4 +1,3 @@
|
||||
|
||||
/* ====================================================================
|
||||
* The Apache Software License, Version 1.1
|
||||
*
|
||||
@ -60,20 +59,19 @@
|
||||
*/
|
||||
package org.apache.poi.hssf.usermodel;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.poi.hssf.HSSFLog;
|
||||
import org.apache.poi.hssf.model.Sheet;
|
||||
import org.apache.poi.hssf.model.Workbook;
|
||||
import org.apache.poi.hssf.record.*;
|
||||
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
|
||||
import org.apache.poi.util.POILogger;
|
||||
import org.apache.poi.hssf.HSSFLog;
|
||||
import org.apache.poi.hssf.model.Workbook;
|
||||
import org.apache.poi.hssf.model.Sheet;
|
||||
import org.apache.poi.hssf.record.*;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* High level representation of a workbook. This is the first object most users
|
||||
@ -165,7 +163,7 @@ public class HSSFWorkbook
|
||||
* Companion to HSSFWorkbook(POIFSFileSystem), this constructs the POI filesystem around your
|
||||
* inputstream.
|
||||
*
|
||||
* @param fs the POI filesystem that contains the Workbook stream.
|
||||
* @param s the POI filesystem that contains the Workbook stream.
|
||||
* @see org.apache.poi.poifs.filesystem.POIFSFileSystem
|
||||
* @see #HSSFWorkbook(POIFSFileSystem)
|
||||
* @exception IOException if the stream cannot be read
|
||||
@ -220,7 +218,7 @@ public class HSSFWorkbook
|
||||
|
||||
/**
|
||||
* get the sheet's index
|
||||
* @param sheet name
|
||||
* @param name sheet name
|
||||
* @return sheet index or -1 if it was not found.
|
||||
*/
|
||||
|
||||
@ -258,6 +256,9 @@ public class HSSFWorkbook
|
||||
sheets.add(sheet);
|
||||
workbook.setSheetName(sheets.size() - 1,
|
||||
"Sheet" + (sheets.size() - 1));
|
||||
WindowTwoRecord windowTwo = (WindowTwoRecord) sheet.getSheet().findFirstRecordBySid(WindowTwoRecord.sid);
|
||||
windowTwo.setSelected(sheets.size() == 1);
|
||||
windowTwo.setPaged(sheets.size() == 1);
|
||||
return sheet;
|
||||
}
|
||||
|
||||
@ -265,7 +266,7 @@ public class HSSFWorkbook
|
||||
* create an HSSFSheet for this HSSFWorkbook, adds it to the sheets and returns
|
||||
* the high level representation. Use this to create new sheets.
|
||||
*
|
||||
* @param Sheetname to set for the sheet.
|
||||
* @param sheetname sheetname to set for the sheet.
|
||||
* @return HSSFSheet representing the new sheet.
|
||||
*/
|
||||
|
||||
@ -278,6 +279,9 @@ public class HSSFWorkbook
|
||||
|
||||
sheets.add(sheet);
|
||||
workbook.setSheetName(sheets.size() - 1, sheetname);
|
||||
WindowTwoRecord windowTwo = (WindowTwoRecord) sheet.getSheet().findFirstRecordBySid(WindowTwoRecord.sid);
|
||||
windowTwo.setSelected(sheets.size() == 1);
|
||||
windowTwo.setPaged(sheets.size() == 1);
|
||||
return sheet;
|
||||
}
|
||||
|
||||
@ -299,7 +303,7 @@ public class HSSFWorkbook
|
||||
|
||||
public HSSFSheet getSheetAt(int index)
|
||||
{
|
||||
return ( HSSFSheet ) sheets.get(index);
|
||||
return (HSSFSheet) sheets.get(index);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -318,7 +322,7 @@ public class HSSFWorkbook
|
||||
|
||||
if (sheetname.equals(name))
|
||||
{
|
||||
retval = ( HSSFSheet ) sheets.get(k);
|
||||
retval = (HSSFSheet) sheets.get(k);
|
||||
}
|
||||
}
|
||||
return retval;
|
||||
@ -345,8 +349,8 @@ public class HSSFWorkbook
|
||||
{
|
||||
BackupRecord backupRecord = workbook.getBackupRecord();
|
||||
|
||||
backupRecord.setBackup(backupValue ? ( short ) 1
|
||||
: ( short ) 0);
|
||||
backupRecord.setBackup(backupValue ? (short) 1
|
||||
: (short) 0);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -371,7 +375,7 @@ public class HSSFWorkbook
|
||||
public HSSFFont createFont()
|
||||
{
|
||||
FontRecord font = workbook.createNewFont();
|
||||
short fontindex = ( short ) (getNumberOfFonts() - 1);
|
||||
short fontindex = (short) (getNumberOfFonts() - 1);
|
||||
|
||||
if (fontindex > 3)
|
||||
{
|
||||
@ -389,12 +393,12 @@ public class HSSFWorkbook
|
||||
|
||||
public short getNumberOfFonts()
|
||||
{
|
||||
return ( short ) workbook.getNumberOfFontRecords();
|
||||
return (short) workbook.getNumberOfFontRecords();
|
||||
}
|
||||
|
||||
/**
|
||||
* get the font at the given index number
|
||||
* @param index number
|
||||
* @param idx index number
|
||||
* @return HSSFFont at the index
|
||||
*/
|
||||
|
||||
@ -414,7 +418,7 @@ public class HSSFWorkbook
|
||||
public HSSFCellStyle createCellStyle()
|
||||
{
|
||||
ExtendedFormatRecord xfr = workbook.createCellXF();
|
||||
short index = ( short ) (getNumCellStyles() - 1);
|
||||
short index = (short) (getNumCellStyles() - 1);
|
||||
HSSFCellStyle style = new HSSFCellStyle(index, xfr);
|
||||
|
||||
return style;
|
||||
@ -427,12 +431,12 @@ public class HSSFWorkbook
|
||||
|
||||
public short getNumCellStyles()
|
||||
{
|
||||
return ( short ) workbook.getNumExFormats();
|
||||
return (short) workbook.getNumExFormats();
|
||||
}
|
||||
|
||||
/**
|
||||
* get the cell style object at the given index
|
||||
* @param index within the set of styles
|
||||
* @param idx index within the set of styles
|
||||
* @return HSSFCellStyle object at the index
|
||||
*/
|
||||
|
||||
@ -477,14 +481,13 @@ public class HSSFWorkbook
|
||||
* @see org.apache.poi.hssf.model.Sheet
|
||||
*/
|
||||
|
||||
public byte [] getBytes()
|
||||
public byte[] getBytes()
|
||||
{
|
||||
log.log(DEBUG, "HSSFWorkbook.getBytes()");
|
||||
int wbsize = workbook.getSize();
|
||||
|
||||
// log.debug("REMOVEME: old sizing method "+workbook.serialize().length);
|
||||
// ArrayList sheetbytes = new ArrayList(sheets.size());
|
||||
int sheetsize = 0;
|
||||
int totalsize = wbsize;
|
||||
|
||||
for (int k = 0; k < sheets.size(); k++)
|
||||
@ -492,13 +495,13 @@ public class HSSFWorkbook
|
||||
workbook.setSheetBof(k, totalsize);
|
||||
|
||||
// sheetbytes.add((( HSSFSheet ) sheets.get(k)).getSheet().getSize());
|
||||
totalsize += (( HSSFSheet ) sheets.get(k)).getSheet().getSize();
|
||||
totalsize += ((HSSFSheet) sheets.get(k)).getSheet().getSize();
|
||||
}
|
||||
if (totalsize < 4096)
|
||||
{
|
||||
totalsize = 4096;
|
||||
}
|
||||
byte[] retval = new byte[ totalsize ];
|
||||
byte[] retval = new byte[totalsize];
|
||||
int pos = workbook.serialize(0, retval);
|
||||
|
||||
// System.arraycopy(wb, 0, retval, 0, wb.length);
|
||||
@ -507,12 +510,12 @@ public class HSSFWorkbook
|
||||
|
||||
// byte[] sb = (byte[])sheetbytes.get(k);
|
||||
// System.arraycopy(sb, 0, retval, pos, sb.length);
|
||||
pos += (( HSSFSheet ) sheets.get(k)).getSheet().serialize(pos,
|
||||
pos += ((HSSFSheet) sheets.get(k)).getSheet().serialize(pos,
|
||||
retval); // sb.length;
|
||||
}
|
||||
for (int k = pos; k < totalsize; k++)
|
||||
{
|
||||
retval[ k ] = 0;
|
||||
retval[k] = 0;
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user