📄 hssfcellstyle.java
字号:
//Do not allow an incorrect rotation to be set throw new IllegalArgumentException("The rotation must be between -90 and 90 degrees"); format.setRotation(rotation); } /** * get the degree of rotation for the text in the cell * @return rotation degrees (between -90 and 90 degrees) */ public short getRotation() { short rotation = format.getRotation(); if (rotation > 90) //This is actually the 4th quadrant rotation = (short)(90-rotation); return rotation; } /** * set the number of spaces to indent the text in the cell * @param indent - number of spaces */ public void setIndention(short indent) { format.setIndent(indent); } /** * get the number of spaces to indent the text in the cell * @return indent - number of spaces */ public short getIndention() { return format.getIndent(); } /** * set the type of border to use for the left border of the cell * @param border type * @see #BORDER_NONE * @see #BORDER_THIN * @see #BORDER_MEDIUM * @see #BORDER_DASHED * @see #BORDER_DOTTED * @see #BORDER_THICK * @see #BORDER_DOUBLE * @see #BORDER_HAIR * @see #BORDER_MEDIUM_DASHED * @see #BORDER_DASH_DOT * @see #BORDER_MEDIUM_DASH_DOT * @see #BORDER_DASH_DOT_DOT * @see #BORDER_MEDIUM_DASH_DOT_DOT * @see #BORDER_SLANTED_DASH_DOT */ public void setBorderLeft(short border) { format.setIndentNotParentBorder(true); format.setBorderLeft(border); } /** * get the type of border to use for the left border of the cell * @return border type * @see #BORDER_NONE * @see #BORDER_THIN * @see #BORDER_MEDIUM * @see #BORDER_DASHED * @see #BORDER_DOTTED * @see #BORDER_THICK * @see #BORDER_DOUBLE * @see #BORDER_HAIR * @see #BORDER_MEDIUM_DASHED * @see #BORDER_DASH_DOT * @see #BORDER_MEDIUM_DASH_DOT * @see #BORDER_DASH_DOT_DOT * @see #BORDER_MEDIUM_DASH_DOT_DOT * @see #BORDER_SLANTED_DASH_DOT */ public short getBorderLeft() { return format.getBorderLeft(); } /** * set the type of border to use for the right border of the cell * @param border type * @see #BORDER_NONE * @see #BORDER_THIN * @see #BORDER_MEDIUM * @see #BORDER_DASHED * @see #BORDER_DOTTED * @see #BORDER_THICK * @see #BORDER_DOUBLE * @see #BORDER_HAIR * @see #BORDER_MEDIUM_DASHED * @see #BORDER_DASH_DOT * @see #BORDER_MEDIUM_DASH_DOT * @see #BORDER_DASH_DOT_DOT * @see #BORDER_MEDIUM_DASH_DOT_DOT * @see #BORDER_SLANTED_DASH_DOT */ public void setBorderRight(short border) { format.setIndentNotParentBorder(true); format.setBorderRight(border); } /** * get the type of border to use for the right border of the cell * @return border type * @see #BORDER_NONE * @see #BORDER_THIN * @see #BORDER_MEDIUM * @see #BORDER_DASHED * @see #BORDER_DOTTED * @see #BORDER_THICK * @see #BORDER_DOUBLE * @see #BORDER_HAIR * @see #BORDER_MEDIUM_DASHED * @see #BORDER_DASH_DOT * @see #BORDER_MEDIUM_DASH_DOT * @see #BORDER_DASH_DOT_DOT * @see #BORDER_MEDIUM_DASH_DOT_DOT * @see #BORDER_SLANTED_DASH_DOT */ public short getBorderRight() { return format.getBorderRight(); } /** * set the type of border to use for the top border of the cell * @param border type * @see #BORDER_NONE * @see #BORDER_THIN * @see #BORDER_MEDIUM * @see #BORDER_DASHED * @see #BORDER_DOTTED * @see #BORDER_THICK * @see #BORDER_DOUBLE * @see #BORDER_HAIR * @see #BORDER_MEDIUM_DASHED * @see #BORDER_DASH_DOT * @see #BORDER_MEDIUM_DASH_DOT * @see #BORDER_DASH_DOT_DOT * @see #BORDER_MEDIUM_DASH_DOT_DOT * @see #BORDER_SLANTED_DASH_DOT */ public void setBorderTop(short border) { format.setIndentNotParentBorder(true); format.setBorderTop(border); } /** * get the type of border to use for the top border of the cell * @return border type * @see #BORDER_NONE * @see #BORDER_THIN * @see #BORDER_MEDIUM * @see #BORDER_DASHED * @see #BORDER_DOTTED * @see #BORDER_THICK * @see #BORDER_DOUBLE * @see #BORDER_HAIR * @see #BORDER_MEDIUM_DASHED * @see #BORDER_DASH_DOT * @see #BORDER_MEDIUM_DASH_DOT * @see #BORDER_DASH_DOT_DOT * @see #BORDER_MEDIUM_DASH_DOT_DOT * @see #BORDER_SLANTED_DASH_DOT */ public short getBorderTop() { return format.getBorderTop(); } /** * set the type of border to use for the bottom border of the cell * @param border type * @see #BORDER_NONE * @see #BORDER_THIN * @see #BORDER_MEDIUM * @see #BORDER_DASHED * @see #BORDER_DOTTED * @see #BORDER_THICK * @see #BORDER_DOUBLE * @see #BORDER_HAIR * @see #BORDER_MEDIUM_DASHED * @see #BORDER_DASH_DOT * @see #BORDER_MEDIUM_DASH_DOT * @see #BORDER_DASH_DOT_DOT * @see #BORDER_MEDIUM_DASH_DOT_DOT * @see #BORDER_SLANTED_DASH_DOT */ public void setBorderBottom(short border) { format.setIndentNotParentBorder(true); format.setBorderBottom(border); } /** * get the type of border to use for the bottom border of the cell * @return border type * @see #BORDER_NONE * @see #BORDER_THIN * @see #BORDER_MEDIUM * @see #BORDER_DASHED * @see #BORDER_DOTTED * @see #BORDER_THICK * @see #BORDER_DOUBLE * @see #BORDER_HAIR * @see #BORDER_MEDIUM_DASHED * @see #BORDER_DASH_DOT * @see #BORDER_MEDIUM_DASH_DOT * @see #BORDER_DASH_DOT_DOT * @see #BORDER_MEDIUM_DASH_DOT_DOT * @see #BORDER_SLANTED_DASH_DOT */ public short getBorderBottom() { return format.getBorderBottom(); } /** * set the color to use for the left border * @param color */ public void setLeftBorderColor(short color) { format.setLeftBorderPaletteIdx(color); } /** * get the color to use for the left border * @return color */ public short getLeftBorderColor() { return format.getLeftBorderPaletteIdx(); } /** * set the color to use for the right border * @param color */ public void setRightBorderColor(short color) { format.setRightBorderPaletteIdx(color); } /** * get the color to use for the left border * @return color */ public short getRightBorderColor() { return format.getRightBorderPaletteIdx(); } /** * set the color to use for the top border * @param color */ public void setTopBorderColor(short color) { format.setTopBorderPaletteIdx(color); } /** * get the color to use for the top border * @return color */ public short getTopBorderColor() { return format.getTopBorderPaletteIdx(); } /** * set the color to use for the bottom border * @param color */ public void setBottomBorderColor(short color) { format.setBottomBorderPaletteIdx(color); } /** * get the color to use for the left border * @return color */ public short getBottomBorderColor() { return format.getBottomBorderPaletteIdx(); } /** * setting to one fills the cell with the foreground color... No idea about * other values * * @see #NO_FILL * @see #SOLID_FOREGROUND * @see #FINE_DOTS * @see #ALT_BARS * @see #SPARSE_DOTS * @see #THICK_HORZ_BANDS * @see #THICK_VERT_BANDS * @see #THICK_BACKWARD_DIAG * @see #THICK_FORWARD_DIAG * @see #BIG_SPOTS * @see #BRICKS * @see #THIN_HORZ_BANDS * @see #THIN_VERT_BANDS * @see #THIN_BACKWARD_DIAG * @see #THIN_FORWARD_DIAG * @see #SQUARES * @see #DIAMONDS * * @param fp fill pattern (set to 1 to fill w/foreground color) */ public void setFillPattern(short fp) { format.setAdtlFillPattern(fp); } /** * get the fill pattern (??) - set to 1 to fill with foreground color * @return fill pattern */ public short getFillPattern() { return format.getAdtlFillPattern(); } /** * Checks if the background and foreground fills are set correctly when one * or the other is set to the default color. * <p>Works like the logic table below:</p> * <p>BACKGROUND FOREGROUND</p> * <p>NONE AUTOMATIC</p> * <p>0x41 0x40</p> * <p>NONE RED/ANYTHING</p> * <p>0x40 0xSOMETHING</p> */ private void checkDefaultBackgroundFills() { if (format.getFillForeground() == org.apache.poi.hssf.util.HSSFColor.AUTOMATIC.index) { //JMH: Why +1, hell why not. I guess it made some sense to someone at the time. Doesnt //to me now.... But experience has shown that when the fore is set to AUTOMATIC then the //background needs to be incremented...... if (format.getFillBackground() != (org.apache.poi.hssf.util.HSSFColor.AUTOMATIC.index+1)) setFillBackgroundColor((short)(org.apache.poi.hssf.util.HSSFColor.AUTOMATIC.index+1)); } else if (format.getFillBackground() == org.apache.poi.hssf.util.HSSFColor.AUTOMATIC.index+1) //Now if the forground changes to a non-AUTOMATIC color the background resets itself!!! if (format.getFillForeground() != org.apache.poi.hssf.util.HSSFColor.AUTOMATIC.index) setFillBackgroundColor(org.apache.poi.hssf.util.HSSFColor.AUTOMATIC.index); } /** * set the background fill color. * <p> * For example: * <pre> * cs.setFillPattern(HSSFCellStyle.FINE_DOTS ); * cs.setFillBackgroundColor(new HSSFColor.RED().getIndex()); * </pre> * optionally a Foreground and background fill can be applied: * <i>Note: Ensure Foreground color is set prior to background</i> * <pre> * cs.setFillPattern(HSSFCellStyle.FINE_DOTS ); * cs.setFillForegroundColor(new HSSFColor.BLUE().getIndex()); * cs.setFillBackgroundColor(new HSSFColor.RED().getIndex()); * </pre> * or, for the special case of SOLID_FILL: * <pre> * cs.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND ); * cs.setFillForegroundColor(new HSSFColor.RED().getIndex()); * </pre> * It is necessary to set the fill style in order * for the color to be shown in the cell. * * @param bg color */ public void setFillBackgroundColor(short bg) { format.setFillBackground(bg); checkDefaultBackgroundFills(); } /** * get the background fill color * @return fill color */ public short getFillBackgroundColor() { short result = format.getFillBackground(); //JMH: Do this ridiculous conversion, and let HSSFCellStyle //internally migrate back and forth if (result == (HSSFColor.AUTOMATIC.index+1)) return HSSFColor.AUTOMATIC.index; else return result; } /** * set the foreground fill color * <i>Note: Ensure Foreground color is set prior to background color.</i> * @param bg color */ public void setFillForegroundColor(short bg) { format.setFillForeground(bg); checkDefaultBackgroundFills(); } /** * get the foreground fill color * @return fill color */ public short getFillForegroundColor() { return format.getFillForeground(); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -