📄 sheetimpl.java
字号:
* * @return whether or not the sheet is hidden * @deprecated in favour of the getSettings function */ public boolean isHidden() { return hidden; } /** * Gets the column info record for the specified column. If no * column is specified, null is returned * * @param col the column * @return the ColumnInfoRecord if specified, NULL otherwise */ public ColumnInfoRecord getColumnInfo(int col) { if (!columnInfosInitialized) { // Initialize the array Iterator i = columnInfosArray.iterator(); ColumnInfoRecord cir = null; while (i.hasNext()) { cir = (ColumnInfoRecord) i.next(); int startcol = Math.max(0, cir.getStartColumn()); int endcol = Math.min(columnInfos.length - 1, cir.getEndColumn()); for (int c = startcol; c <= endcol; c++) { columnInfos[c] = cir; } if (endcol < startcol) { columnInfos[startcol] = cir; } } columnInfosInitialized = true; } return col < columnInfos.length ? columnInfos[col] : null; } /** * Gets all the column info records * * @return the ColumnInfoRecordArray */ public ColumnInfoRecord[] getColumnInfos() { // Just chuck all the column infos we have into an array ColumnInfoRecord[] infos = new ColumnInfoRecord[columnInfosArray.size()]; for (int i = 0; i < columnInfosArray.size(); i++) { infos[i] = (ColumnInfoRecord) columnInfosArray.get(i); } return infos; } /** * Sets the visibility of this sheet * * @param h hidden flag */ final void setHidden(boolean h) { hidden = h; } /** * Clears out the array of cells. This is done for memory allocation * reasons when reading very large sheets */ final void clear() { cells = null; mergedCells = null; columnInfosArray.clear(); sharedFormulas.clear(); hyperlinks.clear(); columnInfosInitialized = false; if (!workbookSettings.getGCDisabled()) { System.gc(); } } /** * Reads in the contents of this sheet */ final void readSheet() { // If this sheet contains only a chart, then set everything to // empty and do not bother parsing the sheet // Thanks to steve.brophy for spotting this if (!sheetBof.isWorksheet()) { numRows = 0; numCols = 0; cells = new Cell[0][0]; // return; } SheetReader reader = new SheetReader(excelFile, sharedStrings, formattingRecords, sheetBof, workbookBof, nineteenFour, workbook, startPosition, this); reader.read(); // Take stuff that was read in numRows = reader.getNumRows(); numCols = reader.getNumCols(); cells = reader.getCells(); rowProperties = reader.getRowProperties(); columnInfosArray = reader.getColumnInfosArray(); hyperlinks = reader.getHyperlinks(); charts = reader.getCharts(); drawings = reader.getDrawings(); dataValidation = reader.getDataValidation(); mergedCells = reader.getMergedCells(); settings = reader.getSettings(); settings.setHidden(hidden); rowBreaks = reader.getRowBreaks(); workspaceOptions = reader.getWorkspaceOptions(); plsRecord = reader.getPLS(); buttonPropertySet = reader.getButtonPropertySet(); reader = null; if (!workbookSettings.getGCDisabled()) { System.gc(); } if (columnInfosArray.size() > 0) { ColumnInfoRecord cir = (ColumnInfoRecord) columnInfosArray.get(columnInfosArray.size() - 1); columnInfos = new ColumnInfoRecord[cir.getEndColumn() + 1]; } else { columnInfos = new ColumnInfoRecord[0]; } } /** * Gets the hyperlinks on this sheet * * @return an array of hyperlinks */ public Hyperlink[] getHyperlinks() { Hyperlink[] hl = new Hyperlink[hyperlinks.size()]; for (int i = 0; i < hyperlinks.size(); i++) { hl[i] = (Hyperlink) hyperlinks.get(i); } return hl; } /** * Gets the cells which have been merged on this sheet * * @return an array of range objects */ public Range[] getMergedCells() { if (mergedCells == null) { return new Range[0]; } return mergedCells; } /** * Gets the non-default rows. Used when copying spreadsheets * * @return an array of row properties */ public RowRecord[] getRowProperties() { RowRecord[] rp = new RowRecord[rowProperties.size()]; for (int i = 0; i < rp.length; i++) { rp[i] = (RowRecord) rowProperties.get(i); } return rp; } /** * Gets the data validations. Used when copying sheets * * @return the data validations */ public DataValidation getDataValidation() { return dataValidation; } /** * Gets the row record. Usually called by the cell in the specified * row in order to determine its size * * @param r the row * @return the RowRecord for the specified row */ RowRecord getRowInfo(int r) { if (!rowRecordsInitialized) { rowRecords = new RowRecord[getRows()]; Iterator i = rowProperties.iterator(); int rownum = 0; RowRecord rr = null; while (i.hasNext()) { rr = (RowRecord) i.next(); rownum = rr.getRowNumber(); if (rownum < rowRecords.length) { rowRecords[rownum] = rr; } } } return rowRecords[r]; } /** * Gets the row breaks. Called when copying sheets * * @return the explicit row breaks */ public final int[] getRowPageBreaks() { return rowBreaks; } /** * Gets the charts. Called when copying sheets * * @return the charts on this page */ public final Chart[] getCharts() { Chart[] ch = new Chart[charts.size()]; for (int i = 0; i < ch.length; i++) { ch[i] = (Chart) charts.get(i); } return ch; } /** * Gets the drawings. Called when copying sheets * * @return the drawings on this page */ public final DrawingGroupObject[] getDrawings() { Object[] dr = drawings.toArray(); DrawingGroupObject[] dr2 = new DrawingGroupObject[dr.length]; System.arraycopy(dr, 0, dr2, 0, dr.length); return dr2; } /** * Determines whether the sheet is protected * * @return whether or not the sheet is protected * @deprecated in favour of the getSettings() api */ public boolean isProtected() { return settings.isProtected(); } /** * Gets the workspace options for this sheet. Called during the copy * process * * @return the workspace options */ public WorkspaceInformationRecord getWorkspaceOptions() { return workspaceOptions; } /** * Accessor for the sheet settings * * @return the settings for this sheet */ public SheetSettings getSettings() { return settings; } /** * Accessor for the workbook * @return the workbook */ WorkbookParser getWorkbook() { return workbook; } /** * Gets the column format for the specified column * * @param col the column number * @return the column format, or NULL if the column has no specific format * @deprecated use getColumnView instead */ public CellFormat getColumnFormat(int col) { CellView cv = getColumnView(col); return cv.getFormat(); } /** * Gets the column width for the specified column * * @param col the column number * @return the column width, or the default width if the column has no * specified format */ public int getColumnWidth(int col) { return getColumnView(col).getSize()/256; } /** * Gets the column width for the specified column * * @param col the column number * @return the column format, or the default format if no override is specified */ public CellView getColumnView(int col) { ColumnInfoRecord cir = getColumnInfo(col); CellView cv = new CellView(); if (cir != null) { cv.setDimension(cir.getWidth()/256); //deprecated cv.setSize(cir.getWidth()); cv.setHidden(cir.getHidden()); cv.setFormat(formattingRecords.getXFRecord(cir.getXFIndex())); } else { cv.setDimension(settings.getDefaultColumnWidth()/256);//deprecated cv.setSize(settings.getDefaultColumnWidth()); } return cv; } /** * Gets the row height for the specified column * * @param row the row number * @return the row height, or the default height if the row has no * specified format * @deprecated use getRowView instead */ public int getRowHeight(int row) { return getRowView(row).getDimension(); } /** * Gets the row view for the specified row * * @param row the row number * @return the row format, or the default format if no override is specified */ public CellView getRowView(int row) { RowRecord rr = getRowInfo(row); CellView cv = new CellView(); if (rr != null) { cv.setDimension(rr.getRowHeight());//deprecated cv.setSize(rr.getRowHeight()); cv.setHidden(rr.isCollapsed()); } else { cv.setDimension(settings.getDefaultRowHeight()); cv.setSize(settings.getDefaultRowHeight());//deprecated } return cv; } /** * Used when copying sheets in order to determine the type of this sheet * * @return the BOF Record */ public BOFRecord getSheetBof() { return sheetBof; } /** * Accessor for the environment specific print record, invoked when * copying sheets * * @return the environment specific print record */ public PLSRecord getPLS() { return plsRecord; } /** * Accessor for the button property set, used during copying */ public ButtonPropertySetRecord getButtonPropertySet() { return buttonPropertySet; } /** * Accessor for the number of images on the sheet * * @return the number of images on this sheet */ public int getNumberOfImages() { if (images == null) { initializeImages(); } return images.size(); } /** * Accessor for the image * * @param i the 0 based image number * @return the image at the specified position */ public Image getDrawing(int i) { if (images == null) { initializeImages(); } return (Image) images.get(i); } /** * Initializes the images */ private void initializeImages() { if (images != null) { return; } images = new ArrayList(); DrawingGroupObject[] dgos = getDrawings(); for (int i = 0 ; i < dgos.length ; i++) { if (dgos[i] instanceof Drawing) { images.add(dgos[i]); } } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -