Fix for Bug#28328

git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@353773 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Amol S. Deshmukh 2005-08-24 16:26:20 +00:00
parent a20040b430
commit cea5e5c6d1
3 changed files with 78 additions and 2 deletions

View File

@ -100,6 +100,7 @@ public class Workbook implements Model
private boolean uses1904datewindowing = false; // whether 1904 date windowing is being used
private DrawingManager2 drawingManager;
private List escherBSERecords = new ArrayList(); // EscherBSERecord
private WindowOneRecord windowOne;
private static POILogger log = POILogFactory.getLogger(Workbook.class);
@ -215,6 +216,10 @@ public class Workbook implements Model
if (log.check( POILogger.DEBUG ))
log.log(DEBUG, "found palette record at " + k);
retval.records.setPalettepos( k );
case WindowOneRecord.sid:
if (log.check( POILogger.DEBUG ))
log.log(DEBUG, "found WindowOneRecord at " + k);
retval.windowOne = (WindowOneRecord) rec;
default :
}
records.add(rec);
@ -226,6 +231,10 @@ public class Workbook implements Model
// }
retval.records.setRecords(records);
if (retval.windowOne == null) {
retval.windowOne = (WindowOneRecord) retval.createWindowOne();
}
if (log.check( POILogger.DEBUG ))
log.log(DEBUG, "exit create workbook from existing file function");
return retval;
@ -259,7 +268,8 @@ public class Workbook implements Model
records.add( retval.createPassword() );
records.add( retval.createProtectionRev4() );
records.add( retval.createPasswordRev4() );
records.add( retval.createWindowOne() );
retval.windowOne = (WindowOneRecord) retval.createWindowOne();
records.add( retval.windowOne );
records.add( retval.createBackup() );
retval.records.setBackuppos( records.size() - 1 );
records.add( retval.createHideObj() );
@ -2165,6 +2175,10 @@ public class Workbook implements Model
}
public WindowOneRecord getWindowOne() {
return windowOne;
}
public int addBSERecord(EscherBSERecord e)
{
createDrawingGroup();

View File

@ -252,6 +252,48 @@ public class HSSFWorkbook
workbook.setSheetOrder(sheetname, pos);
}
/**
* sets the tab whose data is actually seen when the sheet is opened.
* This may be different from the "selected sheet" since excel seems to
* allow you to show the data of one sheet when another is seen "selected"
* in the tabs (at the bottom).
* @see org.apache.poi.hssf.usermodel.HSSFSheet#setSelected(boolean)
* @param index
*/
public void setSelectedTab(short index) {
workbook.getWindowOne().setSelectedTab(index);
}
/**
* gets the tab whose data is actually seen when the sheet is opened.
* This may be different from the "selected sheet" since excel seems to
* allow you to show the data of one sheet when another is seen "selected"
* in the tabs (at the bottom).
* @see org.apache.poi.hssf.usermodel.HSSFSheet#setSelected(boolean)
* @return
*/
public short getSelectedTab() {
return workbook.getWindowOne().getSelectedTab();
}
/**
* sets the first tab that is displayed in the list of tabs
* in excel.
* @param index
*/
public void setDisplayedTab(short index) {
workbook.getWindowOne().setDisplayedTab(index);
}
/**
* sets the first tab that is displayed in the list of tabs
* in excel.
* @return
*/
public short getDisplayedTab() {
return workbook.getWindowOne().getDisplayedTab();
}
public final static byte ENCODING_COMPRESSED_UNICODE = 0;
public final static byte ENCODING_UTF_16 = 1;

View File

@ -64,4 +64,24 @@ public class TestHSSFWorkbook extends TestCase
c.createSheet("Sheet4");
}
public void testWindowOneDefaults() {
HSSFWorkbook b = new HSSFWorkbook( );
try {
assertEquals(b.getSelectedTab(), 0);
assertEquals(b.getDisplayedTab(), 0);
} catch (NullPointerException npe) {
fail("WindowOneRecord in Workbook is probably not initialized");
}
}
public void testSheetSelection() {
HSSFWorkbook b = new HSSFWorkbook();
b.createSheet("Sheet One");
HSSFSheet s = b.createSheet("Sheet Two");
b.setSelectedTab((short) 1);
b.setDisplayedTab((short) 1);
assertEquals(b.getSelectedTab(), 1);
assertEquals(b.getDisplayedTab(), 1);
}
}