Method from jxl.write.biff.WritableWorkbookImpl Detail: |
void addDrawing(DrawingGroupObject d) {
if (drawingGroup == null)
{
drawingGroup = new DrawingGroup(Origin.WRITE);
}
drawingGroup.add(d);
}
Adds a drawing to this workbook |
public void addNameArea(String name,
WritableSheet sheet,
int firstCol,
int firstRow,
int lastCol,
int lastRow) {
addNameArea(name, sheet, firstCol, firstRow, lastCol, lastRow, true);
}
Add new named area to this workbook with the given information. |
void addNameArea(String name,
WritableSheet sheet,
int firstCol,
int firstRow,
int lastCol,
int lastRow,
boolean global) {
if (names == null)
{
names = new ArrayList();
}
int externalSheetIndex = getExternalSheetIndex(sheet.getName());
// Create a new name record.
NameRecord nr =
new NameRecord(name,
names.size(),
externalSheetIndex,
firstRow, lastRow,
firstCol, lastCol,
global);
// Add new name to name array.
names.add(nr);
// Add new name to name hash table.
nameRecords.put(name, nr);
}
Add new named area to this workbook with the given information. |
void addNameArea(BuiltInName name,
WritableSheet sheet,
int firstCol,
int firstRow,
int lastCol,
int lastRow,
boolean global) {
if (names == null)
{
names = new ArrayList();
}
int index = getInternalSheetIndex(sheet.getName());
int externalSheetIndex = getExternalSheetIndex(sheet.getName());
// Create a new name record.
NameRecord nr =
new NameRecord(name,
index,
externalSheetIndex,
firstRow, lastRow,
firstCol, lastCol,
global);
// Add new name to name array.
names.add(nr);
// Add new name to name hash table.
nameRecords.put(name, nr);
}
Add new named area to this workbook with the given information. |
void addNameArea(BuiltInName name,
WritableSheet sheet,
int firstCol,
int firstRow,
int lastCol,
int lastRow,
int firstCol2,
int firstRow2,
int lastCol2,
int lastRow2,
boolean global) {
if (names == null)
{
names = new ArrayList();
}
int index = getInternalSheetIndex(sheet.getName());
int externalSheetIndex = getExternalSheetIndex(sheet.getName());
// Create a new name record.
NameRecord nr =
new NameRecord(name,
index,
externalSheetIndex,
firstRow2, lastRow2,
firstCol2, lastCol2,
firstRow, lastRow,
firstCol, lastCol,
global);
// Add new name to name array.
names.add(nr);
// Add new name to name hash table.
nameRecords.put(name, nr);
}
Add new named area to this workbook with the given information. |
void addRCIRCell(CellValue cv) {
rcirCells.add(cv);
}
Adds a cell to workbook wide range of cells which need adjustment
following a row/column insert or remove |
public void close() throws IOException, JxlWriteException {
outputFile.close(closeStream);
}
Closes this workbook, and frees makes any memory allocated available
for garbage collection |
void columnInserted(WritableSheetImpl s,
int col) {
int externalSheetIndex = getExternalSheetIndex(s.getName());
for (Iterator i = rcirCells.iterator() ; i.hasNext() ;)
{
CellValue cv = (CellValue) i.next();
cv.columnInserted(s, externalSheetIndex, col);
}
// Adjust any named cells
if (names != null)
{
for (Iterator i = names.iterator(); i.hasNext() ;)
{
NameRecord nameRecord = (NameRecord) i.next();
nameRecord.columnInserted(externalSheetIndex, col);
}
}
}
Called when a column is inserted on the specified sheet. Notifies all
RCIR cells of this change |
void columnRemoved(WritableSheetImpl s,
int col) {
int externalSheetIndex = getExternalSheetIndex(s.getName());
for (Iterator i = rcirCells.iterator() ; i.hasNext() ;)
{
CellValue cv = (CellValue) i.next();
cv.columnRemoved(s, externalSheetIndex, col);
}
// Adjust any named cells
ArrayList removedNames = new ArrayList();
if (names != null)
{
for (Iterator i = names.iterator(); i.hasNext() ;)
{
NameRecord nameRecord = (NameRecord) i.next();
boolean removeName = nameRecord.columnRemoved(externalSheetIndex,
col);
if (removeName)
{
removedNames.add(nameRecord);
}
}
// Remove any names which have been deleted
for (Iterator i = removedNames.iterator(); i.hasNext() ;)
{
NameRecord nameRecord = (NameRecord) i.next();
boolean removed = names.remove(nameRecord);
Assert.verify(removed, "Could not remove name " +
nameRecord.getName());
}
}
}
Called when a column is removed on the specified sheet. Notifies all
RCIR cells of this change |
public void copySheet(int s,
String name,
int index) {
WritableSheet sheet = getSheet(s);
WritableSheetImpl ws = (WritableSheetImpl) createSheet(name, index);
ws.copy(sheet);
}
Copies the specified sheet and places it at the index
specified by the parameter |
public void copySheet(String s,
String name,
int index) {
WritableSheet sheet = getSheet(s);
WritableSheetImpl ws = (WritableSheetImpl) createSheet(name, index);
ws.copy(sheet);
}
Copies the specified sheet and places it at the index
specified by the parameter |
DrawingGroup createDrawingGroup() {
if (drawingGroup == null)
{
drawingGroup = new DrawingGroup(Origin.WRITE);
}
return drawingGroup;
}
Create a drawing group for this workbook - used when importing sheets
which contain drawings, but this workbook doesn't.
We can't subsume this into the getDrawingGroup() method because the
null-ness of the return value is used elsewhere to determine the
origin of the workbook |
public WritableSheet createSheet(String name,
int index) {
return createSheet(name, index, true);
}
Creates a new sheet within the workbook, at the specified position.
The new sheet is inserted at the specified position, or prepended/appended
to the list of sheets if the index specified is somehow inappropriate |
public Range[] findByName(String name) {
NameRecord nr = (NameRecord) nameRecords.get(name);
if (nr == null)
{
return null;
}
NameRecord.NameRange[] ranges = nr.getRanges();
Range[] cellRanges = new Range[ranges.length];
for (int i = 0; i < ranges.length ; i++)
{
cellRanges[i] = new RangeImpl
(this,
getExternalSheetIndex(ranges[i].getExternalSheet()),
ranges[i].getFirstColumn(),
ranges[i].getFirstRow(),
getLastExternalSheetIndex(ranges[i].getExternalSheet()),
ranges[i].getLastColumn(),
ranges[i].getLastRow());
}
return cellRanges;
}
Gets the named range from this workbook. The Range object returns
contains all the cells from the top left to the bottom right
of the range.
If the named range comprises an adjacent range,
the Range[] will contain one object; for non-adjacent
ranges, it is necessary to return an array of length greater than
one.
If the named range contains a single cell, the top left and
bottom right cell will be the same cell |
public WritableCell findCellByName(String name) {
NameRecord nr = (NameRecord) nameRecords.get(name);
if (nr == null)
{
return null;
}
NameRecord.NameRange[] ranges = nr.getRanges();
// Go and retrieve the first cell in the first range
int sheetIndex = getExternalSheetIndex(ranges[0].getExternalSheet());
WritableSheet s = getSheet(sheetIndex);
WritableCell cell = s.getWritableCell(ranges[0].getFirstColumn(),
ranges[0].getFirstRow());
return cell;
}
Gets the named cell from this workbook. If the name refers to a
range of cells, then the cell on the top left is returned. If
the name cannot be found, null is returned |
public RGB getColourRGB(Colour c) {
return formatRecords.getColourRGB(c);
}
Accessor for the RGB value for the specified colour |
DrawingGroup getDrawingGroup() {
return drawingGroup;
}
Accessor for the drawing group |
public int getExternalSheetIndex(int index) {
if (externSheet == null)
{
return index;
}
Assert.verify(externSheet != null);
int firstTab = externSheet.getFirstTabIndex(index);
return firstTab;
}
Gets the index of the external sheet for the name |
public int getExternalSheetIndex(String sheetName) {
if (externSheet == null)
{
externSheet = new ExternalSheetRecord();
supbooks = new ArrayList();
supbooks.add(new SupbookRecord(getNumberOfSheets(), settings));
}
// Iterate through the sheets records
boolean found = false;
Iterator i = sheets.iterator();
int sheetpos = 0;
WritableSheetImpl s = null;
while (i.hasNext() && !found)
{
s = (WritableSheetImpl) i.next();
if (s.getName().equals(sheetName))
{
found = true;
}
else
{
sheetpos++;
}
}
if (found)
{
// Check that the supbook record at position zero is internal and
// contains all the sheets
SupbookRecord supbook = (SupbookRecord) supbooks.get(0);
if (supbook.getType() != SupbookRecord.INTERNAL ||
supbook.getNumberOfSheets() != getNumberOfSheets())
{
logger.warn("Cannot find sheet " + sheetName + " in supbook record");
}
return externSheet.getIndex(0, sheetpos);
}
// Check for square brackets
int closeSquareBracketsIndex = sheetName.lastIndexOf(']');
int openSquareBracketsIndex = sheetName.lastIndexOf('[');
if (closeSquareBracketsIndex == -1 ||
openSquareBracketsIndex == -1)
{
logger.warn("Square brackets");
return -1;
}
String worksheetName = sheetName.substring(closeSquareBracketsIndex+1);
String workbookName = sheetName.substring(openSquareBracketsIndex+1,
closeSquareBracketsIndex);
String path = sheetName.substring(0, openSquareBracketsIndex);
String fileName = path + workbookName;
boolean supbookFound = false;
SupbookRecord externalSupbook = null;
int supbookIndex = -1;
for (int ind = 0; ind < supbooks.size() && !supbookFound ; ind++)
{
externalSupbook = (SupbookRecord) supbooks.get(ind);
if (externalSupbook.getType() == SupbookRecord.EXTERNAL &&
externalSupbook.getFileName().equals(fileName))
{
supbookFound = true;
supbookIndex = ind;
}
}
if (!supbookFound)
{
externalSupbook = new SupbookRecord(fileName, settings);
supbookIndex = supbooks.size();
supbooks.add(externalSupbook);
}
int sheetIndex = externalSupbook.getSheetIndex(worksheetName);
return externSheet.getIndex(supbookIndex, sheetIndex);
}
Gets the external sheet index for the sheet name |
public String getExternalSheetName(int index) {
int supbookIndex = externSheet.getSupbookIndex(index);
SupbookRecord sr = (SupbookRecord) supbooks.get(supbookIndex);
int firstTab = externSheet.getFirstTabIndex(index);
if (sr.getType() == SupbookRecord.INTERNAL)
{
// It's an internal reference - get the name from the sheets list
WritableSheet ws = getSheet(firstTab);
return ws.getName();
}
else if (sr.getType() == SupbookRecord.EXTERNAL)
{
String name = sr.getFileName() + sr.getSheetName(firstTab);
return name;
}
// An unknown supbook - return unkown
logger.warn("Unknown Supbook 1");
return "[UNKNOWN]";
}
Gets the name of the external sheet specified by the index |
public int getLastExternalSheetIndex(int index) {
if (externSheet == null)
{
return index;
}
Assert.verify(externSheet != null);
int lastTab = externSheet.getLastTabIndex(index);
return lastTab;
}
Gets the index of the external sheet for the name |
public int getLastExternalSheetIndex(String sheetName) {
if (externSheet == null)
{
externSheet = new ExternalSheetRecord();
supbooks = new ArrayList();
supbooks.add(new SupbookRecord(getNumberOfSheets(), settings));
}
// Iterate through the sheets records
boolean found = false;
Iterator i = sheets.iterator();
int sheetpos = 0;
WritableSheetImpl s = null;
while (i.hasNext() && !found)
{
s = (WritableSheetImpl) i.next();
if (s.getName().equals(sheetName))
{
found = true;
}
else
{
sheetpos++;
}
}
if (!found)
{
return -1;
}
// Check that the supbook record at position zero is internal and contains
// all the sheets
SupbookRecord supbook = (SupbookRecord) supbooks.get(0);
Assert.verify(supbook.getType() == SupbookRecord.INTERNAL &&
supbook.getNumberOfSheets() == getNumberOfSheets());
return externSheet.getIndex(0, sheetpos);
}
Gets the last external sheet index for the sheet name |
public String getLastExternalSheetName(int index) {
int supbookIndex = externSheet.getSupbookIndex(index);
SupbookRecord sr = (SupbookRecord) supbooks.get(supbookIndex);
int lastTab = externSheet.getLastTabIndex(index);
if (sr.getType() == SupbookRecord.INTERNAL)
{
// It's an internal reference - get the name from the sheets list
WritableSheet ws = getSheet(lastTab);
return ws.getName();
}
else if (sr.getType() == SupbookRecord.EXTERNAL)
{
Assert.verify(false);
}
// An unknown supbook - return unkown
logger.warn("Unknown Supbook 2");
return "[UNKNOWN]";
}
Gets the name of the last external sheet specified by the index |
public String getName(int index) {
Assert.verify(index >= 0 && index < names.size());
NameRecord n = (NameRecord) names.get(index);
return n.getName();
}
Gets the name at the specified index |
public int getNameIndex(String name) {
NameRecord nr = (NameRecord) nameRecords.get(name);
return nr != null ? nr.getIndex() : -1;
}
Gets the index of the name record for the name |
public int getNumberOfSheets() {
return sheets.size();
}
Returns the number of sheets in this workbook |
public String[] getRangeNames() {
if (names == null)
{
return new String[0];
}
String[] n = new String[names.size()];
for (int i = 0 ; i < names.size() ; i++)
{
NameRecord nr = (NameRecord) names.get(i);
n[i] = nr.getName();
}
return n;
}
|
public Sheet getReadSheet(int index) {
return getSheet(index);
}
Interface method from WorkbookMethods - gets the specified
sheet within this workbook |
WorkbookSettings getSettings() {
return settings;
}
Accessor for the workbook settings |
public WritableSheet getSheet(int index) {
return (WritableSheet) sheets.get(index);
}
Gets the specified sheet within this workbook |
public WritableSheet getSheet(String name) {
// Iterate through the boundsheet records
boolean found = false;
Iterator i = sheets.iterator();
WritableSheet s = null;
while (i.hasNext() && !found)
{
s = (WritableSheet) i.next();
if (s.getName().equals(name))
{
found = true;
}
}
return found ? s : null;
}
Gets the sheet with the specified name from within this workbook |
public String[] getSheetNames() {
String[] sheetNames = new String[getNumberOfSheets()];
for (int i = 0 ; i < sheetNames.length ; i++)
{
sheetNames[i] = getSheet(i).getName();
}
return sheetNames;
}
|
public WritableSheet[] getSheets() {
WritableSheet[] sheetArray = new WritableSheet[getNumberOfSheets()];
for (int i = 0 ; i < getNumberOfSheets() ; i++)
{
sheetArray[i] = getSheet(i);
}
return sheetArray;
}
Gets the sheets within this workbook. Use of this method for
large worksheets can cause performance problems. |
Styles getStyles() {
return styles;
}
Accessor for the jxl.common.styles |
public BOFRecord getWorkbookBof() {
return null;
}
Parsing of formulas is only supported for a subset of the available
biff version, so we need to test to see if this version is acceptable |
public WritableCell getWritableCell(String loc) {
WritableSheet s = getSheet(CellReferenceHelper.getSheet(loc));
return s.getWritableCell(loc);
}
Returns the cell for the specified location eg. "Sheet1!A4".
This is identical to using the CellReferenceHelper with its
associated performance overheads, consequently it should
be use sparingly |
public WritableSheet importSheet(String name,
int index,
Sheet sheet) {
WritableSheet ws = createSheet(name, index);
((WritableSheetImpl) ws).importSheet(sheet);
return ws;
}
Imports a sheet from a different workbook. Does a deep copy on all
elements within that sheet |
public WritableSheet moveSheet(int fromIndex,
int toIndex) {
// Handle dodgy index
fromIndex = Math.max(fromIndex, 0);
fromIndex = Math.min(fromIndex, sheets.size() - 1);
toIndex = Math.max(toIndex, 0);
toIndex = Math.min(toIndex, sheets.size() - 1);
WritableSheet sheet= (WritableSheet)sheets.remove(fromIndex);
sheets.add(toIndex, sheet);
return sheet;
}
Moves the specified sheet within this workbook to another index
position. |
void removeDrawing(Drawing d) {
Assert.verify(drawingGroup != null);
drawingGroup.remove(d);
}
Removes a drawing from this workbook |
public void removeRangeName(String name) {
int pos = 0;
boolean found = false;
for (Iterator i = names.iterator(); i.hasNext() && !found ;)
{
NameRecord nr = (NameRecord) i.next();
if (nr.getName().equals(name))
{
found = true;
}
else
{
pos++;
}
}
// Remove the name from the list of names and the associated hashmap
// of names (used to retrieve the name index). If the name cannot
// be found, a warning is displayed
if (found)
{
names.remove(pos);
if (nameRecords.remove(name) == null)
{
logger.warn("Could not remove " + name + " from index lookups");
}
}
}
Removes the specified named range from the workbook |
public void removeSheet(int index) {
int pos = index;
if (index < = 0)
{
pos = 0;
sheets.remove(0);
}
else if (index >= sheets.size())
{
pos = sheets.size() - 1;
sheets.remove(sheets.size() - 1);
}
else
{
sheets.remove(index);
}
if (externSheet != null)
{
externSheet.sheetRemoved(pos);
}
if (supbooks != null && supbooks.size() > 0)
{
SupbookRecord supbook = (SupbookRecord) supbooks.get(0);
if (supbook.getType() == SupbookRecord.INTERNAL)
{
supbook.adjustInternal(sheets.size());
}
}
if (names != null && names.size() > 0)
{
for (int i=0; i< names.size();i++)
{
NameRecord n = (NameRecord) names.get(i);
int oldRef = n.getSheetRef();
if(oldRef == (pos+1))
{
n.setSheetRef(0); // make a global name reference
}
else if (oldRef > (pos+1))
{
if(oldRef < 1)
{
oldRef = 1;
}
n.setSheetRef(oldRef-1); // move one sheet
}
}
}
}
Removes a sheet from this workbook, the other sheets indices being
altered accordingly. If the sheet referenced by the index
does not exist, then no action is taken. |
void rowInserted(WritableSheetImpl s,
int row) {
int externalSheetIndex = getExternalSheetIndex(s.getName());
// Adjust the row infos
for (Iterator i = rcirCells.iterator() ; i.hasNext() ;)
{
CellValue cv = (CellValue) i.next();
cv.rowInserted(s, externalSheetIndex, row);
}
// Adjust any named cells
if (names != null)
{
for (Iterator i = names.iterator(); i.hasNext() ;)
{
NameRecord nameRecord = (NameRecord) i.next();
nameRecord.rowInserted(externalSheetIndex, row);
}
}
}
Called when a row is inserted on the specified sheet. Notifies all
RCIR cells of this change |
void rowRemoved(WritableSheetImpl s,
int row) {
int externalSheetIndex = getExternalSheetIndex(s.getName());
for (Iterator i = rcirCells.iterator() ; i.hasNext() ;)
{
CellValue cv = (CellValue) i.next();
cv.rowRemoved(s, externalSheetIndex, row);
}
// Adjust any named cells
ArrayList removedNames = new ArrayList();
if (names != null)
{
for (Iterator i = names.iterator(); i.hasNext() ;)
{
NameRecord nameRecord = (NameRecord) i.next();
boolean removeName = nameRecord.rowRemoved(externalSheetIndex, row);
if (removeName)
{
removedNames.add(nameRecord);
}
}
// Remove any names which have been deleted
for (Iterator i = removedNames.iterator(); i.hasNext() ;)
{
NameRecord nameRecord = (NameRecord) i.next();
boolean removed = names.remove(nameRecord);
Assert.verify(removed, "Could not remove name " +
nameRecord.getName());
}
}
}
Called when a row is removed on the specified sheet. Notifies all
RCIR cells of this change |
public void setColourRGB(Colour c,
int r,
int g,
int b) {
formatRecords.setColourRGB(c,r,g,b);
}
Sets the RGB value for the specified colour for this workbook |
public void setOutputFile(File fileName) throws IOException {
FileOutputStream fos = new FileOutputStream(fileName);
outputFile.setOutputFile(fos);
}
Sets a new output file. This allows the smae workbook to be
written to various different output files without having to
read in any templates again |
public void setProtected(boolean prot) {
wbProtected = prot;
}
Indicates whether or not this workbook is protected |
public void write() throws IOException {
// Perform some preliminary sheet check before we start writing out
// the workbook
WritableSheetImpl wsi = null;
for (int i = 0; i < getNumberOfSheets(); i++)
{
wsi = (WritableSheetImpl) getSheet(i);
// Check the merged records. This has to be done before the
// globals are written out because some more XF formats might be created
wsi.checkMergedBorders();
// Check to see if there are any predefined names
Range range = wsi.getSettings().getPrintArea();
if (range != null)
{
addNameArea(BuiltInName.PRINT_AREA,
wsi,
range.getTopLeft().getColumn(),
range.getTopLeft().getRow(),
range.getBottomRight().getColumn(),
range.getBottomRight().getRow(),
false);
}
// Check to see if print titles by row were set
Range rangeR = wsi.getSettings().getPrintTitlesRow();
Range rangeC = wsi.getSettings().getPrintTitlesCol();
if (rangeR != null && rangeC != null)
{
addNameArea(BuiltInName.PRINT_TITLES,
wsi,
rangeR.getTopLeft().getColumn(),
rangeR.getTopLeft().getRow(),
rangeR.getBottomRight().getColumn(),
rangeR.getBottomRight().getRow(),
rangeC.getTopLeft().getColumn(),
rangeC.getTopLeft().getRow(),
rangeC.getBottomRight().getColumn(),
rangeC.getBottomRight().getRow(),
false);
}
// Check to see if print titles by row were set
else if (rangeR != null)
{
addNameArea(BuiltInName.PRINT_TITLES,
wsi,
rangeR.getTopLeft().getColumn(),
rangeR.getTopLeft().getRow(),
rangeR.getBottomRight().getColumn(),
rangeR.getBottomRight().getRow(),
false);
}
// Check to see if print titles by column were set
else if (rangeC != null)
{
addNameArea(BuiltInName.PRINT_TITLES,
wsi,
rangeC.getTopLeft().getColumn(),
rangeC.getTopLeft().getRow(),
rangeC.getBottomRight().getColumn(),
rangeC.getBottomRight().getRow(),
false);
}
}
// Rationalize all the XF and number formats
if (!settings.getRationalizationDisabled())
{
rationalize();
}
// Write the workbook globals
BOFRecord bof = new BOFRecord(BOFRecord.workbookGlobals);
outputFile.write(bof);
// Must immediatly follow the BOF record
if (settings.getTemplate())
{
// Only write record if we are a template
TemplateRecord trec= new TemplateRecord();
outputFile.write(trec);
}
InterfaceHeaderRecord ihr = new InterfaceHeaderRecord();
outputFile.write(ihr);
MMSRecord mms = new MMSRecord(0,0);
outputFile.write(mms);
InterfaceEndRecord ier = new InterfaceEndRecord();
outputFile.write(ier);
WriteAccessRecord wr = new WriteAccessRecord(settings.getWriteAccess());
outputFile.write(wr);
CodepageRecord cp = new CodepageRecord();
outputFile.write(cp);
DSFRecord dsf = new DSFRecord();
outputFile.write(dsf);
if (settings.getExcel9File())
{
// Only write record if we are a template
// We are not excel 2000, should we still set the flag
Excel9FileRecord e9rec= new Excel9FileRecord();
outputFile.write(e9rec);
}
TabIdRecord tabid = new TabIdRecord(getNumberOfSheets());
outputFile.write(tabid);
if (containsMacros)
{
ObjProjRecord objproj = new ObjProjRecord();
outputFile.write(objproj);
}
if (buttonPropertySet != null)
{
outputFile.write(buttonPropertySet);
}
FunctionGroupCountRecord fgcr = new FunctionGroupCountRecord();
outputFile.write(fgcr);
// do not support password protected workbooks
WindowProtectRecord wpr = new WindowProtectRecord
(settings.getWindowProtected());
outputFile.write(wpr);
ProtectRecord pr = new ProtectRecord(wbProtected);
outputFile.write(pr);
PasswordRecord pw = new PasswordRecord(null);
outputFile.write(pw);
Prot4RevRecord p4r = new Prot4RevRecord(false);
outputFile.write(p4r);
Prot4RevPassRecord p4rp = new Prot4RevPassRecord();
outputFile.write(p4rp);
// If no sheet is identified as being selected, then select
// the first one
boolean sheetSelected = false;
WritableSheetImpl wsheet = null;
int selectedSheetIndex = 0;
for (int i = 0 ; i < getNumberOfSheets() && !sheetSelected ; i++)
{
wsheet = (WritableSheetImpl) getSheet(i);
if (wsheet.getSettings().isSelected())
{
sheetSelected = true;
selectedSheetIndex = i;
}
}
if (!sheetSelected)
{
wsheet = (WritableSheetImpl) getSheet(0);
wsheet.getSettings().setSelected(true);
selectedSheetIndex = 0;
}
Window1Record w1r = new Window1Record(selectedSheetIndex);
outputFile.write(w1r);
BackupRecord bkr = new BackupRecord(false);
outputFile.write(bkr);
HideobjRecord ho = new HideobjRecord(settings.getHideobj());
outputFile.write(ho);
NineteenFourRecord nf = new NineteenFourRecord(false);
outputFile.write(nf);
PrecisionRecord pc = new PrecisionRecord(false);
outputFile.write(pc);
RefreshAllRecord rar = new RefreshAllRecord(settings.getRefreshAll());
outputFile.write(rar);
BookboolRecord bb = new BookboolRecord(true);
outputFile.write(bb);
// Write out all the fonts used
fonts.write(outputFile);
// Write out the cell formats used within this workbook
formatRecords.write(outputFile);
// Write out the palette, if it exists
if (formatRecords.getPalette() != null)
{
outputFile.write(formatRecords.getPalette());
}
// Write out the uses elfs record
UsesElfsRecord uer = new UsesElfsRecord();
outputFile.write(uer);
// Write out the boundsheet records. Keep a handle to each one's
// position so we can write in the stream offset later
int[] boundsheetPos = new int[getNumberOfSheets()];
Sheet sheet = null;
for (int i = 0; i < getNumberOfSheets(); i++)
{
boundsheetPos[i] = outputFile.getPos();
sheet = getSheet(i);
BoundsheetRecord br = new BoundsheetRecord(sheet.getName());
if (sheet.getSettings().isHidden())
{
br.setHidden();
}
if ( ( (WritableSheetImpl) sheets.get(i)).isChartOnly())
{
br.setChartOnly();
}
outputFile.write(br);
}
if (countryRecord == null)
{
CountryCode lang =
CountryCode.getCountryCode(settings.getExcelDisplayLanguage());
if (lang == CountryCode.UNKNOWN)
{
logger.warn("Unknown country code " +
settings.getExcelDisplayLanguage() +
" using " + CountryCode.USA.getCode());
lang = CountryCode.USA;
}
CountryCode region =
CountryCode.getCountryCode(settings.getExcelRegionalSettings());
countryRecord = new CountryRecord(lang, region);
if (region == CountryCode.UNKNOWN)
{
logger.warn("Unknown country code " +
settings.getExcelDisplayLanguage() +
" using " + CountryCode.UK.getCode());
region = CountryCode.UK;
}
}
outputFile.write(countryRecord);
// Write out the names of any add in functions
if (addInFunctionNames != null && addInFunctionNames.length > 0)
{
// Write out the supbook record
// SupbookRecord supbook = new SupbookRecord();
// outputFile.write(supbook);
for (int i = 0 ; i < addInFunctionNames.length; i++)
{
ExternalNameRecord enr = new ExternalNameRecord(addInFunctionNames[i]);
outputFile.write(enr);
}
}
if (xctRecords != null)
{
for (int i = 0 ; i < xctRecords.length; i++)
{
outputFile.write(xctRecords[i]);
}
}
// Write out the external sheet record, if it exists
if (externSheet != null)
{
//Write out all the supbook records
for (int i = 0; i < supbooks.size() ; i++)
{
SupbookRecord supbook = (SupbookRecord) supbooks.get(i);
outputFile.write(supbook);
}
outputFile.write(externSheet);
}
// Write out the names, if any exists
if (names != null)
{
for (int i = 0 ; i < names.size() ; i++)
{
NameRecord n = (NameRecord) names.get(i);
outputFile.write(n);
}
}
// Write out the mso drawing group, if it exists
if (drawingGroup != null)
{
drawingGroup.write(outputFile);
}
sharedStrings.write(outputFile);
EOFRecord eof = new EOFRecord();
outputFile.write(eof);
// Write out the sheets
for (int i = 0; i < getNumberOfSheets(); i++)
{
// first go back and modify the offset we wrote out for the
// boundsheet record
outputFile.setData
(IntegerHelper.getFourBytes(outputFile.getPos()),
boundsheetPos[i] + 4);
wsheet = (WritableSheetImpl) getSheet(i);
wsheet.write();
}
}
Writes out this sheet to the output file. First it writes out
the standard workbook information required by excel, before calling
the write method on each sheet individually |