diff options
author | Josh Micich <josh@apache.org> | 2008-09-29 04:50:20 +0000 |
---|---|---|
committer | Josh Micich <josh@apache.org> | 2008-09-29 04:50:20 +0000 |
commit | 9874fdf90c8e18608927f4cc2a9307c7fec74abd (patch) | |
tree | 10fda74418d10f9b82058413a4721cdb7a913e5b /src/ooxml/java | |
parent | 93e1ccd36b21d32234bc04198a2592cb48187919 (diff) | |
download | poi-9874fdf90c8e18608927f4cc2a9307c7fec74abd.tar.gz poi-9874fdf90c8e18608927f4cc2a9307c7fec74abd.zip |
Applied patch 45899 - XSSFWorkbook getActiveSheetIndex / setActiveSheet
git-svn-id: https://svn.apache.org/repos/asf/poi/branches/ooxml@699989 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/ooxml/java')
-rw-r--r-- | src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java | 61 |
1 files changed, 36 insertions, 25 deletions
diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java index 62743c6183..141bda2928 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java @@ -27,10 +27,8 @@ import java.util.List; import javax.xml.namespace.QName; import org.apache.poi.POIXMLDocument; -import org.apache.poi.ss.usermodel.CellStyle; import org.apache.poi.ss.usermodel.CommentsSource; import org.apache.poi.ss.usermodel.CreationHelper; -import org.apache.poi.ss.usermodel.DataFormat; import org.apache.poi.ss.usermodel.Palette; import org.apache.poi.ss.usermodel.PictureData; import org.apache.poi.ss.usermodel.Row; @@ -337,6 +335,18 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook { return null; } + /** + * Convenience method to get the active sheet. The active sheet is is the sheet + * which is currently displayed when the workbook is viewed in Excel. + * 'Selected' sheet(s) is a distinct concept. + */ + public int getActiveSheetIndex() { + //activeTab (Active Sheet Index) Specifies an unsignedInt + //that contains the index to the active sheet in this book view. + Long index = workbook.getBookViews().getWorkbookViewArray(0).getActiveTab(); + return index.intValue(); + } + public List getAllEmbeddedObjects() { // TODO Auto-generated method stub return null; @@ -518,6 +528,29 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook { this.missingCellPolicy = missingCellPolicy; } + /** + * Convenience method to set the active sheet. The active sheet is is the sheet + * which is currently displayed when the workbook is viewed in Excel. + * 'Selected' sheet(s) is a distinct concept. + */ + public void setActiveSheet(int index) { + + validateSheetIndex(index); + //activeTab (Active Sheet Index) Specifies an unsignedInt that contains the index to the active sheet in this book view. + CTBookView[] arrayBook = workbook.getBookViews().getWorkbookViewArray(); + for (int i = 0; i < arrayBook.length; i++) { + workbook.getBookViews().getWorkbookViewArray(i).setActiveTab(index); + } + } + + private void validateSheetIndex(int index) { + int lastSheetIx = sheets.size() - 1; + if (index < 0 || index > lastSheetIx) { + throw new IllegalArgumentException("Sheet index (" + + index +") is out of range (0.." + lastSheetIx + ")"); + } + } + public void setBackupFlag(boolean backupValue) { // TODO Auto-generated method stub @@ -539,34 +572,12 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook { * * @param index integer that contains the index to the active sheet in this book view. */ - public void setFirstVisibleTab(short index) { + public void setFirstVisibleTab(int index) { CTBookViews bookViews = workbook.getBookViews(); CTBookView bookView= bookViews.getWorkbookViewArray(0); bookView.setActiveTab(index); } - /** - * Gets the first tab that is displayed in the list of tabs - * in excel. - * @return an integer that contains the index to the active sheet in this book view. - * - * @deprecated Aug 2008 - Misleading name - use #getFirstVisibleTab() - */ - public short getDisplayedTab() { - return (short) getFirstVisibleTab(); - } - - /** - * sets the first tab that is displayed in the list of tabs - * in excel. - * @param index integer that contains the index to the active sheet in this book view. - * - * @deprecated Aug 2008 - Misleading name - use #setFirstVisibleTab() - */ - public void setDisplayedTab(short index) { - setFirstVisibleTab(index); - } - public void setPrintArea(int sheetIndex, String reference) { // TODO Auto-generated method stub |