📄 hssfsheet.java
字号:
/** * determines whether the output is vertically centered on the page. * @param value true to vertically center, false otherwise. */ public void setVerticallyCenter(boolean value) { VCenterRecord record = (VCenterRecord) sheet.findFirstRecordBySid(VCenterRecord.sid); record.setVCenter(value); } /** * Determine whether printed output for this sheet will be vertically centered. */ public boolean getVerticallyCenter(boolean value) { VCenterRecord record = (VCenterRecord) sheet.findFirstRecordBySid(VCenterRecord.sid); return record.getVCenter(); } /** * determines whether the output is horizontally centered on the page. * @param value true to horizontally center, false otherwise. */ public void setHorizontallyCenter(boolean value) { HCenterRecord record = (HCenterRecord) sheet.findFirstRecordBySid(HCenterRecord.sid); record.setHCenter(value); } /** * Determine whether printed output for this sheet will be horizontally centered. */ public boolean getHorizontallyCenter() { HCenterRecord record = (HCenterRecord) sheet.findFirstRecordBySid(HCenterRecord.sid); return record.getHCenter(); } /** * removes a merged region of cells (hence letting them free) * @param index of the region to unmerge */ public void removeMergedRegion(int index) { sheet.removeMergedRegion(index); } /** * returns the number of merged regions * @return number of merged regions */ public int getNumMergedRegions() { return sheet.getNumMergedRegions(); } /** * gets the region at a particular index * @param index of the region to fetch * @return the merged region (simple eh?) */ public Region getMergedRegionAt(int index) { return new Region(sheet.getMergedRegionAt(index)); } /** * @return an iterator of the PHYSICAL rows. Meaning the 3rd element may not * be the third row if say for instance the second row is undefined. */ public Iterator rowIterator() { return rows.values().iterator(); } /** * used internally in the API to get the low level Sheet record represented by this * Object. * @return Sheet - low level representation of this HSSFSheet. */ protected Sheet getSheet() { return sheet; } /** * whether alternate expression evaluation is on * @param b alternative expression evaluation or not */ public void setAlternativeExpression(boolean b) { WSBoolRecord record = (WSBoolRecord) sheet.findFirstRecordBySid(WSBoolRecord.sid); record.setAlternateExpression(b); } /** * whether alternative formula entry is on * @param b alternative formulas or not */ public void setAlternativeFormula(boolean b) { WSBoolRecord record = (WSBoolRecord) sheet.findFirstRecordBySid(WSBoolRecord.sid); record.setAlternateFormula(b); } /** * show automatic page breaks or not * @param b whether to show auto page breaks */ public void setAutobreaks(boolean b) { WSBoolRecord record = (WSBoolRecord) sheet.findFirstRecordBySid(WSBoolRecord.sid); record.setAutobreaks(b); } /** * set whether sheet is a dialog sheet or not * @param b isDialog or not */ public void setDialog(boolean b) { WSBoolRecord record = (WSBoolRecord) sheet.findFirstRecordBySid(WSBoolRecord.sid); record.setDialog(b); } /** * set whether to display the guts or not * * @param b guts or no guts (or glory) */ public void setDisplayGuts(boolean b) { WSBoolRecord record = (WSBoolRecord) sheet.findFirstRecordBySid(WSBoolRecord.sid); record.setDisplayGuts(b); } /** * fit to page option is on * @param b fit or not */ public void setFitToPage(boolean b) { WSBoolRecord record = (WSBoolRecord) sheet.findFirstRecordBySid(WSBoolRecord.sid); record.setFitToPage(b); } /** * set if row summaries appear below detail in the outline * @param b below or not */ public void setRowSumsBelow(boolean b) { WSBoolRecord record = (WSBoolRecord) sheet.findFirstRecordBySid(WSBoolRecord.sid); record.setRowSumsBelow(b); } /** * set if col summaries appear right of the detail in the outline * @param b right or not */ public void setRowSumsRight(boolean b) { WSBoolRecord record = (WSBoolRecord) sheet.findFirstRecordBySid(WSBoolRecord.sid); record.setRowSumsRight(b); } /** * whether alternate expression evaluation is on * @return alternative expression evaluation or not */ public boolean getAlternateExpression() { return ((WSBoolRecord) sheet.findFirstRecordBySid(WSBoolRecord.sid)) .getAlternateExpression(); } /** * whether alternative formula entry is on * @return alternative formulas or not */ public boolean getAlternateFormula() { return ((WSBoolRecord) sheet.findFirstRecordBySid(WSBoolRecord.sid)) .getAlternateFormula(); } /** * show automatic page breaks or not * @return whether to show auto page breaks */ public boolean getAutobreaks() { return ((WSBoolRecord) sheet.findFirstRecordBySid(WSBoolRecord.sid)) .getAutobreaks(); } /** * get whether sheet is a dialog sheet or not * @return isDialog or not */ public boolean getDialog() { return ((WSBoolRecord) sheet.findFirstRecordBySid(WSBoolRecord.sid)) .getDialog(); } /** * get whether to display the guts or not * * @return guts or no guts (or glory) */ public boolean getDisplayGuts() { return ((WSBoolRecord) sheet.findFirstRecordBySid(WSBoolRecord.sid)) .getDisplayGuts(); } /** * fit to page option is on * @return fit or not */ public boolean getFitToPage() { return ((WSBoolRecord) sheet.findFirstRecordBySid(WSBoolRecord.sid)) .getFitToPage(); } /** * get if row summaries appear below detail in the outline * @return below or not */ public boolean getRowSumsBelow() { return ((WSBoolRecord) sheet.findFirstRecordBySid(WSBoolRecord.sid)) .getRowSumsBelow(); } /** * get if col summaries appear right of the detail in the outline * @return right or not */ public boolean getRowSumsRight() { return ((WSBoolRecord) sheet.findFirstRecordBySid(WSBoolRecord.sid)) .getRowSumsRight(); } /** * Returns whether gridlines are printed. * @return Gridlines are printed */ public boolean isPrintGridlines() { return getSheet().getPrintGridlines().getPrintGridlines(); } /** * Turns on or off the printing of gridlines. * @param newPrintGridlines boolean to turn on or off the printing of * gridlines */ public void setPrintGridlines( boolean newPrintGridlines ) { getSheet().getPrintGridlines().setPrintGridlines( newPrintGridlines ); } /** * Gets the print setup object. * @return The user model for the print setup object. */ public HSSFPrintSetup getPrintSetup() { return new HSSFPrintSetup( getSheet().getPrintSetup() ); } /** * Gets the user model for the document header. * @return The Document header. */ public HSSFHeader getHeader() { return new HSSFHeader( getSheet().getHeader() ); } /** * Gets the user model for the document footer. * @return The Document footer. */ public HSSFFooter getFooter() { return new HSSFFooter( getSheet().getFooter() ); } /** * Sets whether sheet is selected. * @param sel Whether to select the sheet or deselect the sheet. */ public void setSelected( boolean sel ) { getSheet().setSelected( sel ); } /** * Gets the size of the margin in inches. * @param margin which margin to get * @return the size of the margin */ public double getMargin( short margin ) { return getSheet().getMargin( margin ); } /** * Sets the size of the margin in inches. * @param margin which margin to get * @param size the size of the margin */ public void setMargin( short margin, double size ) { getSheet().setMargin( margin, size ); } /** * Answer whether protection is enabled or disabled * @return true => protection enabled; false => protection disabled */ public boolean getProtect() { return getSheet().getProtect().getProtect(); } /** * Sets the protection on enabled or disabled * @param protect true => protection enabled; false => protection disabled */ public void setProtect(boolean protect) { getSheet().getProtect().setProtect(protect); } /** * Sets the zoom magnication for the sheet. The zoom is expressed as a * fraction. For example to express a zoom of 75% use 3 for the numerator * and 4 for the denominator. * * @param numerator The numerator for the zoom magnification. * @param denominator The denominator for the zoom magnification. */ public void setZoom( int numerator, int denominator) { if (numerator < 1 || numerator > 65535) throw new IllegalArgumentException("Numerator must be greater than 1 and less than 65536"); if (denominator < 1 || denominator > 65535) throw new IllegalArgumentException("Denominator must be greater than 1 and less than 65536"); SCLRecord sclRecord = new SCLRecord(); sclRecord.setNumerator((short)numerator); sclRecord.setDenominator((short)denominator); getSheet().setSCLRecord(sclRecord); } /** * The top row in the visible view when the sheet is * first viewed after opening it in a viewer * @return short indicating the rownum (0 based) of the top row */ public short getTopRow() { return sheet.getTopRow(); } /** * The left col in the visible view when the sheet is * first viewed after opening it in a viewer * @return short indicating the rownum (0 based) of the top row */ public short getLeftCol() { return sheet.getLeftCol(); } /** * Sets desktop window pane display area, when the * file is first opened in a viewer. * @param toprow the top row to show in desktop window pane * @param leftcol the left column to show in desktop window pane */ public void showInPane(short toprow, short leftcol){ this.sheet.setTopRow((short)toprow); this.sheet.setLeftCol((short)leftcol); } /** * Shifts the merged regions left or right depending on mode * <p> * TODO: MODE , this is only row specific * @param startRow * @param endRow * @param n * @param isRow */ protected void shiftMerged(int startRow, int endRow, int n, boolean isRow) { List shiftedRegions = new ArrayList(); //move merged regions completely if they fall within the new region boundaries when they are shifted for (int i = 0; i < this.getNumMergedRegions(); i++) { Region merged = this.getMergedRegionAt(i); boolean inStart = (merged.getRowFrom() >= startRow || merged.getRowTo() >= startRow); boolean inEnd = (merged.getRowTo() <= endRow || merged.getRowFrom() <= endRow); //dont check if it's not within the shifted area if (! (inStart && inEnd)) continue; //only shift if the region outside the shifted rows is not merged too if (!merged.contains(startRow-1, (short)0) && !merged.contains(endRow+1, (short)0)){ merged.setRowFrom(merged.getRowFrom()+n); merged.setRowTo(merged.getRowTo()+n); //have to remove/add it back shiftedRegions.add(merged); this.removeMergedRegion(i); i = i -1; // we have to back up now since we removed one } } //readd so it doesn't get shifted again Iterator iterator = shiftedRegions.iterator(); while (iterator.hasNext()) { Region region = (Region)iterator.next(); this.addMergedRegion(region); } } /** * Shifts rows between startRow and endRow n number of rows. * If you use a negative number, it will shift rows up. * Code ensures that rows don't wrap around. * * Calls shiftRows(startRow, endRow, n, false, false); * * <p> * Additionally shifts merged regions that are completely defined in these * rows (ie. merged 2 cells on a row to be shifted). * @param startRow the row to start shifting * @param endRow the row to end shifting * @param n the number of rows to shift
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -