consolidate duplicated code: XSSFWorkbook#setBookViewsIfMissing()

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1813841 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Javen O'Neal 2017-10-31 01:45:03 +00:00
parent 179fa31242
commit b4ee3da44f
1 changed files with 11 additions and 21 deletions

View File

@ -275,11 +275,7 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook {
load(XSSFFactory.getInstance());
// some broken Workbooks miss this...
if(!workbook.isSetBookViews()) {
CTBookViews bvs = workbook.addNewBookViews();
CTBookView bv = bvs.addNewWorkbookView();
bv.setActiveTab(0);
}
setBookViewsIfMissing();
}
/**
@ -297,19 +293,7 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook {
* </code></pre>
*/
public XSSFWorkbook(InputStream is) throws IOException {
super(PackageHelper.open(is));
beforeDocumentRead();
// Build a tree of POIXMLDocumentParts, this workbook being the root
load(XSSFFactory.getInstance());
// some broken Workbooks miss this...
if(!workbook.isSetBookViews()) {
CTBookViews bvs = workbook.addNewBookViews();
CTBookView bv = bvs.addNewWorkbookView();
bv.setActiveTab(0);
}
this(PackageHelper.open(is));
}
/**
@ -459,9 +443,7 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook {
CTWorkbookPr workbookPr = workbook.addNewWorkbookPr();
workbookPr.setDate1904(false);
CTBookViews bvs = workbook.addNewBookViews();
CTBookView bv = bvs.addNewWorkbookView();
bv.setActiveTab(0);
setBookViewsIfMissing();
workbook.addNewSheets();
POIXMLProperties.ExtendedProperties expProps = getProperties().getExtendedProperties();
@ -476,6 +458,14 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook {
sheets = new ArrayList<>();
pivotTables = new ArrayList<>();
}
private void setBookViewsIfMissing() {
if(!workbook.isSetBookViews()) {
CTBookViews bvs = workbook.addNewBookViews();
CTBookView bv = bvs.addNewWorkbookView();
bv.setActiveTab(0);
}
}
/**
* Create a new SpreadsheetML package and setup the default minimal content