📄 hssfsheet.java
字号:
/** * 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); } /** * 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 */ public void shiftRows( int startRow, int endRow, int n ) { shiftRows(startRow, endRow, n, false, false); } /** * 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 * * <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 * @param copyRowHeight whether to copy the row height during the shift * @param resetOriginalRowHeight whether to set the original row's height to the default */ public void shiftRows( int startRow, int endRow, int n, boolean copyRowHeight, boolean resetOriginalRowHeight) { int s, e, inc; if ( n < 0 ) { s = startRow; e = endRow; inc = 1; } else { s = endRow; e = startRow; inc = -1; } shiftMerged(startRow, endRow, n, true); for ( int rowNum = s; rowNum >= startRow && rowNum <= endRow && rowNum >= 0 && rowNum < 65536; rowNum += inc ) { HSSFRow row = getRow( rowNum ); HSSFRow row2Replace = getRow( rowNum + n ); if ( row2Replace == null ) row2Replace = createRow( rowNum + n ); HSSFCell cell; // Removes the cells before over writting them. for ( short col = row2Replace.getFirstCellNum(); col <= row2Replace.getLastCellNum(); col++ ) { cell = row2Replace.getCell( col ); if ( cell != null ) row2Replace.removeCell( cell ); } if (row == null) continue; // Nothing to do for this row else { if (copyRowHeight) { row2Replace.setHeight(row.getHeight()); } if (resetOriginalRowHeight) { row.setHeight((short)0xff); } } for ( short col = row.getFirstCellNum(); col <= row.getLastCellNum(); col++ ) { cell = row.getCell( col ); if ( cell != null ) { row.removeCell( cell ); CellValueRecordInterface cellRecord = cell.getCellValueRecord(); cellRecord.setRow( rowNum + n ); row2Replace.createCellFromRecord( cellRecord ); sheet.addValueRecord( rowNum + n, cellRecord ); } } } if ( endRow == lastrow || endRow + n > lastrow ) lastrow = Math.min( endRow + n, 65535 ); if ( startRow == firstrow || startRow + n < firstrow ) firstrow = Math.max( startRow + n, 0 ); } protected void insertChartRecords( List records ) { int window2Loc = sheet.findFirstRecordLocBySid( WindowTwoRecord.sid ); sheet.getRecords().addAll( window2Loc, records ); } /** * Creates a split (freezepane). * @param colSplit Horizonatal position of split. * @param rowSplit Vertical position of split. * @param topRow Top row visible in bottom pane * @param leftmostColumn Left column visible in right pane. */ public void createFreezePane(int colSplit, int rowSplit, int leftmostColumn, int topRow ) { if (colSplit < 0 || colSplit > 255) throw new IllegalArgumentException("Column must be between 0 and 255"); if (rowSplit < 0 || rowSplit > 65535) throw new IllegalArgumentException("Row must be between 0 and 65535"); if (leftmostColumn < colSplit) throw new IllegalArgumentException("leftmostColumn parameter must not be less than colSplit parameter"); if (topRow < rowSplit) throw new IllegalArgumentException("topRow parameter must not be less than leftmostColumn parameter"); getSheet().createFreezePane( colSplit, rowSplit, topRow, leftmostColumn ); } /** * Creates a split (freezepane). * @param colSplit Horizonatal position of split. * @param rowSplit Vertical position of split. */ public void createFreezePane( int colSplit, int rowSplit ) { createFreezePane( colSplit, rowSplit, colSplit, rowSplit ); } /** * Creates a split pane. * @param xSplitPos Horizonatal position of split (in 1/20th of a point). * @param ySplitPos Vertical position of split (in 1/20th of a point). * @param topRow Top row visible in bottom pane * @param leftmostColumn Left column visible in right pane. * @param activePane Active pane. One of: PANE_LOWER_RIGHT, * PANE_UPPER_RIGHT, PANE_LOWER_LEFT, PANE_UPPER_LEFT * @see #PANE_LOWER_LEFT * @see #PANE_LOWER_RIGHT * @see #PANE_UPPER_LEFT * @see #PANE_UPPER_RIGHT */ public void createSplitPane(int xSplitPos, int ySplitPos, int leftmostColumn, int topRow, int activePane ) { getSheet().createSplitPane( xSplitPos, ySplitPos, topRow, leftmostColumn, activePane ); } /** * Sets whether the gridlines are shown in a viewer. * @param show whether to show gridlines or not */ public void setDisplayGridlines(boolean show) { sheet.setDisplayGridlines(show); } /** * Returns if gridlines are displayed. * @return whether gridlines are displayed */ public boolean isDisplayGridlines() { return sheet.isDisplayGridlines(); } /** * Sets whether the formulas are shown in a viewer. * @param show whether to show formulas or not */ public void setDisplayFormulas(boolean show) { sheet.setDisplayFormulas(show); } /** * Returns if formulas are displayed. * @return whether formulas are displayed */ public boolean isDisplayFormulas() { return sheet.isDisplayFormulas(); } /** * Sets whether the RowColHeadings are shown in a viewer. * @param show whether to show RowColHeadings or not */ public void setDisplayRowColHeadings(boolean show) { sheet.setDisplayRowColHeadings(show); } /** * Returns if RowColHeadings are displayed. * @return whether RowColHeadings are displayed */ public boolean isDisplayRowColHeadings() { return sheet.isDisplayRowColHeadings(); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -