for (HSSFObjectData obj : workbook.getAllEmbeddedObjects()) {
//the OLE2 Class Name of the object
String oleName = obj.getOLE2ClassName();
- if (oleName.equals("Worksheet")) {
- DirectoryNode dn = (DirectoryNode) obj.getDirectory();
- HSSFWorkbook embeddedWorkbook = new HSSFWorkbook(dn, false);
- embeddedWorkbook.close();
- } else if (oleName.equals("Document")) {
- DirectoryNode dn = (DirectoryNode) obj.getDirectory();
- HWPFDocument embeddedWordDocument = new HWPFDocument(dn);
- embeddedWordDocument.close();
- } else if (oleName.equals("Presentation")) {
- DirectoryNode dn = (DirectoryNode) obj.getDirectory();
- SlideShow<?,?> embeddedSlieShow = new HSLFSlideShow(dn);
- embeddedSlieShow.close();
- } else {
- if(obj.hasDirectoryEntry()){
- // The DirectoryEntry is a DocumentNode. Examine its entries to find out what it is
+ switch (oleName) {
+ case "Worksheet": {
DirectoryNode dn = (DirectoryNode) obj.getDirectory();
- for (Entry entry : dn) {
- //System.out.println(oleName + "." + entry.getName());
- }
- } else {
- // There is no DirectoryEntry
- // Recover the object's data from the HSSFObjectData instance.
- byte[] objectData = obj.getObjectData();
+ HSSFWorkbook embeddedWorkbook = new HSSFWorkbook(dn, false);
+ embeddedWorkbook.close();
+ break;
+ }
+ case "Document": {
+ DirectoryNode dn = (DirectoryNode) obj.getDirectory();
+ HWPFDocument embeddedWordDocument = new HWPFDocument(dn);
+ embeddedWordDocument.close();
+ break;
+ }
+ case "Presentation": {
+ DirectoryNode dn = (DirectoryNode) obj.getDirectory();
+ SlideShow<?, ?> embeddedSlieShow = new HSLFSlideShow(dn);
+ embeddedSlieShow.close();
+ break;
}
+ default:
+ if (obj.hasDirectoryEntry()) {
+ // The DirectoryEntry is a DocumentNode. Examine its entries to find out what it is
+ DirectoryNode dn = (DirectoryNode) obj.getDirectory();
+ for (Entry entry : dn) {
+ //System.out.println(oleName + "." + entry.getName());
+ }
+ } else {
+ // There is no DirectoryEntry
+ // Recover the object's data from the HSSFObjectData instance.
+ byte[] objectData = obj.getObjectData();
+ }
+ break;
}
}
}
- public static void loadEmbedded(XSSFWorkbook workbook) throws IOException, InvalidFormatException, OpenXML4JException, XmlException {
+ public static void loadEmbedded(XSSFWorkbook workbook) throws IOException, InvalidFormatException,
+ OpenXML4JException, XmlException {
for (PackagePart pPart : workbook.getAllEmbeddedParts()) {
String contentType = pPart.getContentType();
- if (contentType.equals("application/vnd.ms-excel")) {
- // Excel Workbook - either binary or OpenXML
- try (InputStream stream = pPart.getInputStream()) {
- HSSFWorkbook embeddedWorkbook = new HSSFWorkbook(stream);
- embeddedWorkbook.close();
- }
- } else if (contentType.equals("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")) {
- // Excel Workbook - OpenXML file format
- try (InputStream stream = pPart.getInputStream()) {
- XSSFWorkbook embeddedWorkbook = new XSSFWorkbook(stream);
- embeddedWorkbook.close();
- }
- } else if (contentType.equals("application/msword")) {
- // Word Document - binary (OLE2CDF) file format
- try (InputStream stream = pPart.getInputStream()) {
- HWPFDocument document = new HWPFDocument(stream);
- document.close();
- }
- } else if (contentType.equals("application/vnd.openxmlformats-officedocument.wordprocessingml.document")) {
- // Word Document - OpenXML file format
- try (InputStream stream = pPart.getInputStream()) {
- XWPFDocument document = new XWPFDocument(stream);
- document.close();
- }
- } else if (contentType.equals("application/vnd.ms-powerpoint")) {
- // PowerPoint Document - binary file format
- try (InputStream stream = pPart.getInputStream()) {
- HSLFSlideShow slideShow = new HSLFSlideShow(stream);
- slideShow.close();
- }
- } else if (contentType.equals("application/vnd.openxmlformats-officedocument.presentationml.presentation")) {
- // PowerPoint Document - OpenXML file format
- try (InputStream stream = pPart.getInputStream()) {
- XMLSlideShow slideShow = new XMLSlideShow(stream);
- slideShow.close();
- }
- } else {
- // Any other type of embedded object.
- System.out.println("Unknown Embedded Document: " + contentType);
- try (InputStream inputStream = pPart.getInputStream()) {
+ switch (contentType) {
+ case "application/vnd.ms-excel":
+ // Excel Workbook - either binary or OpenXML
+ try (InputStream stream = pPart.getInputStream()) {
+ HSSFWorkbook embeddedWorkbook = new HSSFWorkbook(stream);
+ embeddedWorkbook.close();
+ }
+ break;
+ case "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet":
+ // Excel Workbook - OpenXML file format
+ try (InputStream stream = pPart.getInputStream()) {
+ XSSFWorkbook embeddedWorkbook = new XSSFWorkbook(stream);
+ embeddedWorkbook.close();
+ }
+ break;
+ case "application/msword":
+ // Word Document - binary (OLE2CDF) file format
+ try (InputStream stream = pPart.getInputStream()) {
+ HWPFDocument document = new HWPFDocument(stream);
+ document.close();
+ }
+ break;
+ case "application/vnd.openxmlformats-officedocument.wordprocessingml.document":
+ // Word Document - OpenXML file format
+ try (InputStream stream = pPart.getInputStream()) {
+ XWPFDocument document = new XWPFDocument(stream);
+ document.close();
+ }
+ break;
+ case "application/vnd.ms-powerpoint":
+ // PowerPoint Document - binary file format
+ try (InputStream stream = pPart.getInputStream()) {
+ HSLFSlideShow slideShow = new HSLFSlideShow(stream);
+ slideShow.close();
+ }
+ break;
+ case "application/vnd.openxmlformats-officedocument.presentationml.presentation":
+ // PowerPoint Document - OpenXML file format
+ try (InputStream stream = pPart.getInputStream()) {
+ XMLSlideShow slideShow = new XMLSlideShow(stream);
+ slideShow.close();
+ }
+ break;
+ default:
+ // Any other type of embedded object.
+ System.out.println("Unknown Embedded Document: " + contentType);
+ try (InputStream inputStream = pPart.getInputStream()) {
- }
+ }
+ break;
}
}
}
String contentType = pPart.getContentType();
try (InputStream is = pPart.getInputStream()) {
Closeable document;
- if (contentType.equals("application/vnd.ms-excel")) {
- // Excel Workbook - either binary or OpenXML
- document = new HSSFWorkbook(is);
- } else if (contentType.equals("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")) {
- // Excel Workbook - OpenXML file format
- document = new XSSFWorkbook(is);
- } else if (contentType.equals("application/msword")) {
- // Word Document - binary (OLE2CDF) file format
- document = new HWPFDocument(is);
- } else if (contentType.equals("application/vnd.openxmlformats-officedocument.wordprocessingml.document")) {
- // Word Document - OpenXML file format
- document = new XWPFDocument(is);
- } else if (contentType.equals("application/vnd.ms-powerpoint")) {
- // PowerPoint Document - binary file format
- document = new HSLFSlideShow(is);
- } else if (contentType.equals("application/vnd.openxmlformats-officedocument.presentationml.presentation")) {
- // PowerPoint Document - OpenXML file format
- document = new XMLSlideShow(is);
- } else {
- // Any other type of embedded object.
- document = is;
+ switch (contentType) {
+ case "application/vnd.ms-excel":
+ // Excel Workbook - either binary or OpenXML
+ document = new HSSFWorkbook(is);
+ break;
+ case "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet":
+ // Excel Workbook - OpenXML file format
+ document = new XSSFWorkbook(is);
+ break;
+ case "application/msword":
+ // Word Document - binary (OLE2CDF) file format
+ document = new HWPFDocument(is);
+ break;
+ case "application/vnd.openxmlformats-officedocument.wordprocessingml.document":
+ // Word Document - OpenXML file format
+ document = new XWPFDocument(is);
+ break;
+ case "application/vnd.ms-powerpoint":
+ // PowerPoint Document - binary file format
+ document = new HSLFSlideShow(is);
+ break;
+ case "application/vnd.openxmlformats-officedocument.presentationml.presentation":
+ // PowerPoint Document - OpenXML file format
+ document = new XMLSlideShow(is);
+ break;
+ default:
+ // Any other type of embedded object.
+ document = is;
+ break;
}
document.close();
}
public static String getContentTypeFromFileExtension(String filename) {
String extension = filename.substring(filename.lastIndexOf('.') + 1)
.toLowerCase(Locale.ROOT);
- if (extension.equals(EXTENSION_JPG_1)
- || extension.equals(EXTENSION_JPG_2))
- return IMAGE_JPEG;
- else if (extension.equals(EXTENSION_GIF))
- return IMAGE_GIF;
- else if (extension.equals(EXTENSION_PICT))
- return IMAGE_PICT;
- else if (extension.equals(EXTENSION_PNG))
- return IMAGE_PNG;
- else if (extension.equals(EXTENSION_TIFF))
- return IMAGE_TIFF;
- else if (extension.equals(EXTENSION_XML))
- return XML;
- else
- return null;
+ switch (extension) {
+ case EXTENSION_JPG_1:
+ case EXTENSION_JPG_2:
+ return IMAGE_JPEG;
+ case EXTENSION_GIF:
+ return IMAGE_GIF;
+ case EXTENSION_PICT:
+ return IMAGE_PICT;
+ case EXTENSION_PNG:
+ return IMAGE_PNG;
+ case EXTENSION_TIFF:
+ return IMAGE_TIFF;
+ case EXTENSION_XML:
+ return XML;
+ default:
+ return null;
+ }
}
}
for (CellType cell : row.getCellArray()) {
String cellName = cell.getN();
- if (cellName.equals("X")) {
- x = XDGFCell.parseDoubleValue(cell);
- } else if (cellName.equals("Y")) {
- y = XDGFCell.parseDoubleValue(cell);
- } else if (cellName.equals("A")) {
- a = XDGFCell.parseDoubleValue(cell);
- } else {
- throw new POIXMLException("Invalid cell '" + cellName
- + "' in ArcTo row");
+ switch (cellName) {
+ case "X":
+ x = XDGFCell.parseDoubleValue(cell);
+ break;
+ case "Y":
+ y = XDGFCell.parseDoubleValue(cell);
+ break;
+ case "A":
+ a = XDGFCell.parseDoubleValue(cell);
+ break;
+ default:
+ throw new POIXMLException("Invalid cell '" + cellName
+ + "' in ArcTo row");
}
}
}
for (CellType cell : row.getCellArray()) {
String cellName = cell.getN();
- if (cellName.equals("X")) {
- x = XDGFCell.parseDoubleValue(cell);
- } else if (cellName.equals("Y")) {
- y = XDGFCell.parseDoubleValue(cell);
- } else if (cellName.equals("A")) {
- a = XDGFCell.parseDoubleValue(cell);
- } else if (cellName.equals("B")) {
- b = XDGFCell.parseDoubleValue(cell);
- } else if (cellName.equals("C")) {
- c = XDGFCell.parseDoubleValue(cell);
- } else if (cellName.equals("D")) {
- d = XDGFCell.parseDoubleValue(cell);
- } else {
- throw new POIXMLException("Invalid cell '" + cellName
- + "' in Ellipse row");
+ switch (cellName) {
+ case "X":
+ x = XDGFCell.parseDoubleValue(cell);
+ break;
+ case "Y":
+ y = XDGFCell.parseDoubleValue(cell);
+ break;
+ case "A":
+ a = XDGFCell.parseDoubleValue(cell);
+ break;
+ case "B":
+ b = XDGFCell.parseDoubleValue(cell);
+ break;
+ case "C":
+ c = XDGFCell.parseDoubleValue(cell);
+ break;
+ case "D":
+ d = XDGFCell.parseDoubleValue(cell);
+ break;
+ default:
+ throw new POIXMLException("Invalid cell '" + cellName
+ + "' in Ellipse row");
}
}
}
for (CellType cell : row.getCellArray()) {
String cellName = cell.getN();
- if (cellName.equals("X")) {
- x = XDGFCell.parseDoubleValue(cell);
- } else if (cellName.equals("Y")) {
- y = XDGFCell.parseDoubleValue(cell);
- } else if (cellName.equals("A")) {
- a = XDGFCell.parseDoubleValue(cell);
- } else if (cellName.equals("B")) {
- b = XDGFCell.parseDoubleValue(cell);
- } else if (cellName.equals("C")) {
- c = XDGFCell.parseDoubleValue(cell);
- } else if (cellName.equals("D")) {
- d = XDGFCell.parseDoubleValue(cell);
- } else {
- throw new POIXMLException("Invalid cell '" + cellName
- + "' in EllipticalArcTo row");
+ switch (cellName) {
+ case "X":
+ x = XDGFCell.parseDoubleValue(cell);
+ break;
+ case "Y":
+ y = XDGFCell.parseDoubleValue(cell);
+ break;
+ case "A":
+ a = XDGFCell.parseDoubleValue(cell);
+ break;
+ case "B":
+ b = XDGFCell.parseDoubleValue(cell);
+ break;
+ case "C":
+ c = XDGFCell.parseDoubleValue(cell);
+ break;
+ case "D":
+ d = XDGFCell.parseDoubleValue(cell);
+ break;
+ default:
+ throw new POIXMLException("Invalid cell '" + cellName
+ + "' in EllipticalArcTo row");
}
}
}
for (CellType cell : row.getCellArray()) {
String cellName = cell.getN();
- if (cellName.equals("X")) {
- x = XDGFCell.parseDoubleValue(cell);
- } else if (cellName.equals("Y")) {
- y = XDGFCell.parseDoubleValue(cell);
- } else if (cellName.equals("A")) {
- a = XDGFCell.parseDoubleValue(cell);
- } else if (cellName.equals("B")) {
- b = XDGFCell.parseDoubleValue(cell);
- } else {
- throw new POIXMLException("Invalid cell '" + cellName
- + "' in InfiniteLine row");
+ switch (cellName) {
+ case "X":
+ x = XDGFCell.parseDoubleValue(cell);
+ break;
+ case "Y":
+ y = XDGFCell.parseDoubleValue(cell);
+ break;
+ case "A":
+ a = XDGFCell.parseDoubleValue(cell);
+ break;
+ case "B":
+ b = XDGFCell.parseDoubleValue(cell);
+ break;
+ default:
+ throw new POIXMLException("Invalid cell '" + cellName
+ + "' in InfiniteLine row");
}
}
}
for (CellType cell : row.getCellArray()) {
String cellName = cell.getN();
- if (cellName.equals("X")) {
- x = XDGFCell.parseDoubleValue(cell);
- } else if (cellName.equals("Y")) {
- y = XDGFCell.parseDoubleValue(cell);
- } else if (cellName.equals("A")) {
- a = XDGFCell.parseDoubleValue(cell);
- } else if (cellName.equals("B")) {
- b = XDGFCell.parseDoubleValue(cell);
- } else if (cellName.equals("C")) {
- c = XDGFCell.parseDoubleValue(cell);
- } else if (cellName.equals("D")) {
- d = XDGFCell.parseDoubleValue(cell);
- } else if (cellName.equals("E")) {
- e = cell.getV();
- } else {
- throw new POIXMLException("Invalid cell '" + cellName
- + "' in NURBS row");
+ switch (cellName) {
+ case "X":
+ x = XDGFCell.parseDoubleValue(cell);
+ break;
+ case "Y":
+ y = XDGFCell.parseDoubleValue(cell);
+ break;
+ case "A":
+ a = XDGFCell.parseDoubleValue(cell);
+ break;
+ case "B":
+ b = XDGFCell.parseDoubleValue(cell);
+ break;
+ case "C":
+ c = XDGFCell.parseDoubleValue(cell);
+ break;
+ case "D":
+ d = XDGFCell.parseDoubleValue(cell);
+ break;
+ case "E":
+ e = cell.getV();
+ break;
+ default:
+ throw new POIXMLException("Invalid cell '" + cellName
+ + "' in NURBS row");
}
}
}
for (CellType cell : row.getCellArray()) {
String cellName = cell.getN();
- if (cellName.equals("X")) {
- x = XDGFCell.parseDoubleValue(cell);
- } else if (cellName.equals("Y")) {
- y = XDGFCell.parseDoubleValue(cell);
- } else if (cellName.equals("A")) {
- a = cell.getV();
- } else {
- throw new POIXMLException("Invalid cell '" + cellName
- + "' in ArcTo row");
+ switch (cellName) {
+ case "X":
+ x = XDGFCell.parseDoubleValue(cell);
+ break;
+ case "Y":
+ y = XDGFCell.parseDoubleValue(cell);
+ break;
+ case "A":
+ a = cell.getV();
+ break;
+ default:
+ throw new POIXMLException("Invalid cell '" + cellName
+ + "' in ArcTo row");
}
}
}
for (CellType cell : row.getCellArray()) {
String cellName = cell.getN();
- if (cellName.equals("X")) {
- x = XDGFCell.parseDoubleValue(cell);
- } else if (cellName.equals("Y")) {
- y = XDGFCell.parseDoubleValue(cell);
- } else if (cellName.equals("A")) {
- a = XDGFCell.parseDoubleValue(cell);
- } else if (cellName.equals("B")) {
- b = XDGFCell.parseDoubleValue(cell);
- } else if (cellName.equals("C")) {
- c = XDGFCell.parseDoubleValue(cell);
- } else if (cellName.equals("D")) {
- d = XDGFCell.parseDoubleValue(cell);
- } else {
- throw new POIXMLException("Invalid cell '" + cellName
- + "' in RelCubBezTo row");
+ switch (cellName) {
+ case "X":
+ x = XDGFCell.parseDoubleValue(cell);
+ break;
+ case "Y":
+ y = XDGFCell.parseDoubleValue(cell);
+ break;
+ case "A":
+ a = XDGFCell.parseDoubleValue(cell);
+ break;
+ case "B":
+ b = XDGFCell.parseDoubleValue(cell);
+ break;
+ case "C":
+ c = XDGFCell.parseDoubleValue(cell);
+ break;
+ case "D":
+ d = XDGFCell.parseDoubleValue(cell);
+ break;
+ default:
+ throw new POIXMLException("Invalid cell '" + cellName
+ + "' in RelCubBezTo row");
}
}
}
for (CellType cell : row.getCellArray()) {
String cellName = cell.getN();
- if (cellName.equals("X")) {
- x = XDGFCell.parseDoubleValue(cell);
- } else if (cellName.equals("Y")) {
- y = XDGFCell.parseDoubleValue(cell);
- } else if (cellName.equals("A")) {
- a = XDGFCell.parseDoubleValue(cell);
- } else if (cellName.equals("B")) {
- b = XDGFCell.parseDoubleValue(cell);
- } else if (cellName.equals("C")) {
- c = XDGFCell.parseDoubleValue(cell);
- } else if (cellName.equals("D")) {
- d = XDGFCell.parseDoubleValue(cell);
- } else {
- throw new POIXMLException("Invalid cell '" + cellName
- + "' in RelEllipticalArcTo row");
+ switch (cellName) {
+ case "X":
+ x = XDGFCell.parseDoubleValue(cell);
+ break;
+ case "Y":
+ y = XDGFCell.parseDoubleValue(cell);
+ break;
+ case "A":
+ a = XDGFCell.parseDoubleValue(cell);
+ break;
+ case "B":
+ b = XDGFCell.parseDoubleValue(cell);
+ break;
+ case "C":
+ c = XDGFCell.parseDoubleValue(cell);
+ break;
+ case "D":
+ d = XDGFCell.parseDoubleValue(cell);
+ break;
+ default:
+ throw new POIXMLException("Invalid cell '" + cellName
+ + "' in RelEllipticalArcTo row");
}
}
}
for (CellType cell : row.getCellArray()) {
String cellName = cell.getN();
- if (cellName.equals("X")) {
- x = XDGFCell.parseDoubleValue(cell);
- } else if (cellName.equals("Y")) {
- y = XDGFCell.parseDoubleValue(cell);
- } else if (cellName.equals("A")) {
- a = XDGFCell.parseDoubleValue(cell);
- } else if (cellName.equals("B")) {
- b = XDGFCell.parseDoubleValue(cell);
- } else {
- throw new POIXMLException("Invalid cell '" + cellName
- + "' in RelQuadBezTo row");
+ switch (cellName) {
+ case "X":
+ x = XDGFCell.parseDoubleValue(cell);
+ break;
+ case "Y":
+ y = XDGFCell.parseDoubleValue(cell);
+ break;
+ case "A":
+ a = XDGFCell.parseDoubleValue(cell);
+ break;
+ case "B":
+ b = XDGFCell.parseDoubleValue(cell);
+ break;
+ default:
+ throw new POIXMLException("Invalid cell '" + cellName
+ + "' in RelQuadBezTo row");
}
}
}
for (CellType cell : row.getCellArray()) {
String cellName = cell.getN();
- if (cellName.equals("X")) {
- x = XDGFCell.parseDoubleValue(cell);
- } else if (cellName.equals("Y")) {
- y = XDGFCell.parseDoubleValue(cell);
- } else if (cellName.equals("A")) {
- a = XDGFCell.parseDoubleValue(cell);
- } else {
- throw new POIXMLException("Invalid cell '" + cellName
- + "' in SplineKnot row");
+ switch (cellName) {
+ case "X":
+ x = XDGFCell.parseDoubleValue(cell);
+ break;
+ case "Y":
+ y = XDGFCell.parseDoubleValue(cell);
+ break;
+ case "A":
+ a = XDGFCell.parseDoubleValue(cell);
+ break;
+ default:
+ throw new POIXMLException("Invalid cell '" + cellName
+ + "' in SplineKnot row");
}
}
}
for (CellType cell : row.getCellArray()) {
String cellName = cell.getN();
- if (cellName.equals("X")) {
- x = XDGFCell.parseDoubleValue(cell);
- } else if (cellName.equals("Y")) {
- y = XDGFCell.parseDoubleValue(cell);
- } else if (cellName.equals("A")) {
- a = XDGFCell.parseDoubleValue(cell);
- } else if (cellName.equals("B")) {
- b = XDGFCell.parseDoubleValue(cell);
- } else if (cellName.equals("C")) {
- c = XDGFCell.parseDoubleValue(cell);
- } else if (cellName.equals("D")) {
- d = XDGFCell.parseIntegerValue(cell);
- } else {
- throw new POIXMLException("Invalid cell '" + cellName
- + "' in SplineStart row");
+ switch (cellName) {
+ case "X":
+ x = XDGFCell.parseDoubleValue(cell);
+ break;
+ case "Y":
+ y = XDGFCell.parseDoubleValue(cell);
+ break;
+ case "A":
+ a = XDGFCell.parseDoubleValue(cell);
+ break;
+ case "B":
+ b = XDGFCell.parseDoubleValue(cell);
+ break;
+ case "C":
+ c = XDGFCell.parseDoubleValue(cell);
+ break;
+ case "D":
+ d = XDGFCell.parseIntegerValue(cell);
+ break;
+ default:
+ throw new POIXMLException("Invalid cell '" + cellName
+ + "' in SplineStart row");
}
}
}
byte numBits = 0;
int mask = (int) Long.parseLong( bitMask.substring( 2 ), 16 );
- if ( parentType.equals( "byte" ) )
- parentSize = 8;
- else if ( parentType.equals( "short" ) )
- parentSize = 16;
- else if ( parentType.equals( "int" ) )
- parentSize = 32;
+ switch (parentType) {
+ case "byte":
+ parentSize = 8;
+ break;
+ case "short":
+ parentSize = 16;
+ break;
+ case "int":
+ parentSize = 32;
+ break;
+ }
for ( int x = 0; x < parentSize; x++ )
{