| Method from org.apache.cocoon.poi.hssf.usermodel.HSSFWorkbook Detail: |
public HSSFCellStyle createCellStyle() {
ExtendedFormatRecord xfr = workbook.createCellXF();
short index = ( short ) (getNumCellStyles() - 1);
HSSFCellStyle style = new HSSFCellStyle(index, xfr);
return style;
}
create a new Cell style and add it to the workbook's style table |
public HSSFFont createFont() {
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;
}
create a new Font and add it to the workbook's font table |
public HSSFSheet createSheet() {
// 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));
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 (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, sheetname);
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 byte[] getBytes() {
int wbsize = workbook.serialize().length;
int sheetsize = 0;
int totalsize = wbsize;
// for (int k=sheets.size(); k< 3; k++) {
// createSheet();
// }
for (int k = 0; k < sheets.size(); k++)
{
workbook.setSheetBof(k, totalsize);
totalsize +=
(( HSSFSheet ) sheets.get(k)).getSheet().serialize().length;
}
if (totalsize < 4096)
{
totalsize = 4096;
}
byte[] retval = new byte[ totalsize ];
byte[] wb = workbook.serialize();
int pos = wbsize;
System.arraycopy(wb, 0, retval, 0, wb.length);
for (int k = 0; k < sheets.size(); k++)
{
byte[] sb = (( HSSFSheet ) sheets.get(k)).getSheet().serialize();
System.arraycopy(sb, 0, retval, pos, sb.length);
pos += sb.length;
}
for (int k = pos; k < totalsize; k++)
{
retval[ k ] = 0;
}
return retval;
}
Method getBytes - get the bytes of just the HSSF portions of the XLS file.
Use this to construct a POI Filesystem yourself. |
public HSSFCellStyle getCellStyleAt(short idx) {
ExtendedFormatRecord xfr = workbook.getExFormatAt(idx);
HSSFCellStyle style = new HSSFCellStyle(idx, xfr);
return style;
}
get the cell style object at the given index |
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 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 getNumberOfSheets() {
return sheets.size();
}
get the number of spreadsheets in the workbook (this will be three after serialization) |
public HSSFSheet getSheet(String 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;
}
Get sheet with the given name |
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 = -1;
for (int k = 0; k < sheets.size(); k++)
{
String sheet = workbook.getSheetName(k);
if (sheet.equals(name))
{
retval = k;
break;
}
}
return retval;
}
|
public String getSheetName(int sheet) {
if (sheet > (sheets.size() - 1))
{
throw new RuntimeException("Sheet out of bounds");
}
return workbook.getSheetName(sheet);
}
|
public void removeSheetAt(int index) {
sheets.remove(index);
workbook.removeSheet(index);
}
removes sheet at the given index |
public void setSheetName(int sheet,
String name) {
if (sheet > (sheets.size() - 1))
{
throw new RuntimeException("Sheet out of bounds");
}
workbook.setSheetName(sheet, name);
}
|
public void write(OutputStream stream) throws IOException {
byte[] bytes = getBytes();
Filesystem fs = new Filesystem();
fs.createDocument(new ByteArrayInputStream(bytes), "Workbook");
fs.writeFilesystem(stream);
}
Method write - write out this workbook to an Outputstream. Constructs
a new POI Filesystem, passes in the workbook binary representation and
writes it out. |