📄 writablesheetimpl.java
字号:
}
/**
* Gets the hyperlinks on this sheet
*
* @return an array of hyperlinks
*/
public Hyperlink[] getHyperlinks()
{
Hyperlink[] hl = new Hyperlink[hyperlinks.size()];
for (int i = 0; i < hyperlinks.size(); i++)
{
hl[i] = (Hyperlink) hyperlinks.get(i);
}
return hl;
}
/**
* Gets the cells which have been merged on this sheet
*
* @return an array of range objects
*/
public Range[] getMergedCells()
{
return mergedCells.getMergedCells();
}
/**
* Gets the writable hyperlinks on this sheet
*
* @return an array of hyperlinks
*/
public WritableHyperlink[] getWritableHyperlinks()
{
WritableHyperlink[] hl = new WritableHyperlink[hyperlinks.size()];
for (int i = 0; i < hyperlinks.size(); i++)
{
hl[i] = (WritableHyperlink) hyperlinks.get(i);
}
return hl;
}
/**
* Removes the specified hyperlink. Note that if you merely set the
* cell contents to be an Empty cell, then the cells containing the
* hyperlink will still be active. The contents of the cell which
* activate the hyperlink are removed.
* The hyperlink passed in must be a hyperlink retrieved using the
* getHyperlinks method
*
* @param h the hyperlink to remove.
* @param preserveLabel if TRUE preserves the label contents, if FALSE
* removes them
*/
public void removeHyperlink(WritableHyperlink h)
{
removeHyperlink(h, false);
}
/**
* Removes the specified hyperlink. Note that if you merely set the
* cell contents to be an Empty cell, then the cells containing the
* hyperlink will still be active.
* If the preserveLabel field is set, the cell contents of the
* hyperlink are preserved, although the hyperlink is deactivated. If
* this value is FALSE, the cell contents are removed
* The hyperlink passed in must be a hyperlink retrieved using the
* getHyperlinks method
*
* @param h the hyperlink to remove.
* @param preserveLabel if TRUE preserves the label contents, if FALSE
* removes them
*/
public void removeHyperlink(WritableHyperlink h, boolean preserveLabel)
{
// Remove the hyperlink
hyperlinks.remove(hyperlinks.indexOf(h));
if (!preserveLabel)
{
// Set the cell contents for the hyperlink - including any formatting
// information - to be empty
Assert.verify(rows.length > h.getRow() && rows[h.getRow()] != null);
rows[h.getRow()].removeCell(h.getColumn());
}
}
/**
* Adds the specified hyperlink
*
* @param the hyperlink
* @exception WriteException
* @exception RowsExceededException
*/
public void addHyperlink(WritableHyperlink h)
throws WriteException, RowsExceededException
{
// First set the label on the sheet
Cell c = getCell(h.getColumn(), h.getRow());
String contents = null;
if (h.isFile() || h.isUNC())
{
String cnts = ( (HyperlinkRecord) h).getContents();
if (cnts == null)
{
contents = h.getFile().getPath();
}
else
{
contents = cnts;
}
}
else if (h.isURL())
{
String cnts = ( (HyperlinkRecord) h).getContents();
if (cnts == null)
{
contents = h.getURL().toString();
}
else
{
contents=cnts;
}
}
else if (h.isLocation())
{
contents = ( (HyperlinkRecord) h).getContents();
}
// If the cell type is a label, then preserve the cell contents
// and most of the format (apart from the font)
// otherwise overwrite the cell content and the format with the contents
// and the standard hyperlink format
if (c.getType() == CellType.LABEL)
{
Label l = (Label) c;
l.setString(contents);
WritableCellFormat wcf = new WritableCellFormat(l.getCellFormat());
( (XFRecord) wcf).setFont(WritableWorkbook.HYPERLINK_FONT);
l.setCellFormat(wcf);
}
else
{
Label l = new Label(h.getColumn(), h.getRow(), contents,
WritableWorkbook.HYPERLINK_STYLE);
addCell(l);
}
// Set all other cells within range to be empty
for (int i = h.getRow(); i <= h.getLastRow(); i++)
{
for (int j = h.getColumn(); j <= h.getLastColumn(); j++)
{
if (i != h.getRow() && j != h.getColumn())
{
// Set the cell to be empty
if (rows.length < h.getLastColumn() && rows[i] != null)
{
rows[i].removeCell(j);
}
}
}
}
((HyperlinkRecord) h).initialize(this);
hyperlinks.add(h);
}
/**
* Merges the specified cells. Any clashes or intersections between
* merged cells are resolved when the spreadsheet is written out
*
* @param col1 the column number of the top left cell
* @param row1 the row number of the top left cell
* @param col2 the column number of the bottom right cell
* @param row2 the row number of the bottom right cell
* @return the Range object representing the merged cells
* @exception jxl.write..WriteException
* @exception jxl.write.biff.RowsExceededException
*/
public Range mergeCells(int col1, int row1, int col2, int row2)
throws WriteException, RowsExceededException
{
// First check that the cells make sense
if (col2 < col1 || row2 < row1)
{
logger.warn("Cannot merge cells - top left and bottom right "+
"incorrectly specified");
}
// Make sure the spreadsheet is up to size
if (col2 >= numColumns || row2 >= numRows)
{
addCell(new Blank(col2, row2));
}
SheetRangeImpl range = new SheetRangeImpl(this, col1, row1, col2, row2);
mergedCells.add(range);
return range;
}
/**
* Sets a row grouping
*
* @param row1 the first row of the group
* @param row2 the last row of the group
* @param collapsed should the group be collapsed?
* @exception WriteException
* @exception RowsExceededException
*/
public void setRowGroup(int row1, int row2,
boolean collapsed)
throws WriteException, RowsExceededException
{
if (row2 < row1)
{
logger.warn("Cannot merge cells - top and bottom rows incorrectly " +
"specified");
}
for (int i = row1; i <= row2; i++)
{
RowRecord row = getRowRecord(i);
row.incrementOutlineLevel();
row.setCollapsed(collapsed);
maxRowOutlineLevel = Math.max(maxRowOutlineLevel,
row.getOutlineLevel());
}
}
/**
* Unsets a row grouping
*
* @param row1 the first row to unset
* @param row2 the last row to unset
* @exception WriteException
* @exception RowsExceededException
*/
public void unsetRowGroup(int row1, int row2)
throws WriteException, RowsExceededException
{
if (row2 < row1)
{
logger.warn("Cannot merge cells - top and bottom rows incorrectly " +
"specified");
}
// Make sure the spreadsheet is up to size
if (row2 >= numRows)
{
logger.warn("" + row2 +
" is greater than the sheet bounds");
row2 = numRows - 1;
}
for (int i = row1; i <= row2; i++)
{
rows[i].decrementOutlineLevel();
}
// Recalculate the max outline level
maxRowOutlineLevel = 0;
for (int i = rows.length; i-- > 0; )
{
maxRowOutlineLevel = Math.max(maxRowOutlineLevel,
rows[i].getOutlineLevel());
}
}
/**
* Sets a column grouping
*
* @param col1 the first column of the group
* @param col2 the last column of the group
* @param collapsed should the group be collapsed?
* @exception WriteException
* @exception RowsExceededException
*/
public void setColumnGroup(int col1, int col2, boolean collapsed)
throws WriteException, RowsExceededException
{
if (col2 < col1)
{
logger.warn("Cannot merge cells - top and bottom rows incorrectly " +
"specified");
}
for (int i = col1; i <= col2; i++)
{
ColumnInfoRecord cir = getColumnInfo(i);
cir.incrementOutlineLevel();
cir.setCollapsed(collapsed);
maxColumnOutlineLevel = Math.max(maxColumnOutlineLevel,
cir.getOutlineLevel());
}
}
/**
* Unsets a column grouping
*
* @param col1 the first column to unset
* @param col2 the last column to unset
* @exception WriteException
* @exception RowsExceededException
*/
public void unsetColumnGroup(int col1, int col2)
throws WriteException, RowsExceededException
{
if (col2 < col1)
{
logger.warn("Cannot merge cells - top and bottom rows incorrectly " +
"specified");
}
for (int i = col1; i <= col2; i++)
{
ColumnInfoRecord cir = getColumnInfo(i);
cir.decrementOutlineLevel();
}
// Recalculate the max outline level
maxColumnOutlineLevel = 0;
for (Iterator it = columnFormats.iterator(); it.hasNext(); )
{
ColumnInfoRecord cir = (ColumnInfoRecord)it.next();
maxColumnOutlineLevel = Math.max(maxColumnOutlineLevel,
cir.getOutlineLevel());
}
}
/**
* Unmerges the specified cells. The Range passed in should be one that
* has been previously returned as a result of the getMergedCells method
*
* @param r the range of cells to unmerge
*/
public void unmergeCells(Range r)
{
mergedCells.unmergeCells(r);
}
/**
* Sets the header for this page
*
* @param l the print header to print on the left side
* @param c the print header to print in the centre
* @param r the print header to print on the right hand side
* @deprecated Use the sheet settings bean
*/
public void setHeader(String l, String c, String r)
{
HeaderFooter header = new HeaderFooter();
header.getLeft().append(l);
header.getCentre().append(c);
header.getRight().append(r);
settings.setHeader(header);
}
/**
* Sets the footer for this page
*
* @param l the print header to print on the left side
* @param c the print header to print in the centre
* @param r the print header to print on the right hand side
* @deprecated Use the sheet settings bean
*/
public void setFooter(String l, String c, String r)
{
HeaderFooter footer = new HeaderFooter();
footer.getLeft().append(l);
footer.getCentre().append(c);
footer.getRight().append(r);
settings.setFooter(footer);
}
/**
* Sets the page setup details
*
* @param p the page orientation
* @deprecated Use the SheetSettings bean
*/
public void setPageSetup(PageOrientation p)
{
settings.setOrientation(p);
}
/**
* Sets the page setup details
*
* @param p the page orientation
* @param hm the header margin, in inches
* @param fm the footer margin, in inches
* @deprecated Use the SheetSettings bean
*/
public void setPageSetup(PageOrientation p, double hm, double fm)
{
settings.setOrientation(p);
settings.setHeaderMargin(hm);
settings.setFooterMargin(fm);
}
/**
* Sets the page setup details
*
* @param p the page orientation
* @param ps the paper size
* @param hm the header margin, in inches
* @param fm the footer margin, in inches
* @deprecated Use the SheetSettings bean
*/
public void setPageSetup(PageOrientation p, PaperSize ps,
double hm, double fm)
{
settings.setPaperSize(ps);
settings.setOrientation(p);
settings.setHeaderMargin(hm);
settings.setFooterMargin(fm);
}
/**
* Gets the settings for this sheet
*
* @return the page settings bean
*/
public SheetSettings getSettings()
{
return settings;
}
/**
* Gets the workbook settings
*/
WorkbookSettings getWorkbookSettings()
{
return workbookSettings;
}
/**
* Forces a page break at the specified row
*
* @param row the row to break at
*/
public void addRowPageBreak(int row)
{
// First check that the row is not already present
Iterator i = rowBreaks.iterator();
boolean found = false;
while (i.hasNext() && !found)
{
if (( (Integer) i.next()).intValue() == row)
{
found = true;
}
}
if (!found)
{
rowBreaks.add(new Integer(row));
}
}
/**
* Forces a page break at the specified column
*
* @param col the column to break at
*/
public void addColumnPageBreak(int col)
{
// First check that the row is not already present
Iterator i = columnBreaks.iterator();
boolean found = false;
while (i.hasNext() && !found)
{
if (( (Integer) i.next()).intValue() == col)
{
found = true;
}
}
if (!found)
{
columnBreaks.add(new Integer(col));
}
}
/**
* Accessor for the charts. Used when copying
*
* @return the charts on this sheet
*/
Chart[] getCharts()
{
return sheetWriter.getCharts();
}
/**
* Accessor for the drawings. Used when copying
*
* @return the drawings on this sheet
*/
private DrawingGroupObject[] getDrawings()
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -