📄 worksheet.java
字号:
* @param column the column (0 <= column < Worksheet.MAX_COLUMNS).
*/
public void applyBorder(Border border, int row, int column) {
// delegate to more general method...
this.applyBorder(border, row, column, row, column);
}
/**
* Applies the border to the specified region.
* <P>
* This may involve restructuring the style regions.
*
* @param border the border.
* @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 applyBorder(Border border,
int startRow, int startColumn,
int endRow, int endColumn) {
// create a style modifier that changes the font and pass it on...
StyleModifier borderChanger = new BorderStyleModifier(border);
styles.modifyStyle(borderChanger, startRow, startColumn, endRow, endColumn);
}
/**
* Applies a thin outline border to a cell.
*
* @param row the row (0 <= row < Worksheet.MAX_ROWS).
* @param column the column (0 <= column < Worksheet.MAX_COLUMNS).
*/
public void applyOutline(int row, int column) {
this.applyOutline(Border.LINE, row, column);
}
/**
* Applies a thin outline border to a range of cells.
*
* @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 applyOutline(int startRow, int startColumn, int endRow, int endColumn) {
this.applyOutline(Border.LINE, startRow, startColumn, endRow, endColumn);
}
/**
* Applies a border to a cell.
*
* @param borderStyle the border style.
* @param row the row.
* @param column the column.
*/
public void applyOutline(int borderStyle, int row, int column) {
this.applyOutline(borderStyle, row, column, row, column);
}
/**
* Applies a border around a range of cells.
*
* @param lineStyle the style of line for the border.
* @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 applyOutline(int lineStyle,
int startRow, int startColumn, int endRow, int endColumn) {
if (startColumn == endColumn) { // must be either single cell or single column...
if (startRow == endRow) {
// single cell
Border border = new Border(lineStyle, lineStyle, lineStyle, lineStyle,
Border.NONE, Border.NONE);
applyBorder(border, startRow, startColumn, endRow, endColumn);
}
else { // single column
// top cell
Border top = new Border(lineStyle, Border.NONE, lineStyle, lineStyle,
Border.NONE, Border.NONE);
applyBorder(top, startRow, startColumn, startRow, endColumn);
// middle cells...
if ((endRow - startRow) > 1) {
Border middle = new Border(Border.NONE, Border.NONE, lineStyle, lineStyle,
Border.NONE, Border.NONE);
this.applyBorder(middle, startRow + 1, startColumn, endRow - 1, endColumn);
}
// bottom cell
Border bottom = new Border(Border.NONE, lineStyle, lineStyle, lineStyle,
Border.NONE, Border.NONE);
applyBorder(bottom, endRow, startColumn, endRow, endColumn);
}
}
else {
if (startRow == endRow) { // single row
// left cell...
Border left = new Border(lineStyle, lineStyle, lineStyle, Border.NONE,
Border.NONE, Border.NONE);
applyBorder(left, startRow, startColumn, endRow, startColumn);
// middle cells...
if ((endColumn - startColumn) > 1) {
Border middle = new Border(lineStyle, lineStyle, Border.NONE, Border.NONE,
Border.NONE, Border.NONE);
applyBorder(middle, startRow, startColumn + 1, endRow, endColumn - 1);
}
// right cell...
Border right = new Border(lineStyle, lineStyle, Border.NONE, lineStyle,
Border.NONE, Border.NONE);
applyBorder(right, endRow, endColumn, endRow, endColumn);
}
else {
// top left cell...
Border topleft = new Border(lineStyle, Border.NONE, lineStyle, Border.NONE,
Border.NONE, Border.NONE);
this.applyBorder(topleft, startRow, startColumn, startRow, startColumn);
// top right cell...
Border topright = new Border(lineStyle, Border.NONE, Border.NONE, lineStyle,
Border.NONE, Border.NONE);
applyBorder(topright, startRow, endColumn, startRow, endColumn);
// bottom right cell...
Border bottomright = new Border(Border.NONE, lineStyle, Border.NONE, lineStyle,
Border.NONE, Border.NONE);
applyBorder(bottomright, endRow, endColumn, endRow, endColumn);
// bottom left cell...
Border bottomleft = new Border(Border.NONE, lineStyle, lineStyle, Border.NONE,
Border.NONE, Border.NONE);
this.applyBorder(bottomleft, endRow, startColumn, endRow, startColumn);
if ((endColumn - startColumn) > 1) {
// top...
Border top = new Border(lineStyle, Border.NONE, Border.NONE, Border.NONE,
Border.NONE, Border.NONE);
applyBorder(top, startRow, startColumn + 1, startRow, endColumn - 1);
// bottom...
Border bottom = new Border(Border.NONE, lineStyle, Border.NONE, Border.NONE,
Border.NONE, Border.NONE);
applyBorder(bottom, endRow, startColumn + 1, endRow, endColumn - 1);
}
if ((endRow - startRow) > 1) {
// left...
Border left = new Border(Border.NONE, Border.NONE, lineStyle, Border.NONE,
Border.NONE, Border.NONE);
applyBorder(left, startRow + 1, startColumn, endRow - 1, startColumn);
// right...
Border right = new Border(Border.NONE, Border.NONE, Border.NONE, lineStyle,
Border.NONE, Border.NONE);
applyBorder(right, startRow + 1, endColumn, endRow - 1, endColumn);
}
}
}
}
/**
* Applies the foreground color to the specified cell.
* <P>
* This may involve restructuring the style regions.
*
* @param color the color.
* @param row the row (0 <= row < Worksheet.MAX_ROWS).
* @param column the column (0 <= column < Worksheet.MAX_COLUMNS).
*/
public void applyForegroundColor(Color color, int row, int column) {
// delegate to more general method...
this.applyForegroundColor(color, row, column, row, column);
}
/**
* Applies the foreground color to the specified region.
* <P>
* This may involve restructuring the style regions.
*
* @param color the color.
* @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 applyForegroundColor(Color color,
int startRow, int startColumn,
int endRow, int endColumn) {
// create a style modifier that changes the foreground color and pass it on...
StyleModifier foreground = new ColorStyleModifier(Color.FOREGROUND_COLOR, color);
styles.modifyStyle(foreground, startRow, startColumn, endRow, endColumn);
}
/**
* Applies the background color to the specified cell.
* <P>
* This may involve restructuring the style regions.
*
* @param color the color.
* @param row the row (0 <= row < Worksheet.MAX_ROWS).
* @param column the column (0 <= column < Worksheet.MAX_COLUMNS).
*/
public void applyBackgroundColor(Color color, int row, int column) {
// delegate to more general method...
applyBackgroundColor(color, row, column, row, column);
}
/**
* Applies the background color to the specified region.
* <P>
* This may involve restructuring the style regions.
*
* @param color the color.
* @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 applyBackgroundColor(Color color,
int startRow, int startColumn,
int endRow, int endColumn) {
// create a style modifier that changes the background color and pass it on...
StyleModifier background = new ColorStyleModifier(Color.BACKGROUND_COLOR, color);
styles.modifyStyle(background, startRow, startColumn, endRow, endColumn);
}
/**
* Applies the pattern color to the specified cell.
* <P>
* This may involve restructuring the style regions.
*
* @param color the color.
* @param column the column (0 <= column < Worksheet.MAX_COLUMNS).
* @param row the row (0 <= row < Worksheet.MAX_ROWS).
*/
public void applyPatternColor(Color color, int row, int column) {
// delegate to more general method...
this.applyPatternColor(color, row, column, row, column);
}
/**
* Applies the pattern color to the specified region.
* <P>
* This may involve restructuring the style regions.
*
* @param color the color.
* @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 applyPatternColor(Color color,
int startRow, int startColumn, int endRow, int endColumn) {
// create a style modifier that changes the pattern color and pass it on...
StyleModifier pattern = new ColorStyleModifier(Color.PATTERN_COLOR, color);
styles.modifyStyle(pattern, startRow, startColumn, endRow, endColumn);
}
//**********************************************************************************************
/**
* Returns a cell reference using letters for the column (e.g. D4) and the row number.
* <P>
* Note that internally we use zero based indices for the column and row numbers. But
* externally the user expects the first row to be number 1 (not 0).
*
* @param row the cell's row (0 <= row < Worksheet.MAX_ROWS).
* @param column the cell's column (0 <= column < Worksheet.MAX_COLUMNS).
*
* @return A cell reference.
*/
public static String cellReference(int row, int column) {
char[] letters = {'A', 'B', 'C', 'D', 'E', 'F', 'G',
'H', 'I', 'J', 'K', 'L', 'M', 'N',
'O', 'P', 'Q', 'R', 'S', 'T', 'U',
'V', 'W', 'X', 'Y', 'Z'};
String reference;
int columnMost = column / 26;
int columnLeast = column - (columnMost * 26);
if (columnMost > 0) {
char[] columnReference = new char[2];
columnReference[0] = letters[columnMost - 1];
columnReference[1] = letters[columnLeast];
reference = new String(columnReference);
}
else {
reference = new String(letters, columnLeast, 1);
}
return reference + (row + 1);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -