Methods Summary |
---|
public int | addPicture(byte[] pictureData, int format)Adds a picture to the workbook.
byte[] uid = newUID();
EscherBitmapBlip blipRecord = new EscherBitmapBlip();
blipRecord.setRecordId( (short) ( EscherBitmapBlip.RECORD_ID_START + format ) );
switch (format)
{
case PICTURE_TYPE_EMF:
blipRecord.setOptions(HSSFPictureData.MSOBI_EMF);
break;
case PICTURE_TYPE_WMF:
blipRecord.setOptions(HSSFPictureData.MSOBI_WMF);
break;
case PICTURE_TYPE_PICT:
blipRecord.setOptions(HSSFPictureData.MSOBI_PICT);
break;
case PICTURE_TYPE_PNG:
blipRecord.setOptions(HSSFPictureData.MSOBI_PNG);
break;
case HSSFWorkbook.PICTURE_TYPE_JPEG:
blipRecord.setOptions(HSSFPictureData.MSOBI_JPEG);
break;
case HSSFWorkbook.PICTURE_TYPE_DIB:
blipRecord.setOptions(HSSFPictureData.MSOBI_DIB);
break;
}
blipRecord.setUID( uid );
blipRecord.setMarker( (byte) 0xFF );
blipRecord.setPictureData( pictureData );
EscherBSERecord r = new EscherBSERecord();
r.setRecordId( EscherBSERecord.RECORD_ID );
r.setOptions( (short) ( 0x0002 | ( format << 4 ) ) );
r.setBlipTypeMacOS( (byte) format );
r.setBlipTypeWin32( (byte) format );
r.setUid( uid );
r.setTag( (short) 0xFF );
r.setSize( pictureData.length + 25 );
r.setRef( 1 );
r.setOffset( 0 );
r.setBlipRecord( blipRecord );
return workbook.addBSERecord( r );
|
public int | addSSTString(java.lang.String string)
return workbook.addSSTString(new UnicodeString(string));
|
public org.apache.poi.hssf.usermodel.HSSFSheet | cloneSheet(int sheetNum)create an HSSFSheet from an existing sheet in the HSSFWorkbook.
HSSFSheet srcSheet = (HSSFSheet)sheets.get(sheetNum);
String srcName = workbook.getSheetName(sheetNum);
if (srcSheet != null) {
HSSFSheet clonedSheet = srcSheet.cloneSheet(workbook);
WindowTwoRecord windowTwo = (WindowTwoRecord) clonedSheet.getSheet().findFirstRecordBySid(WindowTwoRecord.sid);
windowTwo.setSelected(sheets.size() == 1);
windowTwo.setPaged(sheets.size() == 1);
sheets.add(clonedSheet);
int i=1;
while (true) {
//Try and find the next sheet name that is unique
String name = srcName;
String index = Integer.toString(i++);
if (name.length()+index.length()+2<31)
name = name + "("+index+")";
else name = name.substring(0, 31-index.length()-2)+"("+index+")";
//If the sheet name is unique, then set it otherwise move on to the next number.
if (workbook.getSheetIndex(name) == -1) {
workbook.setSheetName(sheets.size()-1, name);
break;
}
}
return clonedSheet;
}
return null;
|
private void | convertLabelRecords(java.util.List records, int offset)This is basically a kludge to deal with the now obsolete Label records. If
you have to read in a sheet that contains Label records, be aware that the rest
of the API doesn't deal with them, the low level structure only provides read-only
semi-immutable structures (the sets are there for interface conformance with NO
impelmentation). In short, you need to call this function passing it a reference
to the Workbook object. All labels will be converted to LabelSST records and their
contained strings will be written to the Shared String tabel (SSTRecord) within
the Workbook.
if (log.check( POILogger.DEBUG ))
log.log(POILogger.DEBUG, "convertLabelRecords called");
for (int k = offset; k < records.size(); k++)
{
Record rec = ( Record ) records.get(k);
if (rec.getSid() == LabelRecord.sid)
{
LabelRecord oldrec = ( LabelRecord ) rec;
records.remove(k);
LabelSSTRecord newrec = new LabelSSTRecord();
int stringid =
workbook.addSSTString(new UnicodeString(oldrec.getValue()));
newrec.setRow(oldrec.getRow());
newrec.setColumn(oldrec.getColumn());
newrec.setXFIndex(oldrec.getXFIndex());
newrec.setSSTIndex(stringid);
records.add(k, newrec);
}
}
if (log.check( POILogger.DEBUG ))
log.log(POILogger.DEBUG, "convertLabelRecords exit");
|
private void | copyNodeRecursively(org.apache.poi.poifs.filesystem.Entry entry, org.apache.poi.poifs.filesystem.DirectoryEntry target)
//System.err.println("copyNodeRecursively called with "+entry.getName()+
// ","+target.getName());
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);
target.createDocument(dentry.getName(),dstream);
dstream.close();
}
|
private void | copyNodes(org.apache.poi.poifs.filesystem.POIFSFileSystem source, org.apache.poi.poifs.filesystem.POIFSFileSystem target, java.util.List excepts)Copies nodes from one POIFS to the other minus the excepts
//System.err.println("CopyNodes called");
DirectoryEntry root = source.getRoot();
DirectoryEntry newRoot = target.getRoot();
Iterator entries = root.getEntries();
while (entries.hasNext()) {
Entry entry = (Entry)entries.next();
if (!isInList(entry.getName(), excepts)) {
copyNodeRecursively(entry,newRoot);
}
}
|
public org.apache.poi.hssf.usermodel.HSSFCellStyle | createCellStyle()create a new Cell style and add it to the workbook's style table
ExtendedFormatRecord xfr = workbook.createCellXF();
short index = (short) (getNumCellStyles() - 1);
HSSFCellStyle style = new HSSFCellStyle(index, xfr);
return style;
|
public org.apache.poi.hssf.usermodel.HSSFDataFormat | createDataFormat()Returns the instance of HSSFDataFormat for this workbook.
if (formatter == null)
formatter = new HSSFDataFormat(workbook);
return formatter;
|
public org.apache.poi.hssf.usermodel.HSSFFont | createFont()create a new Font and add it to the workbook's font table
FontRecord font = workbook.createNewFont();
short fontindex = (short) (getNumberOfFonts() - 1);
if (fontindex > 3)
{
fontindex++; // THERE IS NO FOUR!!
}
HSSFFont retval = new HSSFFont(fontindex, font);
return retval;
|
public org.apache.poi.hssf.usermodel.HSSFName | createName()creates a new named range and add it to the model
NameRecord nameRecord = workbook.createName();
HSSFName newName = new HSSFName(workbook, nameRecord);
names.add(newName);
return newName;
|
public org.apache.poi.hssf.usermodel.HSSFSheet | createSheet()create an HSSFSheet for this HSSFWorkbook, adds it to the sheets and returns
the high level representation. Use this to create new sheets.
// if (getNumberOfSheets() == 3)
// throw new RuntimeException("You cannot have more than three sheets in HSSF 1.0");
HSSFSheet sheet = new HSSFSheet(workbook);
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;
|
public org.apache.poi.hssf.usermodel.HSSFSheet | createSheet(java.lang.String sheetname)create an HSSFSheet for this HSSFWorkbook, adds it to the sheets and returns
the high level representation. Use this to create new sheets.
if (workbook.doesContainsSheetName( sheetname, sheets.size() ))
throw new IllegalArgumentException( "The workbook already contains a sheet of this name" );
HSSFSheet sheet = new HSSFSheet(workbook);
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;
|
public void | dumpDrawingGroupRecords(boolean fat)Spits out a list of all the drawing records in the workbook.
DrawingGroupRecord r = (DrawingGroupRecord) workbook.findFirstRecordBySid( DrawingGroupRecord.sid );
r.decode();
List escherRecords = r.getEscherRecords();
PrintWriter w = new PrintWriter(System.out);
for ( Iterator iterator = escherRecords.iterator(); iterator.hasNext(); )
{
EscherRecord escherRecord = (EscherRecord) iterator.next();
if (fat)
System.out.println(escherRecord.toString());
else
escherRecord.display(w, 0);
}
w.flush();
|
private org.apache.poi.hssf.record.NameRecord | findExistingRowColHeaderNameRecord(int sheetIndex)
int index = findExistingRowColHeaderNameRecordIdx(sheetIndex);
if (index == -1)
return null;
else
return (NameRecord)workbook.findNextRecordBySid(NameRecord.sid, index);
|
private int | findExistingRowColHeaderNameRecordIdx(int sheetIndex)
int index = 0;
NameRecord r = null;
while ((r = (NameRecord) workbook.findNextRecordBySid(NameRecord.sid, index)) != null)
{
int indexToSheet = r.getEqualsToIndexToSheet() -1;
if(indexToSheet > -1) { //ignore "GLOBAL" name records
int nameRecordSheetIndex = workbook.getSheetIndexFromExternSheetIndex(indexToSheet);
if (isRowColHeaderRecord( r ) && nameRecordSheetIndex == sheetIndex)
{
return index;
}
}
index++;
}
return -1;
|
public org.apache.poi.hssf.usermodel.HSSFFont | findFont(short boldWeight, short color, short fontHeight, java.lang.String name, boolean italic, boolean strikeout, short typeOffset, byte underline)Finds a font that matches the one with the supplied attributes
// 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;
|
public java.util.List | getAllPictures()Gets all pictures from the Workbook.
List pictures = new ArrayList();
Iterator recordIter = workbook.getRecords().iterator();
while (recordIter.hasNext())
{
Object obj = recordIter.next();
if (obj instanceof AbstractEscherHolderRecord)
{
((AbstractEscherHolderRecord) obj).decode();
List escherRecords = ((AbstractEscherHolderRecord) obj).getEscherRecords();
searchForPictures(escherRecords, pictures);
}
}
return pictures;
|
public boolean | getBackupFlag()determine whether the Excel GUI will backup the workbook when saving.
BackupRecord backupRecord = workbook.getBackupRecord();
return (backupRecord.getBackup() == 0) ? false
: true;
|
public byte[] | getBytes()Method getBytes - get the bytes of just the HSSF portions of the XLS file.
Use this to construct a POI POIFSFileSystem yourself.
if (log.check( POILogger.DEBUG ))
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);
// ArrayList sheetbytes = new ArrayList(sheets.size());
int totalsize = wbsize;
for (int k = 0; k < sheets.size(); k++)
{
workbook.setSheetBof(k, totalsize);
totalsize += ((HSSFSheet) sheets.get(k)).getSheet().getSize();
}
/* if (totalsize < 4096)
{
totalsize = 4096;
}*/
byte[] retval = new byte[totalsize];
int pos = workbook.serialize(0, retval);
// System.arraycopy(wb, 0, retval, 0, wb.length);
for (int k = 0; k < sheets.size(); k++)
{
// byte[] sb = (byte[])sheetbytes.get(k);
// System.arraycopy(sb, 0, retval, pos, sb.length);
int len = ((HSSFSheet) sheets.get(k)).getSheet().serialize(pos,
retval);
pos += len; // sb.length;
}
/* for (int k = pos; k < totalsize; k++)
{
retval[k] = 0;
}*/
return retval;
|
public org.apache.poi.hssf.usermodel.HSSFCellStyle | getCellStyleAt(short idx)get the cell style object at the given index
ExtendedFormatRecord xfr = workbook.getExFormatAt(idx);
HSSFCellStyle style = new HSSFCellStyle(idx, xfr);
return style;
|
public org.apache.poi.hssf.usermodel.HSSFPalette | getCustomPalette()
return new HSSFPalette(workbook.getCustomPalette());
|
public short | getDisplayedTab()sets the first tab that is displayed in the list of tabs
in excel.
return workbook.getWindowOne().getDisplayedTab();
|
public org.apache.poi.hssf.usermodel.HSSFFont | getFontAt(short idx)get the font at the given index number
FontRecord font = workbook.getFontRecordAt(idx);
HSSFFont retval = new HSSFFont(idx, font);
return retval;
|
public org.apache.poi.hssf.usermodel.HSSFName | getNameAt(int index)gets the Named range
HSSFName result = (HSSFName) names.get(index);
return result;
|
public int | getNameIndex(java.lang.String name)gets the named range index by his name
Note:Excel named ranges are case-insensitive and
this method performs a case-insensitive search.
int retval = -1;
for (int k = 0; k < names.size(); k++)
{
String nameName = getNameName(k);
if (nameName.equalsIgnoreCase(name))
{
retval = k;
break;
}
}
return retval;
|
public java.lang.String | getNameName(int index)gets the named range name
String result = getNameAt(index).getNameName();
return result;
|
public short | getNumCellStyles()get the number of styles the workbook contains
return (short) workbook.getNumExFormats();
|
public short | getNumberOfFonts()get the number of fonts in the font table
return (short) workbook.getNumberOfFontRecords();
|
public int | getNumberOfNames()gets the total number of named ranges in the workboko
int result = names.size();
return result;
|
public int | getNumberOfSheets()get the number of spreadsheets in the workbook (this will be three after serialization)
return sheets.size();
|
public java.lang.String | getPrintArea(int sheetIndex)Retrieves the reference for the printarea of the specified sheet, the sheet name is appended to the reference even if it was not specified.
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);
|
public java.lang.String | getSSTString(int index)
return workbook.getSSTString(index).getString();
|
public short | getSelectedTab()gets the tab whose data is actually seen when the sheet is opened.
This may be different from the "selected sheet" since excel seems to
allow you to show the data of one sheet when another is seen "selected"
in the tabs (at the bottom).
return workbook.getWindowOne().getSelectedTab();
|
public org.apache.poi.hssf.usermodel.HSSFSheet | getSheet(java.lang.String name)Get sheet with the given name
HSSFSheet retval = null;
for (int k = 0; k < sheets.size(); k++)
{
String sheetname = workbook.getSheetName(k);
if (sheetname.equals(name))
{
retval = (HSSFSheet) sheets.get(k);
}
}
return retval;
|
public org.apache.poi.hssf.usermodel.HSSFSheet | getSheetAt(int index)Get the HSSFSheet object at the given index.
return (HSSFSheet) sheets.get(index);
|
public int | getSheetIndex(java.lang.String name)Returns the index of the sheet by his name
int retval = workbook.getSheetIndex(name);
return retval;
|
public java.lang.String | getSheetName(int sheet)get the sheet name
if (sheet > (sheets.size() - 1))
{
throw new RuntimeException("Sheet out of bounds");
}
return workbook.getSheetName(sheet);
|
org.apache.poi.hssf.model.Workbook | getWorkbook()
return workbook;
|
public void | insertChartRecord()Test only. Do not use
int loc = workbook.findFirstRecordLocBySid(SSTRecord.sid);
byte[] data = {
(byte)0x0F, (byte)0x00, (byte)0x00, (byte)0xF0, (byte)0x52,
(byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,
(byte)0x06, (byte)0xF0, (byte)0x18, (byte)0x00, (byte)0x00,
(byte)0x00, (byte)0x01, (byte)0x08, (byte)0x00, (byte)0x00,
(byte)0x02, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x02,
(byte)0x00, (byte)0x00, (byte)0x00, (byte)0x01, (byte)0x00,
(byte)0x00, (byte)0x00, (byte)0x01, (byte)0x00, (byte)0x00,
(byte)0x00, (byte)0x03, (byte)0x00, (byte)0x00, (byte)0x00,
(byte)0x33, (byte)0x00, (byte)0x0B, (byte)0xF0, (byte)0x12,
(byte)0x00, (byte)0x00, (byte)0x00, (byte)0xBF, (byte)0x00,
(byte)0x08, (byte)0x00, (byte)0x08, (byte)0x00, (byte)0x81,
(byte)0x01, (byte)0x09, (byte)0x00, (byte)0x00, (byte)0x08,
(byte)0xC0, (byte)0x01, (byte)0x40, (byte)0x00, (byte)0x00,
(byte)0x08, (byte)0x40, (byte)0x00, (byte)0x1E, (byte)0xF1,
(byte)0x10, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x0D,
(byte)0x00, (byte)0x00, (byte)0x08, (byte)0x0C, (byte)0x00,
(byte)0x00, (byte)0x08, (byte)0x17, (byte)0x00, (byte)0x00,
(byte)0x08, (byte)0xF7, (byte)0x00, (byte)0x00, (byte)0x10,
};
UnknownRecord r = new UnknownRecord((short)0x00EB, data);
workbook.getRecords().add(loc, r);
|
private boolean | isInList(java.lang.String entry, java.util.List list)
for (int k = 0; k < list.size(); k++) {
if (list.get(k).equals(entry)) {
return true;
}
}
return false;
|
private boolean | isRowColHeaderRecord(org.apache.poi.hssf.record.NameRecord r)
return r.getOptionFlag() == 0x20 && ("" + ((char)7)).equals(r.getNameText());
|
private byte[] | newUID()
byte[] bytes = new byte[16];
return bytes;
|
public void | removeName(int index)remove the named range by his index
names.remove(index);
workbook.removeName(index);
|
public void | removeName(java.lang.String name)remove the named range by his name
int index = getNameIndex(name);
removeName(index);
|
public void | removePrintArea(int sheetIndex)Delete the printarea for the sheet specified
getWorkbook().removeBuiltinRecord(NameRecord.BUILTIN_PRINT_AREA, sheetIndex+1);
|
public void | removeSheetAt(int index)removes sheet at the given index
sheets.remove(index);
workbook.removeSheet(index);
|
private void | searchForPictures(java.util.List escherRecords, java.util.List pictures)Performs a recursive search for pictures in the given list of escher records.
Iterator recordIter = escherRecords.iterator();
while (recordIter.hasNext())
{
Object obj = recordIter.next();
if (obj instanceof EscherRecord)
{
EscherRecord escherRecord = (EscherRecord) obj;
if (escherRecord instanceof EscherBSERecord)
{
EscherBlipRecord blip = ((EscherBSERecord) escherRecord).getBlipRecord();
if (blip instanceof EscherBitmapBlip)
{
// TODO: Some kind of structure.
pictures.add(new HSSFPictureData((EscherBitmapBlip) blip));
}
}
// Recursive call.
searchForPictures(escherRecord.getChildRecords(), pictures);
}
}
|
public void | setBackupFlag(boolean backupValue)determine whether the Excel GUI will backup the workbook when saving.
BackupRecord backupRecord = workbook.getBackupRecord();
backupRecord.setBackup(backupValue ? (short) 1
: (short) 0);
|
public void | setDisplayedTab(short index)sets the first tab that is displayed in the list of tabs
in excel.
workbook.getWindowOne().setDisplayedTab(index);
|
public void | setPrintArea(int sheetIndex, java.lang.String reference)Sets the printarea for the sheet provided
i.e. Reference = $A$1:$B$2
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.setAreaReference(reference);
|
public void | setPrintArea(int sheetIndex, int startColumn, int endColumn, int startRow, int endRow)For the Convenience of Java Programmers maintaining pointers.
//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);
|
private void | setPropertiesFromWorkbook(org.apache.poi.hssf.model.Workbook book)used internally to set the workbook properties.
this.workbook = book;
// none currently
|
public void | setRepeatingRowsAndColumns(int sheetIndex, int startColumn, int endColumn, int startRow, int endRow)Sets the repeating rows and columns for a sheet (as found in
File->PageSetup->Sheet). This is function is included in the workbook
because it creates/modifies name records which are stored at the
workbook level.
To set just repeating columns:
workbook.setRepeatingRowsAndColumns(0,0,1,-1-1);
To set just repeating rows:
workbook.setRepeatingRowsAndColumns(0,-1,-1,0,4);
To remove all repeating rows and columns for a sheet.
workbook.setRepeatingRowsAndColumns(0,-1,-1,-1,-1);
// Check arguments
if (startColumn == -1 && endColumn != -1) throw new IllegalArgumentException("Invalid column range specification");
if (startRow == -1 && endRow != -1) throw new IllegalArgumentException("Invalid row range specification");
if (startColumn < -1 || startColumn >= 0xFF) throw new IllegalArgumentException("Invalid column range specification");
if (endColumn < -1 || endColumn >= 0xFF) throw new IllegalArgumentException("Invalid column range specification");
if (startRow < -1 || startRow > 65535) throw new IllegalArgumentException("Invalid row range specification");
if (endRow < -1 || endRow > 65535) throw new IllegalArgumentException("Invalid row range specification");
if (startColumn > endColumn) throw new IllegalArgumentException("Invalid column range specification");
if (startRow > endRow) throw new IllegalArgumentException("Invalid row range specification");
HSSFSheet sheet = getSheetAt(sheetIndex);
short externSheetIndex = getWorkbook().checkExternSheet(sheetIndex);
boolean settingRowAndColumn =
startColumn != -1 && endColumn != -1 && startRow != -1 && endRow != -1;
boolean removingRange =
startColumn == -1 && endColumn == -1 && startRow == -1 && endRow == -1;
boolean isNewRecord = false;
NameRecord nameRecord;
nameRecord = findExistingRowColHeaderNameRecord(sheetIndex);
if (removingRange )
{
if (nameRecord != null)
workbook.removeName(findExistingRowColHeaderNameRecordIdx(sheetIndex+1));
return;
}
if ( nameRecord == null )
{
nameRecord = workbook.createBuiltInName(NameRecord.BUILTIN_PRINT_TITLE, sheetIndex+1);
//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);
Stack ptgs = new Stack();
if (settingRowAndColumn)
{
MemFuncPtg memFuncPtg = new MemFuncPtg();
memFuncPtg.setLenRefSubexpression(23);
ptgs.add(memFuncPtg);
}
if (startColumn >= 0)
{
Area3DPtg area3DPtg1 = new Area3DPtg();
area3DPtg1.setExternSheetIndex(externSheetIndex);
area3DPtg1.setFirstColumn((short)startColumn);
area3DPtg1.setLastColumn((short)endColumn);
area3DPtg1.setFirstRow((short)0);
area3DPtg1.setLastRow((short)0xFFFF);
ptgs.add(area3DPtg1);
}
if (startRow >= 0)
{
Area3DPtg area3DPtg2 = new Area3DPtg();
area3DPtg2.setExternSheetIndex(externSheetIndex);
area3DPtg2.setFirstColumn((short)0);
area3DPtg2.setLastColumn((short)0x00FF);
area3DPtg2.setFirstRow((short)startRow);
area3DPtg2.setLastRow((short)endRow);
ptgs.add(area3DPtg2);
}
if (settingRowAndColumn)
{
UnionPtg unionPtg = new UnionPtg();
ptgs.add(unionPtg);
}
nameRecord.setNameDefinition(ptgs);
if (isNewRecord)
{
HSSFName newName = new HSSFName(workbook, nameRecord);
names.add(newName);
}
HSSFPrintSetup printSetup = sheet.getPrintSetup();
printSetup.setValidSettings(false);
WindowTwoRecord w2 = (WindowTwoRecord) sheet.getSheet().findFirstRecordBySid(WindowTwoRecord.sid);
w2.setPaged(true);
|
public void | setSelectedTab(short index)sets the tab whose data is actually seen when the sheet is opened.
This may be different from the "selected sheet" since excel seems to
allow you to show the data of one sheet when another is seen "selected"
in the tabs (at the bottom).
workbook.getWindowOne().setSelectedTab(index);
|
public void | setSheetName(int sheet, java.lang.String name)set the sheet name.
Will throw IllegalArgumentException if the name is greater than 31 chars
or contains /\?*[]
if (workbook.doesContainsSheetName( name, sheet ))
throw new IllegalArgumentException( "The workbook already contains a sheet with this name" );
if (sheet > (sheets.size() - 1))
{
throw new RuntimeException("Sheet out of bounds");
}
workbook.setSheetName( sheet, name);
|
public void | setSheetName(int sheet, java.lang.String name, short encoding)set the sheet name forcing the encoding. Forcing the encoding IS A BAD IDEA!!!
if (workbook.doesContainsSheetName( name, sheet ))
throw new IllegalArgumentException( "The workbook already contains a sheet with this name" );
if (sheet > (sheets.size() - 1))
{
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 );
|
public void | setSheetOrder(java.lang.String sheetname, int pos)sets the order of appearance for a given sheet.
sheets.add(pos,sheets.remove(getSheetIndex(sheetname)));
workbook.setSheetOrder(sheetname, pos);
|
public void | write(java.io.OutputStream stream)Method write - write out this workbook to an Outputstream. Constructs
a new POI POIFSFileSystem, passes in the workbook binary representation and
writes it out.
byte[] bytes = getBytes();
POIFSFileSystem fs = new POIFSFileSystem();
fs.createDocument(new ByteArrayInputStream(bytes), "Workbook");
if (preserveNodes) {
List excepts = new ArrayList(1);
excepts.add("Workbook");
copyNodes(this.poifs,fs,excepts);
}
fs.writeFilesystem(stream);
//poifs.writeFilesystem(stream);
|