| Method from org.apache.poi.hssf.usermodel.HSSFWorkbook Detail: |
public int addPicture(byte[] pictureData,
int format) {
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 );
}
Adds a picture to the workbook. |
public int addSSTString(String string) {
return workbook.addSSTString(new UnicodeString(string));
} Deprecated! Do - not call this method from your applications. Use the methods
available in the HSSFRow to add string HSSFCells
|
public HSSFSheet cloneSheet(int sheetNum) {
validateSheetIndex(sheetNum);
HSSFSheet srcSheet = (HSSFSheet) _sheets.get(sheetNum);
String srcName = workbook.getSheetName(sheetNum);
HSSFSheet clonedSheet = srcSheet.cloneSheet(this);
clonedSheet.setSelected(false);
clonedSheet.setActive(false);
_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;
}
create an HSSFSheet from an existing sheet in the HSSFWorkbook. |
public HSSFCellStyle createCellStyle() {
ExtendedFormatRecord xfr = workbook.createCellXF();
short index = (short) (getNumCellStyles() - 1);
HSSFCellStyle style = new HSSFCellStyle(index, xfr, this);
return style;
}
create a new Cell style and add it to the workbook's style table |
public HSSFDataFormat createDataFormat() {
if (formatter == null)
formatter = new HSSFDataFormat(workbook);
return formatter;
}
Returns the instance of HSSFDataFormat for this workbook. |
public HSSFFont createFont() {
FontRecord font = workbook.createNewFont();
short fontindex = (short) (getNumberOfFonts() - 1);
if (fontindex > 3)
{
fontindex++; // THERE IS NO FOUR!!
}
if(fontindex == Short.MAX_VALUE){
throw new IllegalArgumentException("Maximum number of fonts was exceeded");
}
HSSFFont retval = new HSSFFont(fontindex, font);
return retval;
}
create a new Font and add it to the workbook's font table |
public HSSFName createName() {
NameRecord nameRecord = workbook.createName();
HSSFName newName = new HSSFName(this, nameRecord);
names.add(newName);
return newName;
}
creates a new named range and add it to the model |
public HSSFSheet createSheet() {
HSSFSheet sheet = new HSSFSheet(this);
_sheets.add(sheet);
workbook.setSheetName(_sheets.size() - 1, "Sheet" + (_sheets.size() - 1));
boolean isOnlySheet = _sheets.size() == 1;
sheet.setSelected(isOnlySheet);
sheet.setActive(isOnlySheet);
return sheet;
}
create an HSSFSheet for this HSSFWorkbook, adds it to the sheets and returns
the high level representation. Use this to create new sheets. |
public HSSFSheet createSheet(String sheetname) {
if (workbook.doesContainsSheetName( sheetname, _sheets.size() ))
throw new IllegalArgumentException( "The workbook already contains a sheet of this name" );
HSSFSheet sheet = new HSSFSheet(this);
_sheets.add(sheet);
workbook.setSheetName(_sheets.size() - 1, sheetname);
boolean isOnlySheet = _sheets.size() == 1;
sheet.setSelected(isOnlySheet);
sheet.setActive(isOnlySheet);
return sheet;
}
create an HSSFSheet for this HSSFWorkbook, adds it to the sheets and
returns the high level representation. Use this to create new sheets. |
public void dumpDrawingGroupRecords(boolean fat) {
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();
}
Spits out a list of all the drawing records in the workbook. |
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;
}
Finds a font that matches the one with the supplied attributes |
public int getActiveSheetIndex() {
return workbook.getWindowOne().getActiveSheetIndex();
}
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). |
public List getAllEmbeddedObjects() {
List objects = new ArrayList();
for (int i = 0; i < getNumberOfSheets(); i++)
{
getAllEmbeddedObjects(getSheetAt(i).getSheet().getRecords(), objects);
}
return objects;
}
Gets all embedded OLE2 objects from the Workbook. |
public List getAllPictures() {
// The drawing group record always exists at the top level, so we won't need to do this recursively.
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;
}
Gets all pictures from the Workbook. |
public boolean getBackupFlag() {
BackupRecord backupRecord = workbook.getBackupRecord();
return (backupRecord.getBackup() == 0) ? false
: true;
}
determine whether the Excel GUI will backup the workbook when saving. |
public byte[] getBytes() {
if (log.check( POILogger.DEBUG )) {
log.log(DEBUG, "HSSFWorkbook.getBytes()");
}
HSSFSheet[] sheets = getSheets();
int nSheets = sheets.length;
// before getting the workbook size we must tell the sheets that
// serialization is about to occur.
for (int i = 0; i < nSheets; i++) {
sheets[i].getSheet().preSerialize();
}
int totalsize = workbook.getSize();
// pre-calculate all the sheet sizes and set BOF indexes
int[] estimatedSheetSizes = new int[nSheets];
for (int k = 0; k < nSheets; k++) {
workbook.setSheetBof(k, totalsize);
int sheetSize = sheets[k].getSheet().getSize();
estimatedSheetSizes[k] = sheetSize;
totalsize += sheetSize;
}
byte[] retval = new byte[totalsize];
int pos = workbook.serialize(0, retval);
for (int k = 0; k < nSheets; k++) {
int serializedSize = sheets[k].getSheet().serialize(pos, retval);
if (serializedSize != estimatedSheetSizes[k]) {
// Wrong offset values have been passed in the call to setSheetBof() above.
// For books with more than one sheet, this discrepancy would cause excel
// to report errors and loose data while reading the workbook
throw new IllegalStateException("Actual serialized sheet size (" + serializedSize
+ ") differs from pre-calculated size (" + estimatedSheetSizes[k]
+ ") for sheet (" + k + ")");
// TODO - add similar sanity check to ensure that Sheet.serializeIndexRecord() does not write mis-aligned offsets either
}
pos += serializedSize;
}
return retval;
}
Method getBytes - get the bytes of just the HSSF portions of the XLS file.
Use this to construct a POI POIFSFileSystem yourself. |
public HSSFCellStyle getCellStyleAt(short idx) {
ExtendedFormatRecord xfr = workbook.getExFormatAt(idx);
HSSFCellStyle style = new HSSFCellStyle(idx, xfr, this);
return style;
}
get the cell style object at the given index |
public HSSFPalette getCustomPalette() {
return new HSSFPalette(workbook.getCustomPalette());
}
|
public short getDisplayedTab() {
return (short) getFirstVisibleTab();
} Deprecated! - - Misleading name - use getFirstVisibleTab()
|
public short getExternalSheetIndex(int internalSheetIndex) {
return workbook.checkExternSheet(internalSheetIndex);
}
Returns the external sheet index of the sheet
with the given internal index, creating one
if needed.
Used by some of the more obscure formula and
named range things. |
public int getFirstVisibleTab() {
return workbook.getWindowOne().getFirstVisibleTab();
}
sets the first tab that is displayed in the list of tabs in excel. |
public HSSFFont getFontAt(short idx) {
FontRecord font = workbook.getFontRecordAt(idx);
HSSFFont retval = new HSSFFont(idx, font);
return retval;
}
get the font at the given index number |
public MissingCellPolicy getMissingCellPolicy() {
return missingCellPolicy;
}
Retrieves the current policy on what to do when
getting missing or blank cells from a row.
The default is to return blank and null cells.
MissingCellPolicy |
public HSSFName getNameAt(int index) {
HSSFName result = (HSSFName) names.get(index);
return result;
}
|
public int getNameIndex(String name) {
int retval = -1;
for (int k = 0; k < names.size(); k++)
{
String nameName = getNameName(k);
if (nameName.equalsIgnoreCase(name))
{
retval = k;
break;
}
}
return retval;
}
gets the named range index by his name
Note:Excel named ranges are case-insensitive and
this method performs a case-insensitive search. |
public String getNameName(int index) {
String result = getNameAt(index).getNameName();
return result;
}
gets the named range name |
public short getNumCellStyles() {
return (short) workbook.getNumExFormats();
}
get the number of styles the workbook contains |
public short getNumberOfFonts() {
return (short) workbook.getNumberOfFontRecords();
}
get the number of fonts in the font table |
public int getNumberOfNames() {
int result = names.size();
return result;
}
gets the total number of named ranges in the workboko |
public int getNumberOfSheets() {
return _sheets.size();
}
get the number of spreadsheets in the workbook (this will be three after serialization) |
public String getPrintArea(int sheetIndex) {
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(this);
}
Retrieves the reference for the printarea of the specified sheet, the sheet name is appended to the reference even if it was not specified. |
public String getSSTString(int index) {
return workbook.getSSTString(index).getString();
} Deprecated! Do - not call this method from your applications. Use the methods
available in the HSSFRow to get string HSSFCells
|
public short getSelectedTab() {
return (short) getActiveSheetIndex();
} Deprecated! - - Misleading name - use getActiveSheetIndex()
|
public HSSFSheet getSheet(String name) {
HSSFSheet retval = null;
for (int k = 0; k < _sheets.size(); k++)
{
String sheetname = workbook.getSheetName(k);
if (sheetname.equalsIgnoreCase(name))
{
retval = (HSSFSheet) _sheets.get(k);
}
}
return retval;
}
Get sheet with the given name (case insensitive match) |
public HSSFSheet getSheetAt(int index) {
return (HSSFSheet) _sheets.get(index);
}
Get the HSSFSheet object at the given index. |
public int getSheetIndex(String name) {
int retval = workbook.getSheetIndex(name);
return retval;
}
Returns the index of the sheet by his name |
public int getSheetIndex(HSSFSheet sheet) {
for(int i=0; i< _sheets.size(); i++) {
if(_sheets.get(i) == sheet) {
return i;
}
}
return -1;
}
Returns the index of the given sheet |
public String getSheetName(int sheetIx) {
validateSheetIndex(sheetIx);
return workbook.getSheetName(sheetIx);
}
|
public SheetReferences getSheetReferences() {
return workbook.getSheetReferences();
}
|
protected Workbook getWorkbook() {
return workbook;
}
|
public void insertChartRecord() {
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);
}
|
public boolean isSheetHidden(int sheetIx) {
validateSheetIndex(sheetIx);
return workbook.isSheetHidden(sheetIx);
}
check whether a sheet is hidden |
public boolean isWriteProtected() {
return this.workbook.isWriteProtected();
}
Is the workbook protected with a password (not encrypted)? |
public void removeName(int index) {
names.remove(index);
workbook.removeName(index);
}
remove the named range by his index |
public void removeName(String name) {
int index = getNameIndex(name);
removeName(index);
}
remove the named range by his name |
public void removePrintArea(int sheetIndex) {
getWorkbook().removeBuiltinRecord(NameRecord.BUILTIN_PRINT_AREA, sheetIndex+1);
}
Delete the printarea for the sheet specified |
public void removeSheetAt(int index) {
validateSheetIndex(index);
boolean wasActive = getSheetAt(index).isActive();
boolean wasSelected = getSheetAt(index).isSelected();
_sheets.remove(index);
workbook.removeSheet(index);
// set the remaining active/selected sheet
int nSheets = _sheets.size();
if (nSheets < 1) {
// nothing more to do if there are no sheets left
return;
}
// the index of the closest remaining sheet to the one just deleted
int newSheetIndex = index;
if (newSheetIndex >= nSheets) {
newSheetIndex = nSheets-1;
}
if (wasActive) {
setActiveSheet(newSheetIndex);
}
if (wasSelected) {
boolean someOtherSheetIsStillSelected = false;
for (int i =0; i < nSheets; i++) {
if (getSheetAt(i).isSelected()) {
someOtherSheetIsStillSelected = true;
break;
}
}
if (!someOtherSheetIsStillSelected) {
setSelectedTab(newSheetIndex);
}
}
}
Removes sheet at the given index.
Care must be taken if the removed sheet is the currently active or only selected sheet in
the workbook. There are a few situations when Excel must have a selection and/or active
sheet. (For example when printing - see Bug 40414).
This method makes sure that if the removed sheet was active, another sheet will become
active in its place. Furthermore, if the removed sheet was the only selected sheet, another
sheet will become selected. The newly active/selected sheet will have the same index, or
one less if the removed sheet was the last in the workbook. |
public String resolveNameXText(int refIndex,
int definedNameIndex) {
return workbook.resolveNameXText(refIndex, definedNameIndex);
}
TODO - make this less cryptic / move elsewhere |
public void setActiveSheet(int index) {
validateSheetIndex(index);
int nSheets = _sheets.size();
for (int i=0; i< nSheets; i++) {
getSheetAt(i).setActive(i == index);
}
workbook.getWindowOne().setActiveSheetIndex(index);
}
Convenience method to set the active sheet. The active sheet is is the sheet
which is currently displayed when the workbook is viewed in Excel.
'Selected' sheet(s) is a distinct concept. |
public void setBackupFlag(boolean backupValue) {
BackupRecord backupRecord = workbook.getBackupRecord();
backupRecord.setBackup(backupValue ? (short) 1
: (short) 0);
}
determine whether the Excel GUI will backup the workbook when saving. |
public void setDisplayedTab(short index) {
setFirstVisibleTab(index);
} Deprecated! - - Misleading name - use setFirstVisibleTab()
|
public void setFirstVisibleTab(int index) {
workbook.getWindowOne().setFirstVisibleTab(index);
}
sets the first tab that is displayed in the list of tabs
in excel. |
public void setMissingCellPolicy(MissingCellPolicy missingCellPolicy) {
this.missingCellPolicy = missingCellPolicy;
}
|
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.setAreaReference(reference);
}
|
public void setPrintArea(int sheetIndex,
int startColumn,
int endColumn,
int startRow,
int endRow) {
//using absolute references because they don't get copied and pasted anyway
CellReference cell = new CellReference(startRow, startColumn, true, true);
String reference = cell.formatAsString();
cell = new CellReference(endRow, endColumn, true, true);
reference = reference+":"+cell.formatAsString();
setPrintArea(sheetIndex, reference);
}
For the Convenience of Java Programmers maintaining pointers. |
public void setRepeatingRowsAndColumns(int sheetIndex,
int startColumn,
int endColumn,
int startRow,
int endRow) {
// 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)
{
ptgs.add(new MemFuncPtg(23)); // TODO - where did constant '23' come from?
}
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)
{
ptgs.add(UnionPtg.instance);
}
nameRecord.setNameDefinition(ptgs);
if (isNewRecord)
{
HSSFName newName = new HSSFName(this, nameRecord);
names.add(newName);
}
HSSFPrintSetup printSetup = sheet.getPrintSetup();
printSetup.setValidSettings(false);
sheet.setActive(true);
}
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);
|
public void setSelectedTab(int index) {
validateSheetIndex(index);
int nSheets = _sheets.size();
for (int i=0; i< nSheets; i++) {
getSheetAt(i).setSelected(i == index);
}
workbook.getWindowOne().setNumSelectedTabs((short)1);
}
Selects a single sheet. This may be different to
the 'active' sheet (which is the sheet with focus). |
public void setSelectedTab(short index) {
setSelectedTab((int)index);
} Deprecated! use - setSelectedTab(int)
|
public void setSelectedTabs(int[] indexes) {
for (int i = 0; i < indexes.length; i++) {
validateSheetIndex(indexes[i]);
}
int nSheets = _sheets.size();
for (int i=0; i< nSheets; i++) {
boolean bSelect = false;
for (int j = 0; j < indexes.length; j++) {
if (indexes[j] == i) {
bSelect = true;
break;
}
}
getSheetAt(i).setSelected(bSelect);
}
workbook.getWindowOne().setNumSelectedTabs((short)indexes.length);
}
|
public void setSheetHidden(int sheetIx,
boolean hidden) {
validateSheetIndex(sheetIx);
workbook.setSheetHidden(sheetIx, hidden);
}
|
public void setSheetName(int sheetIx,
String name) {
if (workbook.doesContainsSheetName( name, sheetIx )) {
throw new IllegalArgumentException( "The workbook already contains a sheet with this name" );
}
validateSheetIndex(sheetIx);
workbook.setSheetName(sheetIx, name);
}
set the sheet name.
Will throw IllegalArgumentException if the name is greater than 31 chars
or contains /\?*[] |
public void setSheetName(int sheetIx,
String name,
short encoding) {
if (workbook.doesContainsSheetName( name, sheetIx )) {
throw new IllegalArgumentException( "The workbook already contains a sheet with this name" );
}
validateSheetIndex(sheetIx);
switch ( encoding ) {
case ENCODING_COMPRESSED_UNICODE:
case ENCODING_UTF_16:
break;
default:
// TODO java.io.UnsupportedEncodingException
throw new RuntimeException( "Unsupported encoding" );
}
workbook.setSheetName( sheetIx, name, encoding );
} Deprecated! 3-Jan-2006 - POI now automatically detects unicode and sets the encoding
appropriately. Simply use setSheetName(int sheet, String encoding)
set the sheet name forcing the encoding. Forcing the encoding IS A BAD IDEA!!! |
public void setSheetOrder(String sheetname,
int pos) {
_sheets.add(pos,_sheets.remove(getSheetIndex(sheetname)));
workbook.setSheetOrder(sheetname, pos);
}
sets the order of appearance for a given sheet. |
public void unwriteProtectWorkbook() {
this.workbook.unwriteProtectWorkbook();
}
removes the write protect flag |
public void write(OutputStream stream) throws IOException {
byte[] bytes = getBytes();
POIFSFileSystem fs = new POIFSFileSystem();
// For tracking what we've written out, used if we're
// going to be preserving nodes
List excepts = new ArrayList(1);
// Write out the Workbook stream
fs.createDocument(new ByteArrayInputStream(bytes), "Workbook");
// Write out our HPFS properties, if we have them
writeProperties(fs, excepts);
if (preserveNodes) {
// Don't write out the old Workbook, we'll be doing our new one
excepts.add("Workbook");
// If the file had WORKBOOK instead of Workbook, we'll write it
// out correctly shortly, so don't include the old one
excepts.add("WORKBOOK");
// Copy over all the other nodes to our new poifs
copyNodes(this.filesystem,fs,excepts);
}
fs.writeFilesystem(stream);
//poifs.writeFilesystem(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. |
public void writeProtectWorkbook(String password,
String username) {
this.workbook.writeProtectWorkbook(password, username);
}
protect a workbook with a password (not encypted, just sets writeprotect
flags and the password. |