📄 writableworkbookimpl.java~
字号:
* Adds a cell to workbook wide range of cells which need adjustment
* following a row/column insert or remove
*
* @param f the cell to add to the list
*/
void addRCIRCell(CellValue cv)
{
logger.debug("addRCIRCell");
rcirCells.add(cv);
}
/**
* Called when a column is inserted on the specified sheet. Notifies all
* RCIR cells of this change
*
* @param s the sheet on which the column was inserted
* @param col the column number which was inserted
*/
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);
}
}
/**
* Called when a column is removed on the specified sheet. Notifies all
* RCIR cells of this change
*
* @param s the sheet on which the column was removed
* @param col the column number which was removed
*/
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);
}
}
/**
* Called when a row is inserted on the specified sheet. Notifies all
* RCIR cells of this change
*
* @param s the sheet on which the row was inserted
* @param row the row number which was inserted
*/
void rowInserted(WritableSheetImpl s, int row)
{
int externalSheetIndex = getExternalSheetIndex(s.getName());
for (Iterator i = rcirCells.iterator() ; i.hasNext() ;)
{
CellValue cv = (CellValue) i.next();
cv.rowInserted(s, externalSheetIndex, row);
}
}
/**
* Called when a row is removed on the specified sheet. Notifies all
* RCIR cells of this change
*
* @param s the sheet on which the row was removed
* @param row the row number which was removed
*/
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);
}
}
/**
* 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
*
* @param the name of the cell/range to search for
* @return the cell in the top left of the range if found, NULL
* otherwise
*/
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 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
*
* @param the name of the cell/range to search for
* @return the range of cells
*/
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;
}
/**
* Adds a drawing to this workbook
*
* @param d the drawing to add
*/
void addDrawing(DrawingGroupObject d)
{
if (drawingGroup == null)
{
drawingGroup = new DrawingGroup(Origin.WRITE);
}
drawingGroup.add(d);
}
/**
* Removes a drawing from this workbook
*
* @param d the drawing to remove
*/
void removeDrawing(Drawing d)
{
Assert.verify(drawingGroup != null);
drawingGroup.remove(d);
}
/**
* Accessor for the drawing group
*
* @return the drawing group
*/
DrawingGroup getDrawingGroup()
{
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
*/
DrawingGroup createDrawingGroup()
{
if (drawingGroup == null)
{
drawingGroup = new DrawingGroup(Origin.WRITE);
}
return drawingGroup;
}
/**
* Gets the named ranges
*
* @return the list of named cells within the 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;
}
/**
* Removes the specified named range from the workbook
*
* @param name the name to remove
*/
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++;
}
}
if (found)
{
names.remove(pos);
}
}
/**
* Accessor for the common styles
*
* @return the standard styles for this workbook
*/
Styles getStyles()
{
return styles;
}
/**
* Add new named area to this workbook with the given information.
*
* @param name name to be created.
* @param sheet sheet containing the name
* @param firstCol first column this name refers to.
* @param firstRow first row this name refers to.
* @param lastCol last column this name refers to.
* @param lastRow last row this name refers to.
*/
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.
*
* @param name name to be created.
* @param sheet sheet containing the name
* @param firstCol first column this name refers to.
* @param firstRow first row this name refers to.
* @param lastCol last column this name refers to.
* @param lastRow last row this name refers to.
* @param global TRUE if this is a global name, FALSE if this is tied to
* the sheet
*/
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.
*
* @param name name to be created.
* @param sheet sheet containing the name
* @param firstCol first column this name refers to.
* @param firstRow first row this name refers to.
* @param lastCol last column this name refers to.
* @param lastRow last row this name refers to.
* @param global TRUE if this is a global name, FALSE if this is tied to
* the sheet
*/
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);
}
/**
* Accessor for the workbook settings
*/
WorkbookSettings getSettings()
{
return settings;
}
/**
* 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
*
* @param loc the cell to retrieve
* @return the cell at the specified location
*/
public WritableCell getWritableCell(String loc)
{
WritableSheet s = getSheet(CellReferenceHelper.getSheet(loc));
return s.getWritableCell(loc);
}
/**
* Imports a sheet from a different workbook. Does a deep copy on all
* elements within that sheet
*
* @param name the name of the new sheet
* @param index the position for the new sheet within this workbook
* @param sheet the sheet (from another workbook) to merge into this one
* @return the new sheet
*/
public WritableSheet importSheet(String name, int index, Sheet sheet)
{
WritableSheet ws = createSheet(name, index);
((WritableSheetImpl) ws).importSheet(sheet);
return ws;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -