Bug 59002 - RecordFormatException: Expected size 18 but got (0) when opening workbook
Summary: RecordFormatException: Expected size 18 but got (0) when opening workbook
Status: RESOLVED INVALID
Alias: None
Product: POI
Classification: Unclassified
Component: HSSF (show other bugs)
Version: 3.13-FINAL
Hardware: PC All
: P2 critical (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-02-14 18:24 UTC by Sanjay saini
Modified: 2016-03-29 15:06 UTC (History)
1 user (show)



Attachments
xls file in zip format (I have used that file for making HSSFWorkbook instance. (363.52 KB, application/x-zip-compressed)
2016-02-14 18:24 UTC, Sanjay saini
Details
Code Used for reading or writing (17.10 KB, text/plain)
2016-02-14 18:26 UTC, Sanjay saini
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Sanjay saini 2016-02-14 18:24:34 UTC
Created attachment 33551 [details]
xls file in zip format (I have used that file for making HSSFWorkbook instance.

Exception Occured inside transFormXLS2XLSX :: file Name :: D:/t.xls:: reason ::Expected size 18 but got (0)
org.apache.poi.hssf.record.RecordFormatException: Expected size 18 but got (0)
	at org.apache.poi.hssf.record.CommonObjectDataSubRecord.<init>(CommonObjectDataSubRecord.java:86)
	at org.apache.poi.hssf.record.SubRecord.createSubRecord(SubRecord.java:49)
	at org.apache.poi.hssf.record.ObjRecord.<init>(ObjRecord.java:93)
	at sun.reflect.GeneratedConstructorAccessor9.newInstance(Unknown Source)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
	at java.lang.reflect.Constructor.newInstance(Unknown Source)
	at org.apache.poi.hssf.record.RecordFactory$ReflectionConstructorRecordCreator.create(RecordFactory.java:84)
	at org.apache.poi.hssf.record.RecordFactory.createSingleRecord(RecordFactory.java:334)
	at org.apache.poi.hssf.record.RecordFactoryInputStream.readNextRecord(RecordFactoryInputStream.java:308)
	at org.apache.poi.hssf.record.RecordFactoryInputStream.nextRecord(RecordFactoryInputStream.java:274)
	at org.apache.poi.hssf.record.RecordFactory.createRecords(RecordFactory.java:478)
	at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:344)
	at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:401)
	at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:382)
	at readexcel.Conversion.convertXLS2XLSX(Conversion.java:89)
	at readexcel.Conversion.main(Conversion.java:69)



I have trying to convert xls file to xlsx.

wbIn = new HSSFWorkbook(inputStream); // main culprit of the above exception

Code ::::::::::::::::::::::


package readexcel;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.HashMap;


import java.util.Iterator;
import java.util.List;
import java.util.Map;

import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.validator.GenericValidator;
import org.apache.poi.POIOLE2TextExtractor;
import org.apache.poi.POITextExtractor;
import org.apache.poi.extractor.ExtractorFactory;
import org.apache.poi.hssf.record.RecordFactory;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFClientAnchor;
import org.apache.poi.hssf.usermodel.HSSFPalette;
import org.apache.poi.hssf.usermodel.HSSFPatriarch;
import org.apache.poi.hssf.usermodel.HSSFPicture;
import org.apache.poi.hssf.usermodel.HSSFPictureData;
import org.apache.poi.hssf.usermodel.HSSFShape;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.util.HSSFColor;
import org.apache.poi.hssf.util.PaneInformation;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.ClientAnchor;
import org.apache.poi.ss.usermodel.CreationHelper;
import org.apache.poi.ss.usermodel.DataFormat;
import org.apache.poi.ss.usermodel.Drawing;
import org.apache.poi.ss.usermodel.Font;
import org.apache.poi.ss.usermodel.Footer;
import org.apache.poi.ss.usermodel.Header;
import org.apache.poi.ss.usermodel.PrintSetup;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.WorkbookFactory;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.xssf.usermodel.XSSFCellStyle;
import org.apache.poi.xssf.usermodel.XSSFClientAnchor;
import org.apache.poi.xssf.usermodel.XSSFColor;
import org.apache.poi.xssf.usermodel.XSSFDrawing;
import org.apache.poi.xssf.usermodel.XSSFPicture;
import org.apache.poi.xssf.usermodel.XSSFPictureData;
import org.apache.poi.xssf.usermodel.XSSFShape;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTMarker;
import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTTwoCellAnchor;


public class Conversion {
	//TODO
	private static final int ZOOM_FACTOR_NUMERATOR = 1;
	private static final int ZOOM_FACTOR_DENOMINATOR = 1;


	public static void main(String args[]){
		new Conversion().convertXLS2XLSX();
	}

	//private transient static Log log = LogFactory.getLog(FileConversionUtil.class);


	//public String convertXLS2XLSX(InputStream inputStream,String xlsFilePath){
	public String convertXLS2XLSX(){
		Map cellStyleMap = new HashMap();
		String xlsFilePath ="D:/DD.xls";
		System.out.println("::::"+xlsFilePath);
		String xlsxFilePath = null;
		InputStream inputStream = null;
		Workbook wbIn = null;
		File xlsxFile= null;
		Workbook wbOut = null;
		OutputStream out = null;
		try {

			inputStream = new BufferedInputStream(new FileInputStream(xlsFilePath));
			wbIn = new HSSFWorkbook(inputStream);
			if(GenericValidator.isBlankOrNull(xlsFilePath)&&inputStream==null)
				return null;
			else
				xlsxFilePath = xlsFilePath.substring(0,xlsFilePath.lastIndexOf('.'))+".xlsx";
			wbIn = new HSSFWorkbook(inputStream);
			xlsxFile = new File(xlsxFilePath);
			if (xlsxFile.exists())
				xlsxFile.delete();
			wbOut = new XSSFWorkbook();
			Map fontMap  = createFontForXLSXWorkSheet(wbOut,wbIn);
			int sheetCnt = wbIn.getNumberOfSheets();

			for (int i = 0; i < sheetCnt; i++) {
				Sheet sIn = wbIn.getSheetAt(i);
				Sheet sOut = wbOut.createSheet(sIn.getSheetName());
				copySheetProperties(sOut,sIn);
				Iterator<Row> rowIt = sIn.rowIterator();
				while (rowIt.hasNext()) {
					Row rowIn = rowIt.next();
					Row rowOut = sOut.createRow(rowIn.getRowNum());
					copyRowProperties(rowOut,rowIn,fontMap,cellStyleMap);
				}
			}
			out = new BufferedOutputStream(new FileOutputStream(xlsxFile));
			wbOut.write(out);
		}catch(Exception ex){
			System.out.println("Exception Occured inside transFormXLS2XLSX :: file Name :: "+xlsFilePath + ":: reason ::"+ ex.getMessage());
			ex.printStackTrace();
			xlsxFilePath =null;
		}finally {
			try{
				if(wbOut!=null)
					wbOut.close();
				if(wbIn!=null)
					wbIn.close();
				if(out!=null)
					out.close();
				if(inputStream!=null)
					inputStream.close();
			}catch(Exception ex){
				ex.printStackTrace();
				xlsxFilePath =null;
			}
		}
		return xlsxFilePath;
	}

	public void copySheetProperties(Sheet sOut,Sheet sIn){
		sOut.setZoom(ZOOM_FACTOR_NUMERATOR,ZOOM_FACTOR_DENOMINATOR);//set 100% zoom on sheet
		List<CellRangeAddress>cellRangeAddresssList =  sIn.getMergedRegions();
		if(cellRangeAddresssList!=null){
			for(int i=0;i<cellRangeAddresssList.size();i++){
				CellRangeAddress copyCellRegion  = cellRangeAddresssList.get(i);
				int firstRow = copyCellRegion.getFirstRow();
				int lasRow = copyCellRegion.getLastRow();
				int firstColumn = copyCellRegion.getFirstColumn();
				int lastColumn =copyCellRegion.getLastColumn();
				if(firstRow<=lasRow && firstColumn <= lastColumn){
					CellRangeAddress cellRegion = new CellRangeAddress(copyCellRegion.getFirstRow(),copyCellRegion.getLastRow(),copyCellRegion.getFirstColumn(),copyCellRegion.getLastColumn());
					sOut.addMergedRegion(cellRegion);
				}
			}
		}
		PaneInformation paneInformation = sIn.getPaneInformation();
		if(paneInformation!=null){
			if(paneInformation.isFreezePane()){
				sOut.createFreezePane(paneInformation.getVerticalSplitLeftColumn(),paneInformation.getHorizontalSplitTopRow());
			}else{
				sOut.createSplitPane(paneInformation.getHorizontalSplitPosition(), paneInformation.getVerticalSplitPosition(), paneInformation.getVerticalSplitLeftColumn(),paneInformation.getHorizontalSplitTopRow(),paneInformation.getActivePane());
			}
		}
		copyPictures(sOut,sIn);
		sOut.setVerticallyCenter(sIn.getVerticallyCenter());
		sOut.setHorizontallyCenter(sIn.getHorizontallyCenter());
		sOut.setDisplayRowColHeadings(sIn.isDisplayRowColHeadings());
		sOut.setDisplayFormulas(sIn.isDisplayFormulas());
		sOut.setDisplayZeros(sIn.isDisplayZeros());
		sOut.setRightToLeft(sIn.isRightToLeft());
		int [] rowBreaks = sIn.getRowBreaks();
		int [] colBreaks = sIn.getColumnBreaks();
		if(rowBreaks!=null){
			for(int row : rowBreaks){
				sOut.setRowBreak(row);
			}
		}
		if(colBreaks!=null){
			for(int column : colBreaks){
				sOut.setColumnBreak(column);
			}
		}
		sOut.setAutobreaks(sIn.getAutobreaks());
		sOut.setDefaultRowHeight(sIn.getDefaultRowHeight());
		sOut.setDefaultRowHeightInPoints(sIn.getDefaultRowHeightInPoints());
		sOut.setDefaultColumnWidth(sIn.getDefaultColumnWidth());
		sOut.setRowSumsRight(sIn.getRowSumsRight());
		sOut.setRowSumsBelow(sIn.getRowSumsBelow());
		sOut.setDisplayGuts(sIn.getDisplayGuts());
		sOut.setDisplayGridlines(sIn.isDisplayGridlines());
		sOut.setRepeatingColumns(sIn.getRepeatingColumns());
		sOut.setSelected(sIn.isSelected());
		sOut.setMargin(Sheet.LeftMargin,sIn.getMargin(Sheet.LeftMargin));
		sOut.setMargin(Sheet.RightMargin,sIn.getMargin(Sheet.RightMargin));
		sOut.setMargin(Sheet.TopMargin,sIn.getMargin(Sheet.TopMargin));
		sOut.setMargin(Sheet.BottomMargin,sIn.getMargin(Sheet.BottomMargin));
		PrintSetup sInPrintSetup = sIn.getPrintSetup();
		PrintSetup sOutPrintSetup = sOut.getPrintSetup();
		sOutPrintSetup.setPaperSize(sInPrintSetup.getPaperSize());
		if(sInPrintSetup.getScale()>10&&sInPrintSetup.getScale()<400)
			sOutPrintSetup.setScale(sInPrintSetup.getScale());
		sOutPrintSetup.setPageStart(sInPrintSetup.getPageStart());
		sOutPrintSetup.setFitWidth(sInPrintSetup.getFitWidth());
		sOutPrintSetup.setFitHeight(sInPrintSetup.getFitHeight());
		sOutPrintSetup.setLeftToRight(sInPrintSetup.getLeftToRight());
		sOutPrintSetup.setLandscape(sInPrintSetup.getLandscape());
		sOutPrintSetup.setValidSettings(sInPrintSetup.getValidSettings());
		sOutPrintSetup.setNoColor(sInPrintSetup.getNoColor());
		sOutPrintSetup.setDraft(sInPrintSetup.getDraft());
		sOutPrintSetup.setNotes(sInPrintSetup.getNotes());
		sOutPrintSetup.setNoOrientation(sInPrintSetup.getNoOrientation());
		sOutPrintSetup.setUsePage(sInPrintSetup.getUsePage());
		sOutPrintSetup.setHResolution(sInPrintSetup.getHResolution());
		sOutPrintSetup.setVResolution(sInPrintSetup.getVResolution());
		sOutPrintSetup.setHeaderMargin(sInPrintSetup.getHeaderMargin());
		sOutPrintSetup.setFooterMargin(sInPrintSetup.getFooterMargin());
		sOutPrintSetup.setCopies(sInPrintSetup.getCopies());

		Header sInHeader = sIn.getHeader();
		Header sOutHeader = sOut.getHeader();
		sOutHeader.setCenter(sInHeader.getCenter());
		sOutHeader.setLeft(sInHeader.getLeft());
		sOutHeader.setRight(sInHeader.getRight());

		Footer sInFooter = sIn.getFooter();
		Footer sOutFooter = sOut.getFooter();
		sOutFooter.setCenter(sInFooter.getCenter());
		sOutFooter.setLeft(sInFooter.getLeft());
		sOutFooter.setRight(sInFooter.getRight());
	}

	public void copyRowProperties(Row rowOut,Row rowIn,Map fontMap,Map cellStyleMap){
		rowOut.setRowStyle(rowIn.getRowStyle());
		rowOut.setRowNum(rowIn.getRowNum());
		rowOut.setHeight(rowIn.getHeight());
		rowOut.setHeightInPoints(rowIn.getHeightInPoints());
		rowOut.setZeroHeight(rowIn.getZeroHeight());
		Iterator<Cell> cellIt = rowIn.cellIterator();
		while (cellIt.hasNext()) {
			Cell cellIn = cellIt.next();
			Cell cellOut = rowOut.createCell(cellIn.getColumnIndex(), cellIn.getCellType());
			rowOut.getSheet().setColumnWidth(cellOut.getColumnIndex(),rowIn.getSheet().getColumnWidth(cellIn.getColumnIndex()));
			copyCellProperties(cellOut,cellIn,fontMap,cellStyleMap);
		}

	}

	public void copyCellProperties(Cell cellOut,Cell cellIn,Map fontMap,Map cellStyleMap){

		Workbook wbOut = cellOut.getSheet().getWorkbook();
		HSSFPalette hssfPalette = ((HSSFWorkbook)cellIn.getSheet().getWorkbook()).getCustomPalette();
		switch (cellIn.getCellType()) {
		case Cell.CELL_TYPE_BLANK:
			break;

		case Cell.CELL_TYPE_BOOLEAN:
			cellOut.setCellValue(cellIn.getBooleanCellValue());
			break;

		case Cell.CELL_TYPE_ERROR:
			cellOut.setCellValue(cellIn.getErrorCellValue());
			break;

		case Cell.CELL_TYPE_FORMULA:
			cellOut.setCellFormula(cellIn.getCellFormula());
			break;

		case Cell.CELL_TYPE_NUMERIC:
			cellOut.setCellValue(cellIn.getNumericCellValue());
			break;

		case Cell.CELL_TYPE_STRING:
			cellOut.setCellValue(cellIn.getStringCellValue());
			break;
		}
		HSSFCellStyle styleIn = (HSSFCellStyle) cellIn.getCellStyle();
		XSSFCellStyle styleOut = null;
		if(cellStyleMap.get(styleIn.getIndex())!=null){
			styleOut = (XSSFCellStyle)cellStyleMap.get(styleIn.getIndex());
		}
		else{
			styleOut = (XSSFCellStyle) wbOut.createCellStyle();
			styleOut.setAlignment(styleIn.getAlignment());
			short fontIndex =  styleIn.getFontIndex();
			Font font = (Font)fontMap.get(fontIndex);
			if(font==null){
				font = wbOut.createFont();
				font.setColor(HSSFColor.BLACK.index);
				fontMap.put(font.getIndex(),font);
			}
			DataFormat format = wbOut.createDataFormat();
			styleOut.setDataFormat(format.getFormat(styleIn.getDataFormatString()));
			HSSFColor forgroundColor = (HSSFColor) styleIn.getFillForegroundColorColor();
			if(forgroundColor!=null){
				short [] foregroundColorValues = forgroundColor.getTriplet();
				styleOut.setFillForegroundColor(new XSSFColor(new java.awt.Color(foregroundColorValues[0], foregroundColorValues[1], foregroundColorValues[2])));
				styleOut.setFillPattern(styleIn.getFillPattern());
			}
			styleOut.setFillPattern(styleIn.getFillPattern());
			styleOut.setBorderBottom(styleIn.getBorderBottom());
			styleOut.setBorderLeft(styleIn.getBorderLeft());
			styleOut.setBorderRight(styleIn.getBorderRight());
			styleOut.setBorderTop(styleIn.getBorderTop());
			HSSFColor bottom =  hssfPalette.getColor(styleIn.getBottomBorderColor());
			if(bottom!=null){
				short [] bottomColorArray = bottom.getTriplet();
				styleOut.setBottomBorderColor(new XSSFColor(new java.awt.Color(bottomColorArray[0], bottomColorArray[1], bottomColorArray[2])));
			}
			HSSFColor top =  hssfPalette.getColor(styleIn.getTopBorderColor());
			if(top!=null){
				short []  topColorArray =top.getTriplet();
				styleOut.setTopBorderColor(new XSSFColor(new java.awt.Color(topColorArray[0],topColorArray[1],topColorArray[2])));
			}
			HSSFColor left =  hssfPalette.getColor(styleIn.getLeftBorderColor());
			if(left!=null){
				short [] leftColorArray = left.getTriplet();
				styleOut.setLeftBorderColor(new XSSFColor(new java.awt.Color(leftColorArray[0],leftColorArray[1],leftColorArray[2])));
			}
			HSSFColor right =  hssfPalette.getColor(styleIn.getRightBorderColor());
			if(right!=null){
				short [] rightColorArray= right.getTriplet();
				styleOut.setRightBorderColor(new XSSFColor(new java.awt.Color(rightColorArray[0],rightColorArray[1],rightColorArray[2])));
			}
			styleOut.setVerticalAlignment(styleIn.getVerticalAlignment());
			styleOut.setHidden(styleIn.getHidden());
			styleOut.setIndention(styleIn.getIndention());
			styleOut.setLocked(styleIn.getLocked());
			styleOut.setRotation(styleIn.getRotation());
			styleOut.setShrinkToFit(styleIn.getShrinkToFit());
			styleOut.setVerticalAlignment(styleIn.getVerticalAlignment());
			styleOut.setWrapText(styleIn.getWrapText());
			styleOut.setFont(font);
			cellOut.setCellComment(cellIn.getCellComment());
			cellStyleMap.put(styleIn.getIndex(),styleOut);
		}
		cellOut.setCellStyle(styleOut);
	}


	private void copyPictures(Sheet sOut, Sheet sIn) {
		try{
			if(sOut!=null && sIn!=null){
				Drawing drawingOld = sIn.createDrawingPatriarch();
				Drawing drawingNew = sOut.createDrawingPatriarch();
				CreationHelper helper = sOut.getWorkbook().getCreationHelper();

				if (drawingOld instanceof HSSFPatriarch) {
					List<HSSFShape> shapes = ((HSSFPatriarch) drawingOld).getChildren();
					for (int i = 0; i < shapes.size(); i++) {
						if (shapes.get(i) instanceof HSSFPicture) {
							HSSFPicture pic = (HSSFPicture) shapes.get(i);
							HSSFPictureData picdata = pic.getPictureData();
							int pictureIndex = sOut.getWorkbook().addPicture(picdata.getData(), picdata.getFormat());
							ClientAnchor anchor = null;
							if (pic.getAnchor() != null) {
								anchor = helper.createClientAnchor();
								anchor.setDx1(((HSSFClientAnchor) pic.getAnchor()).getDx1());
								anchor.setDx2(((HSSFClientAnchor) pic.getAnchor()).getDx2());
								anchor.setDy1(((HSSFClientAnchor) pic.getAnchor()).getDy1());
								anchor.setDy2(((HSSFClientAnchor) pic.getAnchor()).getDy2());
								anchor.setCol1(((HSSFClientAnchor) pic.getAnchor()).getCol1());
								anchor.setCol2(((HSSFClientAnchor) pic.getAnchor()).getCol2());
								anchor.setRow1(((HSSFClientAnchor) pic.getAnchor()).getRow1());
								anchor.setRow2(((HSSFClientAnchor) pic.getAnchor()).getRow2());
								anchor.setAnchorType(((HSSFClientAnchor) pic.getAnchor()).getAnchorType());
							}
							drawingNew.createPicture(anchor, pictureIndex);
						}
					}
				} else {
					if (drawingNew instanceof XSSFDrawing) {
						List<XSSFShape> shapes = ((XSSFDrawing) drawingOld).getShapes();
						for (int i = 0; i < shapes.size(); i++) {
							if (shapes.get(i) instanceof XSSFPicture) {
								XSSFPicture pic = (XSSFPicture) shapes.get(i);
								XSSFPictureData picdata = pic.getPictureData();
								int pictureIndex = sOut.getWorkbook().addPicture(picdata.getData(), picdata.getPictureType());
								XSSFClientAnchor anchor = null;
								CTTwoCellAnchor oldAnchor = ((XSSFDrawing) drawingOld).getCTDrawing().getTwoCellAnchorArray(i);
								if (oldAnchor != null) {
									anchor = (XSSFClientAnchor) helper.createClientAnchor();
									CTMarker markerFrom = oldAnchor.getFrom();
									CTMarker markerTo = oldAnchor.getTo();
									anchor.setDx1((int) markerFrom.getColOff());
									anchor.setDx2((int) markerTo.getColOff());
									anchor.setDy1((int) markerFrom.getRowOff());
									anchor.setDy2((int) markerTo.getRowOff());
									anchor.setCol1(markerFrom.getCol());
									anchor.setCol2(markerTo.getCol());
									anchor.setRow1(markerFrom.getRow());
									anchor.setRow2(markerTo.getRow());
								}
								drawingNew.createPicture(anchor, pictureIndex);
							}
						}
					}
				}
			}
		}catch(Exception ex){
			ex.printStackTrace();
		}
	}

	public Map createFontForXLSXWorkSheet(Workbook XLSXWorkbook,Workbook XLSWorkbook){
		Map fontMap =  new HashMap();
		try{
			if(XLSXWorkbook!=null && XLSWorkbook!=null){
				short totalNoOfFontsUsed = XLSWorkbook.getNumberOfFonts();
				if(totalNoOfFontsUsed!=0){
					for(short i=0;i<=totalNoOfFontsUsed;i++){
						Font xlsFont =  XLSWorkbook.getFontAt(i);
						Font xlsxFont = XLSXWorkbook.createFont();
						BeanUtils.copyProperties(xlsxFont, xlsFont);
						fontMap.put(xlsFont.getIndex(), xlsxFont);
					}
				}
			}
		}catch(Exception ex){
			ex.printStackTrace();
		}
		return fontMap;
	}	
}
Comment 1 Sanjay saini 2016-02-14 18:26:10 UTC
Created attachment 33552 [details]
Code Used for reading or writing
Comment 2 Sanjay saini 2016-02-17 06:04:44 UTC
Any one please can help me?
Comment 3 Tim Allison 2016-02-17 12:10:31 UTC
I regret that I can't actually help.  

I agree with your diagnosis, the problem is that POI can't read/open this file either with the event listener model or with your method:

wbIn = new HSSFWorkbook(inputStream); // main culprit of the above exception

When I try to open the attached file in Excel, I get an "Office has detected a problem with this file" message, and Excel sternly warns me not to edit it.

I don't know enough about the underlying POI/Excel code (ObjRecord,SubRecord) to be able to help.
Comment 4 Tim Allison 2016-02-17 12:27:23 UTC
Question asked on SO: http://stackoverflow.com/questions/35298310/org-apache-poi-hssf-record-recordformatexception-expected-size-18-but-got-0

Response there, also: potentially corrupt file, although LibreOffice is able to open it.

Note, too, that from https://www.mail-archive.com/dev@poi.apache.org/msg12584.html, it looks like we used to get this exception from 43493.xls (if I read that list correctly), but we're now getting a different exception for that file.  43493 was closed as "won't fix" because the file was corrupt.
Comment 5 Dominik Stadler 2016-03-29 15:06:35 UTC
I don't think it much use to try to read files which Excel itself marks as "corrupt", I strongly suggest you fix how the files are created in the first place to not have to "fix" the symptoms of a corrupted file later. Please feel free to submit a patch for this issue if you find out how this can be handled gracefully in POI then we can see if it makes sense to handle this more gracefully in POI.