sheet.java
来自「EXCEL read and write」· Java 代码 · 共 1,758 行 · 第 1/5 页
JAVA
1,758 行
*/ public void setColumnHidden(int column, boolean hidden) { setColumn( column, null, null, null, Boolean.valueOf(hidden), null); } public void setDefaultColumnStyle(int column, int styleIndex) { setColumn(column, new Short((short)styleIndex), null, null, null, null); } private void setColumn(int column, Short xfStyle, Integer width, Integer level, Boolean hidden, Boolean collapsed) { _columnInfos.setColumn( column, xfStyle, width, level, hidden, collapsed ); } /** * Creates an outline group for the specified columns. * @param fromColumn group from this column (inclusive) * @param toColumn group to this column (inclusive) * @param indent if true the group will be indented by one level, * if false indenting will be removed by one level. */ public void groupColumnRange(int fromColumn, int toColumn, boolean indent) { // Set the level for each column _columnInfos.groupColumnRange( fromColumn, toColumn, indent); // Determine the maximum overall level int maxLevel = _columnInfos.getMaxOutlineLevel(); GutsRecord guts = getGutsRecord(); guts.setColLevelMax( (short) ( maxLevel+1 ) ); if (maxLevel == 0) { guts.setTopColGutter( (short)0 ); } else { guts.setTopColGutter( (short) ( 29 + (12 * (maxLevel-1)) ) ); } } /** * creates the Dimensions Record and sets it to bogus values (you should set this yourself * or let the high level API do it for you) */ private static DimensionsRecord createDimensions() { DimensionsRecord retval = new DimensionsRecord(); retval.setFirstCol(( short ) 0); retval.setLastRow(1); // one more than it is retval.setFirstRow(0); retval.setLastCol(( short ) 1); // one more than it is return retval; } /** * creates the WindowTwo Record and sets it to: <P> * options = 0x6b6 <P> * toprow = 0 <P> * leftcol = 0 <P> * headercolor = 0x40 <P> * pagebreakzoom = 0x0 <P> * normalzoom = 0x0 <p> */ private static WindowTwoRecord createWindowTwo() { WindowTwoRecord retval = new WindowTwoRecord(); retval.setOptions(( short ) 0x6b6); retval.setTopRow(( short ) 0); retval.setLeftCol(( short ) 0); retval.setHeaderColor(0x40); retval.setPageBreakZoom(( short ) 0); retval.setNormalZoom(( short ) 0); return retval; } /** * Creates the Selection record and sets it to nothing selected */ private static SelectionRecord createSelection() { return new SelectionRecord(0, 0); } public short getTopRow() { return (windowTwo==null) ? (short) 0 : windowTwo.getTopRow(); } public void setTopRow(short topRow) { if (windowTwo!=null) { windowTwo.setTopRow(topRow); } } /** * Sets the left column to show in desktop window pane. * @param leftCol the left column to show in desktop window pane */ public void setLeftCol(short leftCol){ if (windowTwo!=null) { windowTwo.setLeftCol(leftCol); } } public short getLeftCol() { return (windowTwo==null) ? (short) 0 : windowTwo.getLeftCol(); } /** * Returns the active row * * @see org.apache.poi.hssf.record.SelectionRecord * @return row the active row index */ public int getActiveCellRow() { if (selection == null) { return 0; } return selection.getActiveCellRow(); } /** * Sets the active row * * @param row the row index * @see org.apache.poi.hssf.record.SelectionRecord */ public void setActiveCellRow(int row) { //shouldn't have a sheet w/o a SelectionRecord, but best to guard anyway if (selection != null) { selection.setActiveCellRow(row); } } /** * @see org.apache.poi.hssf.record.SelectionRecord * @return column of the active cell */ public short getActiveCellCol() { if (selection == null) { return 0; } return (short)selection.getActiveCellCol(); } /** * Sets the active column * * @param col the column index * @see org.apache.poi.hssf.record.SelectionRecord */ public void setActiveCellCol(short col) { //shouldn't have a sheet w/o a SelectionRecord, but best to guard anyway if (selection != null) { selection.setActiveCellCol(col); } } public List getRecords() { return records; } /** * Gets the gridset record for this sheet. */ public GridsetRecord getGridsetRecord() { return gridset; } /** * Returns the first occurrence of a record matching a particular sid. */ public Record findFirstRecordBySid(short sid) { int ix = findFirstRecordLocBySid(sid); if (ix < 0) { return null; } return (Record) records.get(ix); } /** * Sets the SCL record or creates it in the correct place if it does not * already exist. * * @param sclRecord The record to set. */ public void setSCLRecord(SCLRecord sclRecord) { int oldRecordLoc = findFirstRecordLocBySid(SCLRecord.sid); if (oldRecordLoc == -1) { // Insert it after the window record int windowRecordLoc = findFirstRecordLocBySid(WindowTwoRecord.sid); records.add(windowRecordLoc+1, sclRecord); } else { records.set(oldRecordLoc, sclRecord); } } /** * Finds the first occurrence of a record matching a particular sid and * returns it's position. * @param sid the sid to search for * @return the record position of the matching record or -1 if no match * is made. */ public int findFirstRecordLocBySid( short sid ) { // TODO - remove this method int max = records.size(); for (int i=0; i< max; i++) { Object rb = records.get(i); if (!(rb instanceof Record)) { continue; } Record record = (Record) rb; if (record.getSid() == sid) { return i; } } return -1; } public WindowTwoRecord getWindowTwo() { return windowTwo; } /** * Returns the PrintGridlinesRecord. * @return PrintGridlinesRecord for the sheet. */ public PrintGridlinesRecord getPrintGridlines () { return printGridlines; } /** * Sets the PrintGridlinesRecord. * @param newPrintGridlines The new PrintGridlinesRecord for the sheet. */ public void setPrintGridlines (PrintGridlinesRecord newPrintGridlines) { printGridlines = newPrintGridlines; } /** * Sets whether the sheet is selected * @param sel True to select the sheet, false otherwise. */ public void setSelected(boolean sel) { windowTwo.setSelected(sel); } /** * Creates a split (freezepane). Any existing freezepane or split pane is overwritten. * @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 topRow, int leftmostColumn ) { int paneLoc = findFirstRecordLocBySid(PaneRecord.sid); if (paneLoc != -1) records.remove(paneLoc); int loc = findFirstRecordLocBySid(WindowTwoRecord.sid); PaneRecord pane = new PaneRecord(); pane.setX((short)colSplit); pane.setY((short)rowSplit); pane.setTopRow((short) topRow); pane.setLeftColumn((short) leftmostColumn); if (rowSplit == 0) { pane.setTopRow((short)0); pane.setActivePane((short)1); } else if (colSplit == 0) { pane.setLeftColumn((short)64); pane.setActivePane((short)2); } else { pane.setActivePane((short)0); } records.add(loc+1, pane); windowTwo.setFreezePanes(true); windowTwo.setFreezePanesNoSplit(true); SelectionRecord sel = (SelectionRecord) findFirstRecordBySid(SelectionRecord.sid); sel.setPane((byte)pane.getActivePane()); } /** * Creates a split pane. Any existing freezepane or split pane is overwritten. * @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 topRow, int leftmostColumn, int activePane ) { int paneLoc = findFirstRecordLocBySid(PaneRecord.sid); if (paneLoc != -1) records.remove(paneLoc); int loc = findFirstRecordLocBySid(WindowTwoRecord.sid); PaneRecord r = new PaneRecord(); r.setX((short)xSplitPos); r.setY((short)ySplitPos); r.setTopRow((short) topRow); r.setLeftColumn((short) leftmostColumn); r.setActivePane((short) activePane); records.add(loc+1, r); windowTwo.setFreezePanes(false); windowTwo.setFreezePanesNoSplit(false); SelectionRecord sel = (SelectionRecord) findFirstRecordBySid(SelectionRecord.sid); sel.setPane(PANE_LOWER_RIGHT); } /** * Returns the information regarding the currently configured pane (split or freeze). * @return null if no pane configured, or the pane information. */ public PaneInformation getPaneInformation() { PaneRecord rec = (PaneRecord)findFirstRecordBySid(PaneRecord.sid); if (rec == null) return null; return new PaneInformation(rec.getX(), rec.getY(), rec.getTopRow(),
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?