You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by jo...@apache.org on 2008/09/29 06:50:21 UTC

svn commit: r699989 - in /poi/branches/ooxml/src/ooxml: interfaces-jdk14/org/apache/poi/ss/usermodel/ interfaces-jdk15/org/apache/poi/ss/usermodel/ java/org/apache/poi/xssf/usermodel/ testcases/org/apache/poi/xssf/usermodel/

Author: josh
Date: Sun Sep 28 21:50:20 2008
New Revision: 699989

URL: http://svn.apache.org/viewvc?rev=699989&view=rev
Log:
Applied patch 45899 - XSSFWorkbook getActiveSheetIndex / setActiveSheet

Modified:
    poi/branches/ooxml/src/ooxml/interfaces-jdk14/org/apache/poi/ss/usermodel/Workbook.java
    poi/branches/ooxml/src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/Workbook.java
    poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java
    poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFWorkbook.java

Modified: poi/branches/ooxml/src/ooxml/interfaces-jdk14/org/apache/poi/ss/usermodel/Workbook.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/ooxml/interfaces-jdk14/org/apache/poi/ss/usermodel/Workbook.java?rev=699989&r1=699988&r2=699989&view=diff
==============================================================================
--- poi/branches/ooxml/src/ooxml/interfaces-jdk14/org/apache/poi/ss/usermodel/Workbook.java (original)
+++ poi/branches/ooxml/src/ooxml/interfaces-jdk14/org/apache/poi/ss/usermodel/Workbook.java Sun Sep 28 21:50:20 2008
@@ -26,6 +26,13 @@
  *  which work properly for both HSSFWorkbook and XSSFWorkbook
  */
 public interface Workbook {
+
+    int getActiveSheetIndex();
+    void setActiveSheet(int sheetIndex);
+
+    int getFirstVisibleTab();
+    void setFirstVisibleTab(int sheetIndex);
+
     int getNumberOfSheets();
     short getNumberOfFonts();
     int getNumberOfNames();
@@ -34,15 +41,11 @@
     HSSFName getNameAt(int index);
     int getNameIndex(String name);
     String getNameName(int index);
-    String resolveNameXText(int refIndex, int definedNameIndex);
 
     String getSheetName(int sheet);
     HSSFSheet getSheetAt(int index);
-    String findSheetNameFromExternSheet(int externSheetIndex);
     int getSheetIndex(String name);
     int getSheetIndex(Sheet sheet);
-    int getSheetIndexFromExternSheetIndex(int externSheetNumber);
-	int getExternalSheetIndex(int internalSheetIndex);
 
     CreationHelper getCreationHelper();
 

Modified: poi/branches/ooxml/src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/Workbook.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/Workbook.java?rev=699989&r1=699988&r2=699989&view=diff
==============================================================================
--- poi/branches/ooxml/src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/Workbook.java (original)
+++ poi/branches/ooxml/src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/Workbook.java Sun Sep 28 21:50:20 2008
@@ -49,9 +49,15 @@
     /** PNG format */
     public static final int PICTURE_TYPE_PNG = 6;
 
-    /** Device independant bitmap */
+    /** Device independent bitmap */
     public static final int PICTURE_TYPE_DIB = 7;
 
+    int getActiveSheetIndex();
+    void setActiveSheet(int sheetIndex);
+
+    int getFirstVisibleTab();
+    void setFirstVisibleTab(int sheetIndex);
+
     /**
      * sets the order of appearance for a given sheet.
      *
@@ -81,19 +87,6 @@
     short getSelectedTab();
 
     /**
-     * sets the first tab that is displayed in the list of tabs
-     * in excel.
-     * @param index
-     */
-    void setDisplayedTab(short index);
-
-    /**
-     * sets the first tab that is displayed in the list of tabs
-     * in excel.
-     */
-    short getDisplayedTab();
-
-    /**
      * set the sheet name.
      * Will throw IllegalArgumentException if the name is greater than 31 chars
      * or contains /\?*[]

Modified: poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java?rev=699989&r1=699988&r2=699989&view=diff
==============================================================================
--- poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java (original)
+++ poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java Sun Sep 28 21:50:20 2008
@@ -27,10 +27,8 @@
 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 @@
     	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 @@
 		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 @@
      *
      * @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
 

Modified: poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFWorkbook.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFWorkbook.java?rev=699989&r1=699988&r2=699989&view=diff
==============================================================================
--- poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFWorkbook.java (original)
+++ poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFWorkbook.java Sun Sep 28 21:50:20 2008
@@ -43,7 +43,7 @@
 public final class TestXSSFWorkbook extends TestCase {
 
 	@Override
-	protected void setUp() throws Exception {
+	protected void setUp() {
 		// Use system out logger
 		System.setProperty(
 				"org.apache.poi.util.POILogger",
@@ -51,6 +51,17 @@
 		);
 	}
 
+	public void testGetSetActiveSheet(){
+		XSSFWorkbook workbook = new XSSFWorkbook();
+		workbook.createSheet("sheet1");
+		workbook.createSheet("sheet2");
+		workbook.createSheet("sheet3");
+		// set second sheet
+		workbook.setActiveSheet(1);
+		// test if second sheet is set up
+		assertEquals(1, workbook.getActiveSheetIndex());
+	}
+
 	public void testGetSheetIndex() {
 		XSSFWorkbook workbook = new XSSFWorkbook();
 		Sheet sheet1 = workbook.createSheet("sheet1");



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org