mirror of https://github.com/apache/poi.git
Applied patch 45899 - XSSFWorkbook getActiveSheetIndex / setActiveSheet
git-svn-id: https://svn.apache.org/repos/asf/poi/branches/ooxml@699989 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
93e1ccd36b
commit
9874fdf90c
|
@ -26,6 +26,13 @@ import org.apache.poi.hssf.usermodel.*;
|
||||||
* which work properly for both HSSFWorkbook and XSSFWorkbook
|
* which work properly for both HSSFWorkbook and XSSFWorkbook
|
||||||
*/
|
*/
|
||||||
public interface Workbook {
|
public interface Workbook {
|
||||||
|
|
||||||
|
int getActiveSheetIndex();
|
||||||
|
void setActiveSheet(int sheetIndex);
|
||||||
|
|
||||||
|
int getFirstVisibleTab();
|
||||||
|
void setFirstVisibleTab(int sheetIndex);
|
||||||
|
|
||||||
int getNumberOfSheets();
|
int getNumberOfSheets();
|
||||||
short getNumberOfFonts();
|
short getNumberOfFonts();
|
||||||
int getNumberOfNames();
|
int getNumberOfNames();
|
||||||
|
@ -34,15 +41,11 @@ public interface Workbook {
|
||||||
HSSFName getNameAt(int index);
|
HSSFName getNameAt(int index);
|
||||||
int getNameIndex(String name);
|
int getNameIndex(String name);
|
||||||
String getNameName(int index);
|
String getNameName(int index);
|
||||||
String resolveNameXText(int refIndex, int definedNameIndex);
|
|
||||||
|
|
||||||
String getSheetName(int sheet);
|
String getSheetName(int sheet);
|
||||||
HSSFSheet getSheetAt(int index);
|
HSSFSheet getSheetAt(int index);
|
||||||
String findSheetNameFromExternSheet(int externSheetIndex);
|
|
||||||
int getSheetIndex(String name);
|
int getSheetIndex(String name);
|
||||||
int getSheetIndex(Sheet sheet);
|
int getSheetIndex(Sheet sheet);
|
||||||
int getSheetIndexFromExternSheetIndex(int externSheetNumber);
|
|
||||||
int getExternalSheetIndex(int internalSheetIndex);
|
|
||||||
|
|
||||||
CreationHelper getCreationHelper();
|
CreationHelper getCreationHelper();
|
||||||
|
|
||||||
|
|
|
@ -49,9 +49,15 @@ public interface Workbook {
|
||||||
/** PNG format */
|
/** PNG format */
|
||||||
public static final int PICTURE_TYPE_PNG = 6;
|
public static final int PICTURE_TYPE_PNG = 6;
|
||||||
|
|
||||||
/** Device independant bitmap */
|
/** Device independent bitmap */
|
||||||
public static final int PICTURE_TYPE_DIB = 7;
|
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.
|
* sets the order of appearance for a given sheet.
|
||||||
*
|
*
|
||||||
|
@ -80,19 +86,6 @@ public interface Workbook {
|
||||||
*/
|
*/
|
||||||
short getSelectedTab();
|
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.
|
* set the sheet name.
|
||||||
* Will throw IllegalArgumentException if the name is greater than 31 chars
|
* Will throw IllegalArgumentException if the name is greater than 31 chars
|
||||||
|
|
|
@ -27,10 +27,8 @@ import java.util.List;
|
||||||
import javax.xml.namespace.QName;
|
import javax.xml.namespace.QName;
|
||||||
|
|
||||||
import org.apache.poi.POIXMLDocument;
|
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.CommentsSource;
|
||||||
import org.apache.poi.ss.usermodel.CreationHelper;
|
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.Palette;
|
||||||
import org.apache.poi.ss.usermodel.PictureData;
|
import org.apache.poi.ss.usermodel.PictureData;
|
||||||
import org.apache.poi.ss.usermodel.Row;
|
import org.apache.poi.ss.usermodel.Row;
|
||||||
|
@ -337,6 +335,18 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook {
|
||||||
return null;
|
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() {
|
public List getAllEmbeddedObjects() {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
return null;
|
return null;
|
||||||
|
@ -518,6 +528,29 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook {
|
||||||
this.missingCellPolicy = missingCellPolicy;
|
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) {
|
public void setBackupFlag(boolean backupValue) {
|
||||||
// TODO Auto-generated method stub
|
// 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.
|
* @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();
|
CTBookViews bookViews = workbook.getBookViews();
|
||||||
CTBookView bookView= bookViews.getWorkbookViewArray(0);
|
CTBookView bookView= bookViews.getWorkbookViewArray(0);
|
||||||
bookView.setActiveTab(index);
|
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) {
|
public void setPrintArea(int sheetIndex, String reference) {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
|
|
@ -43,7 +43,7 @@ import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorkbook;
|
||||||
public final class TestXSSFWorkbook extends TestCase {
|
public final class TestXSSFWorkbook extends TestCase {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void setUp() throws Exception {
|
protected void setUp() {
|
||||||
// Use system out logger
|
// Use system out logger
|
||||||
System.setProperty(
|
System.setProperty(
|
||||||
"org.apache.poi.util.POILogger",
|
"org.apache.poi.util.POILogger",
|
||||||
|
@ -51,6 +51,17 @@ public final class TestXSSFWorkbook extends TestCase {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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() {
|
public void testGetSheetIndex() {
|
||||||
XSSFWorkbook workbook = new XSSFWorkbook();
|
XSSFWorkbook workbook = new XSSFWorkbook();
|
||||||
Sheet sheet1 = workbook.createSheet("sheet1");
|
Sheet sheet1 = workbook.createSheet("sheet1");
|
||||||
|
|
Loading…
Reference in New Issue