import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
+import java.io.Reader;
+import java.io.Writer;
import java.nio.charset.StandardCharsets;
import java.util.Enumeration;
import java.util.HashMap;
/**
* Construct a new workbook with default row window size
*/
- public SXSSFWorkbook(){
+ public SXSSFWorkbook()
+ {
this(null /*workbook*/);
}
*
* @param workbook the template workbook
*/
- public SXSSFWorkbook(XSSFWorkbook workbook){
+ public SXSSFWorkbook(XSSFWorkbook workbook) {
this(workbook, DEFAULT_WINDOW_SIZE);
}
*
* @param rowAccessWindowSize the number of rows that are kept in memory until flushed out, see above.
*/
- public SXSSFWorkbook(XSSFWorkbook workbook, int rowAccessWindowSize){
+ public SXSSFWorkbook(XSSFWorkbook workbook, int rowAccessWindowSize) {
this(workbook, rowAccessWindowSize, false);
}
*
* @param rowAccessWindowSize the number of rows that are kept in memory until flushed out, see above.
*/
- public SXSSFWorkbook(int rowAccessWindowSize){
+ public SXSSFWorkbook(int rowAccessWindowSize) {
this(null /*workbook*/, rowAccessWindowSize);
}
return new SheetDataWriter(_sharedStringSource);
}
- XSSFSheet getXSSFSheet(SXSSFSheet sheet)
- {
+ XSSFSheet getXSSFSheet(SXSSFSheet sheet) {
return _sxFromXHash.get(sheet);
}
- SXSSFSheet getSXSSFSheet(XSSFSheet sheet)
- {
+ SXSSFSheet getSXSSFSheet(XSSFSheet sheet) {
return _xFromSxHash.get(sheet);
}
- void registerSheetMapping(SXSSFSheet sxSheet,XSSFSheet xSheet)
- {
+ void registerSheetMapping(SXSSFSheet sxSheet,XSSFSheet xSheet) {
_sxFromXHash.put(sxSheet,xSheet);
_xFromSxHash.put(xSheet,sxSheet);
}
- void deregisterSheetMapping(XSSFSheet xSheet)
- {
+ void deregisterSheetMapping(XSSFSheet xSheet) {
SXSSFSheet sxSheet = getSXSSFSheet(xSheet);
if (sxSheet != null) {
// ensure that the writer is closed in all cases to not have lingering writers
}
}
- protected XSSFSheet getSheetFromZipEntryName(String sheetRef)
- {
- for(XSSFSheet sheet : _sxFromXHash.values())
- {
+ protected XSSFSheet getSheetFromZipEntryName(String sheetRef) {
+ for(XSSFSheet sheet : _sxFromXHash.values()) {
if(sheetRef.equals(sheet.getPackagePart().getPartName().getName().substring(1))) {
return sheet;
}
// private static void copyStreamAndInjectWorksheet(InputStream in, OutputStream out, InputStream worksheetData) throws IOException {
private static void copyStreamAndInjectWorksheet(InputStream in, OutputStream out, ISheetInjector sheetInjector) throws IOException {
- InputStreamReader inReader = new InputStreamReader(in, StandardCharsets.UTF_8);
- OutputStreamWriter outWriter = new OutputStreamWriter(out, StandardCharsets.UTF_8);
+ Reader inReader = new InputStreamReader(in, StandardCharsets.UTF_8);
+ Writer outWriter = new OutputStreamWriter(out, StandardCharsets.UTF_8);
boolean needsStartTag = true;
int c;
int pos=0;
String s="<sheetData";
int n=s.length();
//Copy from "in" to "out" up to the string "<sheetData/>" or "</sheetData>" (excluding).
- while(((c=inReader.read())!=-1))
- {
- if(c==s.charAt(pos))
- {
+ while(((c=inReader.read())!=-1)) {
+ if(c==s.charAt(pos)) {
pos++;
- if(pos==n)
- {
- if ("<sheetData".equals(s))
- {
+ if(pos==n) {
+ if ("<sheetData".equals(s)) {
c = inReader.read();
- if (c == -1)
- {
+ if (c == -1) {
outWriter.write(s);
break;
}
- if (c == '>')
- {
+ if (c == '>') {
// Found <sheetData>
outWriter.write(s);
outWriter.write(c);
needsStartTag = false;
continue;
}
- if (c == '/')
- {
+ if (c == '/') {
// Found <sheetData/
c = inReader.read();
- if (c == -1)
- {
+ if (c == -1) {
outWriter.write(s);
break;
}
- if (c == '>')
- {
+ if (c == '>') {
// Found <sheetData/>
break;
}
outWriter.write(c);
pos = 0;
continue;
- }
- else
- {
+ } else {
// Found </sheetData>
break;
}
}
- }
- else
- {
+ } else {
if(pos>0) {
outWriter.write(s,0,pos);
}
- if(c==s.charAt(0))
- {
+ if(c==s.charAt(0)) {
pos=1;
- }
- else
- {
+ } else {
outWriter.write(c);
pos=0;
}
}
}
outWriter.flush();
- if (needsStartTag)
- {
+ if (needsStartTag) {
outWriter.write("<sheetData>\n");
outWriter.flush();
}
outWriter.flush();
}
- public XSSFWorkbook getXSSFWorkbook()
- {
+ public XSSFWorkbook getXSSFWorkbook() {
return _wb;
}
* @return the index of the active sheet (0-based)
*/
@Override
- public int getActiveSheetIndex()
- {
+ public int getActiveSheetIndex() {
return _wb.getActiveSheetIndex();
}
* @param sheetIndex index of the active sheet (0-based)
*/
@Override
- public void setActiveSheet(int sheetIndex)
- {
+ public void setActiveSheet(int sheetIndex) {
_wb.setActiveSheet(sheetIndex);
}
* @return the first tab that to display in the list of tabs (0-based).
*/
@Override
- public int getFirstVisibleTab()
- {
+ public int getFirstVisibleTab() {
return _wb.getFirstVisibleTab();
}
* @param sheetIndex the first tab that to display in the list of tabs (0-based)
*/
@Override
- public void setFirstVisibleTab(int sheetIndex)
- {
+ public void setFirstVisibleTab(int sheetIndex) {
_wb.setFirstVisibleTab(sheetIndex);
}
* @param pos the position that we want to insert the sheet into (0 based)
*/
@Override
- public void setSheetOrder(String sheetname, int pos)
- {
+ public void setSheetOrder(String sheetname, int pos) {
_wb.setSheetOrder(sheetname,pos);
}
* @param index the index of the sheet to select (0 based)
*/
@Override
- public void setSelectedTab(int index)
- {
+ public void setSelectedTab(int index) {
_wb.setSelectedTab(index);
}
* @throws IllegalArgumentException if the name is greater than 31 chars or contains <code>/\?*[]</code>
*/
@Override
- public void setSheetName(int sheet, String name)
- {
+ public void setSheetName(int sheet, String name) {
_wb.setSheetName(sheet,name);
}
* @return Sheet name
*/
@Override
- public String getSheetName(int sheet)
- {
+ public String getSheetName(int sheet) {
return _wb.getSheetName(sheet);
}
* @return index of the sheet (0 based)
*/
@Override
- public int getSheetIndex(String name)
- {
+ public int getSheetIndex(String name) {
return _wb.getSheetIndex(name);
}
* @return index of the sheet (0 based)
*/
@Override
- public int getSheetIndex(Sheet sheet)
- {
+ public int getSheetIndex(Sheet sheet) {
return _wb.getSheetIndex(getXSSFSheet((SXSSFSheet)sheet));
}
* @return Sheet representing the new sheet.
*/
@Override
- public SXSSFSheet createSheet()
- {
+ public SXSSFSheet createSheet() {
return createAndRegisterSXSSFSheet(_wb.createSheet());
}
* @throws IllegalArgumentException if the name is greater than 31 chars or contains <code>/\?*[]</code>
*/
@Override
- public SXSSFSheet createSheet(String sheetname)
- {
+ public SXSSFSheet createSheet(String sheetname) {
return createAndRegisterSXSSFSheet(_wb.createSheet(sheetname));
}
* @return the number of sheets
*/
@Override
- public int getNumberOfSheets()
- {
+ public int getNumberOfSheets() {
return _wb.getNumberOfSheets();
}
* @return Sheet at the provided index
*/
@Override
- public SXSSFSheet getSheetAt(int index)
- {
+ public SXSSFSheet getSheetAt(int index) {
return getSXSSFSheet(_wb.getSheetAt(index));
}
* @return Sheet with the name provided or <code>null</code> if it does not exist
*/
@Override
- public SXSSFSheet getSheet(String name)
- {
+ public SXSSFSheet getSheet(String name) {
return getSXSSFSheet(_wb.getSheet(name));
}
* @param index of the sheet to remove (0-based)
*/
@Override
- public void removeSheetAt(int index)
- {
+ public void removeSheetAt(int index) {
// Get the sheet to be removed
XSSFSheet xSheet = _wb.getSheetAt(index);
SXSSFSheet sxSheet = getSXSSFSheet(xSheet);
* @return new font object
*/
@Override
- public Font createFont()
- {
+ public Font createFont() {
return _wb.createFont();
}
* @return the font with the matched attributes or <code>null</code>
*/
@Override
- public Font findFont(boolean bold, short color, short fontHeight, String name, boolean italic, boolean strikeout, short typeOffset, byte underline)
- {
+ public Font findFont(boolean bold, short color, short fontHeight, String name, boolean italic, boolean strikeout, short typeOffset, byte underline) {
return _wb.findFont(bold, color, fontHeight, name, italic, strikeout, typeOffset, underline);
}
@Override
@Deprecated
@Removal(version = "6.0.0")
- public int getNumberOfFontsAsInt()
- {
+ public int getNumberOfFontsAsInt() {
return getNumberOfFonts();
}
@Override
- public Font getFontAt(int idx)
- {
+ public Font getFontAt(int idx) {
return _wb.getFontAt(idx);
}
* @return the new Cell Style object
*/
@Override
- public CellStyle createCellStyle()
- {
+ public CellStyle createCellStyle() {
return _wb.createCellStyle();
}
* @return count of cell styles
*/
@Override
- public int getNumCellStyles()
- {
+ public int getNumCellStyles() {
return _wb.getNumCellStyles();
}
* @return CellStyle object at the index
*/
@Override
- public CellStyle getCellStyleAt(int idx)
- {
+ public CellStyle getCellStyleAt(int idx) {
return _wb.getCellStyleAt(idx);
}
@Override
public void close() throws IOException {
// ensure that any lingering writer is closed
- for (SXSSFSheet sheet : _xFromSxHash.values())
- {
+ for (SXSSFSheet sheet : _xFromSxHash.values()) {
try {
SheetDataWriter _writer = sheet.getSheetDataWriter();
if (_writer != null) _writer.close();
* Calling this method will render the workbook unusable.
* @return true if all temporary files were deleted successfully.
*/
- public boolean dispose()
- {
+ public boolean dispose() {
boolean success = true;
- for (SXSSFSheet sheet : _sxFromXHash.keySet())
- {
+ for (SXSSFSheet sheet : _sxFromXHash.keySet()) {
try {
success = sheet.dispose() && success;
} catch (IOException e) {
* @return the total number of defined names in this workbook
*/
@Override
- public int getNumberOfNames()
- {
+ public int getNumberOfNames() {
return _wb.getNumberOfNames();
}
* @return the defined name with the specified name. <code>null</code> if not found.
*/
@Override
- public Name getName(String name)
- {
+ public Name getName(String name) {
return _wb.getName(name);
}
* @return all defined names
*/
@Override
- public List<? extends Name> getAllNames()
- {
+ public List<? extends Name> getAllNames() {
return _wb.getAllNames();
}
* @return new defined name object
*/
@Override
- public Name createName()
- {
+ public Name createName() {
return _wb.createName();
}
* @param name the name to remove
*/
@Override
- public void removeName(Name name)
- {
+ public void removeName(Name name) {
_wb.removeName(name);
}
* @param reference Valid name Reference for the Print Area
*/
@Override
- public void setPrintArea(int sheetIndex, String reference)
- {
+ public void setPrintArea(int sheetIndex, String reference) {
_wb.setPrintArea(sheetIndex,reference);
}
* @param endRow Row to end the printarea
*/
@Override
- public void setPrintArea(int sheetIndex, int startColumn, int endColumn, int startRow, int endRow)
- {
+ public void setPrintArea(int sheetIndex, int startColumn, int endColumn, int startRow, int endRow) {
_wb.setPrintArea(sheetIndex, startColumn, endColumn, startRow, endRow);
}
* @return String Null if no print area has been defined
*/
@Override
- public String getPrintArea(int sheetIndex)
- {
+ public String getPrintArea(int sheetIndex) {
return _wb.getPrintArea(sheetIndex);
}
* @param sheetIndex Zero-based sheet index (0 = First Sheet)
*/
@Override
- public void removePrintArea(int sheetIndex)
- {
+ public void removePrintArea(int sheetIndex) {
_wb.removePrintArea(sheetIndex);
}
* </p>
*/
@Override
- public MissingCellPolicy getMissingCellPolicy()
- {
+ public MissingCellPolicy getMissingCellPolicy() {
return _wb.getMissingCellPolicy();
}
* {@link MissingCellPolicy}
*/
@Override
- public void setMissingCellPolicy(MissingCellPolicy missingCellPolicy)
- {
+ public void setMissingCellPolicy(MissingCellPolicy missingCellPolicy) {
_wb.setMissingCellPolicy(missingCellPolicy);
}
* @return the DataFormat object
*/
@Override
- public DataFormat createDataFormat()
- {
+ public DataFormat createDataFormat() {
return _wb.createDataFormat();
}
* @see #PICTURE_TYPE_DIB
*/
@Override
- public int addPicture(byte[] pictureData, int format)
- {
+ public int addPicture(byte[] pictureData, int format) {
return _wb.addPicture(pictureData,format);
}
* @return the list of pictures (a list of {@link PictureData} objects.)
*/
@Override
- public List<? extends PictureData> getAllPictures()
- {
+ public List<? extends PictureData> getAllPictures() {
return _wb.getAllPictures();
}
@Override
@NotImplemented("XSSFWorkbook#isHidden is not implemented")
- public boolean isHidden()
- {
+ public boolean isHidden() {
return _wb.isHidden();
}
@Override
@NotImplemented("XSSFWorkbook#setHidden is not implemented")
- public void setHidden(boolean hiddenFlag)
- {
+ public void setHidden(boolean hiddenFlag) {
_wb.setHidden(hiddenFlag);
}
@Override
- public boolean isSheetHidden(int sheetIx)
- {
+ public boolean isSheetHidden(int sheetIx) {
return _wb.isSheetHidden(sheetIx);
}
@Override
- public boolean isSheetVeryHidden(int sheetIx)
- {
+ public boolean isSheetVeryHidden(int sheetIx) {
return _wb.isSheetVeryHidden(sheetIx);
}
}
@Override
- public void setSheetHidden(int sheetIx, boolean hidden)
- {
+ public void setSheetHidden(int sheetIx, boolean hidden) {
_wb.setSheetHidden(sheetIx,hidden);
}
* @param toolpack the toolpack to register
*/
@Override
- public void addToolPack(UDFFinder toolpack)
- {
+ public void addToolPack(UDFFinder toolpack) {
_wb.addToolPack(toolpack);
}
* @since 3.8
*/
@Override
- public void setForceFormulaRecalculation(boolean value){
+ public void setForceFormulaRecalculation(boolean value) {
_wb.setForceFormulaRecalculation(value);
}
* Whether Excel will be asked to recalculate all formulas when the workbook is opened.
*/
@Override
- public boolean getForceFormulaRecalculation(){
+ public boolean getForceFormulaRecalculation() {
return _wb.getForceFormulaRecalculation();
}