📄 worksheet.java
字号:
// pass to more general method...
this.setRowHeight(row, row, height);
}
/**
* Sets the height of a range of rows.
*
* @param startRow the row (0 <= startRow < Worksheets.MAX_ROWS).
* @param endRow the row (startRow <= endRow < Worksheets.MAX_ROWS).
* @param height the new height (height >= 0.0).
*/
public void setRowHeight(int startRow, int endRow, double height) {
// pass to the row attributes object...
this.rowAttributesManager.setRowHeight(startRow, endRow, height);
}
/**
* Sets the width of one column.
*
* @param column the column (0 to Worksheets.MAX_COLUMNS-1).
* @param width the new width.
*/
public void setColumnWidth(int column, double width) {
// pass to more general method...
this.setColumnWidth(column, column, width);
}
/**
* Sets the width of a range of columns.
*
* @param startColumn the start column (0 <= startColumn < Worksheets.MAX_COLUMNS).
* @param endColumn the end column (startColumn <= endColumn < Worksheets.MAX_COLUMNS).
* @param width the new width.
*/
public void setColumnWidth(int startColumn, int endColumn, double width) {
// pass to the column attributes object...
this.columnAttributesManager.setColumnWidth(startColumn, endColumn, width);
}
/**
* Sets the value at the specified cell.
*
* @param cell the new cell.
*/
public void addCell(Cell cell) {
// update the max cell...
this.maxRow = Math.max(cell.row, this.maxRow);
this.maxColumn = Math.max(cell.column, this.maxColumn);
// then add the cell to the cell manager...
cells.add(cell);
}
/**
* Adds a name to the worksheet. For now, there is no validation performed here, so be
* careful what you add.
*
* @param name the new name.
* @param value the value that the name resolves to.
*/
public void addName(String name, String value) {
this.getNamesManager().addName(name, value);
}
/**
* Adds the specified style region.
* <P>
* Note: this method will not adjust row sizes for the particular style that is being applied.
* Not sure what is the best way to achieve this...
*
* @param styleRegion the style region being added.
*/
public void addStyleRegion(StyleRegion styleRegion) {
styles.addStyleRegion(styleRegion);
}
/**
* Set the style for the specified range of the worksheet.
* <P>
* Note: this method will not adjust row sizes for the particular style that is being applied.
* Not sure what is the best way to achieve this...
*
* @param style the style to be applied.
* @param startRow the start row for the style region.
* @param startColumn the start column for the style region.
* @param endRow the end row for the style region.
* @param endColumn the end column for the style region.
*/
public void setStyle(Style style, int startRow, int startColumn, int endRow, int endColumn) {
// check parameters...handled by StyleRegion constructor.
StyleRegion styleRegion = new StyleRegion(style, startRow, startColumn, endRow, endColumn);
this.addStyleRegion(styleRegion);
}
/**
* Puts a date in a cell, overwriting any existing cell contents.
*
* @param row the row (0 <= row < Worksheet.MAX_ROWS).
* @param column the column (0 <= column < Worksheet.MAX_COLUMNS).
* @param date the date.
*/
public void putDate(int row, int column, SerialDate date) {
DateCell cell = new DateCell(date, row, column);
this.addCell(cell);
}
/**
* Puts a formula in a cell, overwriting any existing cell contents.
*
* @param formula the formula (not validated).
* @param column the column (0 <= column < Worksheet.MAX_COLUMNS).
* @param row the row (0 <= row < Worksheet.MAX_ROWS).
*/
public void putFormula(int row, int column, String formula) {
FormulaCell formulaCell = new FormulaCell(formula, row, column);
this.addCell(formulaCell);
}
/**
* Puts a label in a cell, overwriting any existing cell contents.
*
* @param label the label.
* @param column the column (0 <= column < Worksheet.MAX_COLUMNS).
* @param row the row (0 <= row < Worksheet.MAX_ROWS).
*/
public void putLabel(int row, int column, String label) {
LabelCell labelCell = new LabelCell(label, row, column);
this.addCell(labelCell);
}
/**
* Puts a value in a cell, overwriting any existing cell contents.
*
* @param value the value.
* @param column the column (0 <= column < Worksheet.MAX_COLUMNS).
* @param row the row (0 <= row < Worksheet.MAX_ROWS).
*/
public void putValue(int row, int column, double value) {
ValueCell valueCell = new ValueCell(value, row, column);
this.addCell(valueCell);
}
/**
* Puts a comment in a cell, overwriting any existing cell comments.
*
* @param row the row (0 <= row < Worksheet.MAX_ROWS).
* @param column the column (0 <= column < Worksheet.MAX_COLUMNS).
* @param comment the comment.
*/
public void putComment(int row, int column, String comment) {
Comment c = new Comment(row, column, comment);
int commentIndex = Collections.binarySearch(comments, c);
if (commentIndex > 0) {
comments.remove(commentIndex);
comments.add(commentIndex, c);
}
else {
comments.add(-commentIndex - 1, c);
this.maxRow = Math.max(row, this.maxRow);
this.maxColumn = Math.max(column, this.maxColumn);
}
}
/**
* Applies the font to the specified cell.
* <P>
* This may involve restructuring the style regions.
*
* @param font the font.
* @param row the row (0 <= row < Worksheet.MAX_ROWS).
* @param column the column (0 <= column < Worksheet.MAX_COLUMNS).
*/
public void applyFont(FontStyle font, int row, int column) {
// delegate to more general method...
this.applyFont(font, row, column, row, column);
}
/**
* Applies the font to the specified region.
* <P>
* This may involve restructuring the style regions.
*
* @param font the font.
* @param startRow the start row (0 <= startRow < Worksheet.MAX_ROWS).
* @param startColumn the start column (0 <= startColumn < Worksheet.MAX_COLUMNS).
* @param endRow the end row (0 <= endRow < Worksheet.MAX_ROWS).
* @param endColumn the end column (0 <= endColumn < Worksheet.MAX_COLUMNS).
*/
public void applyFont(FontStyle font,
int startRow, int startColumn,
int endRow, int endColumn) {
// create a style modifier that changes the font and pass it on...
StyleModifier fontChanger = new FontStyleModifier(font);
styles.modifyStyle(fontChanger, startRow, startColumn, endRow, endColumn);
}
/**
* Applies a horizontal alignment setting to a cell.
* <P>
* This may involve restructuring the style regions.
*
* @param align the new alignment.
* @param row the row (0 <= row < Worksheet.MAX_ROWS).
* @param column the column (0 <= column < Worksheet.MAX_COLUMNS).
*/
public void applyHorizontalAlignment(int align, int row, int column) {
// pass on to the more general method...
this.applyHorizontalAlignment(align, row, column, row, column);
}
/**
* Applies a horizontal alignment setting to a range of cells.
* <P>
* This may involve restructuring the style regions.
*
* @param align the new alignment.
* @param startRow the start row (0 <= startRow < Worksheet.MAX_ROWS).
* @param startColumn the start column (0 <= startColumn < Worksheet.MAX_COLUMNS).
* @param endRow the end row (0 <= endRow < Worksheet.MAX_ROWS).
* @param endColumn the end column (0 <= endColumn < Worksheet.MAX_COLUMNS).
*/
public void applyHorizontalAlignment(int align,
int startRow, int startColumn, int endRow, int endColumn) {
StyleModifier modifier = new GeneralStyleModifier(true, align, false, 0);
styles.modifyStyle(modifier, startRow, startColumn, endRow, endColumn);
}
/**
* Applies a vertical alignment setting to a cell.
* <P>
* This may involve restructuring the style regions.
*
* @param align the new alignment.
* @param row the row (0 <= row < Worksheet.MAX_ROWS).
* @param column the column (0 <= column < Worksheet.MAX_COLUMNS).
*/
public void applyVerticalAlignment(int align, int row, int column) {
// pass on to the more general method...
this.applyVerticalAlignment(align, row, column, row, column);
}
/**
* Applies a vertical alignment setting to a range of cells.
* <P>
* This may involve restructuring the style regions.
*
* @param align the new alignment.
* @param startColumn the start column (0 <= startColumn < Worksheet.MAX_COLUMNS).
* @param startRow the start row (0 <= startRow < Worksheet.MAX_ROWS).
* @param endColumn the end column (0 <= endColumn < Worksheet.MAX_COLUMNS).
* @param endRow the end row (0 <= endRow < Worksheet.MAX_ROWS).
*/
public void applyVerticalAlignment(int align,
int startRow, int startColumn, int endRow, int endColumn) {
StyleModifier modifier = new GeneralStyleModifier(false, 0, true, align);
styles.modifyStyle(modifier, startRow, startColumn, endRow, endColumn);
}
/**
* Applies the "wrap-text" setting to the specified cell.
* <P>
* This may involve restructuring the style regions.
*
* @param wrapText the new value of the wrap-text flag.
* @param row the row (0 <= row < Worksheet.MAX_ROWS).
* @param column the column (0 <= column < Worksheet.MAX_COLUMNS).
*/
public void applyWrapText(boolean wrapText, int row, int column) {
// pass on to the more general method...
this.applyWrapText(wrapText, row, column, row, column);
}
/**
* Applies the "wrap-text" setting to the specified region.
* <P>
* This may involve restructuring the style regions.
*
* @param wrapText the new value of the wrap-text flag.
* @param startColumn the start column (0 <= startColumn < Worksheet.MAX_COLUMNS).
* @param startRow the start row (0 <= startRow < Worksheet.MAX_ROWS).
* @param endColumn the end column (0 <= endColumn < Worksheet.MAX_COLUMNS).
* @param endRow the end row (0 <= endRow < Worksheet.MAX_ROWS).
*/
public void applyWrapText(boolean wrapText,
int startRow, int startColumn, int endRow, int endColumn) {
StyleModifier modifier = new GeneralStyleModifier(true, wrapText);
styles.modifyStyle(modifier, startRow, startColumn, endRow, endColumn);
}
/**
* Applies the foreground color to the specified cell.
* <P>
* This may involve restructuring the style regions.
*
* @param border the border.
* @param row the row (0 <= row < Worksheet.MAX_ROWS).
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -