org.apache.poi.poifs.filesystem.NotOLE2FileException Java Examples

The following examples show how to use org.apache.poi.poifs.filesystem.NotOLE2FileException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ExcelPerfModeReader.java    From azeroth with Apache License 2.0 5 votes vote down vote up
private List<String> readAsXLS(String path) {
    try {
        XLS2CSV xls2csv = new XLS2CSV(path, -1);
        return xls2csv.process();
    } catch (Exception e) {
        if (e instanceof NotOLE2FileException || e instanceof NotOfficeXmlFileException || e instanceof OfficeXmlFileException) {
            throw new ExcelOperBaseException("请选择正确格式excel文件");
        }
        if (e instanceof IOException) {
            throw new ExcelOperBaseException("文件读取失败");
        }
        throw new RuntimeException(e);
    }
}
 
Example #2
Source File: ExcelPerfModeReader.java    From jeesuite-libs with Apache License 2.0 5 votes vote down vote up
private List<String> readAsXLS(String path){
	try {				
		XLS2CSV xls2csv = new XLS2CSV(path, -1);
		return xls2csv.process();
	} catch (Exception e) {
		if(e instanceof NotOLE2FileException || e instanceof NotOfficeXmlFileException || e instanceof OfficeXmlFileException){
			throw new ExcelOperBaseException("请选择正确格式excel文件");
		}
		if(e instanceof IOException){
			throw new ExcelOperBaseException("文件读取失败");
		}
		throw new RuntimeException(e);
	}
}
 
Example #3
Source File: HeaderBlock.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
private HeaderBlock(byte[] data) throws IOException {
   this._data = data.clone();
   
	// verify signature
   FileMagic fm = FileMagic.valueOf(data);
   
   switch (fm) {
   case OLE2:
       break;
   case OOXML:
          throw new OfficeXmlFileException("The supplied data appears to be in the Office 2007+ XML. "
              + "You are calling the part of POI that deals with OLE2 Office Documents. "
              + "You need to call a different part of POI to process this data (eg XSSF instead of HSSF)");
   case XML:
          throw new NotOLE2FileException("The supplied data appears to be a raw XML file. "
              + "Formats such as Office 2003 XML are not supported");
   case MSWRITE:
          throw new NotOLE2FileException("The supplied data appears to be in the old MS Write format. "
              + "Apache POI doesn't currently support this format");
      case BIFF2:
      case BIFF3:
      case BIFF4:
          throw new OldExcelFormatException("The supplied data appears to be in "+fm+" format. "
              + "HSSF only supports the BIFF8 format, try OldExcelExtractor");
   default:
          // Give a generic error if the OLE2 signature isn't found
       String exp = HexDump.longToHex(_signature);
       String act = HexDump.longToHex(LittleEndian.getLong(data, 0));
          throw new NotOLE2FileException(
              "Invalid header signature; read " + act + ", expected " + exp +
              " - Your file appears not to be a valid OLE2 document");
   }
   
	// Figure out our block size
	if (_data[30] == 12) {
		this.bigBlockSize = POIFSConstants.LARGER_BIG_BLOCK_SIZE_DETAILS;
	} else if(_data[30] == 9) {
		this.bigBlockSize = POIFSConstants.SMALLER_BIG_BLOCK_SIZE_DETAILS;
	} else {
	   throw new IOException("Unsupported blocksize  (2^"+ _data[30] + "). Expected 2^9 or 2^12.");
	}

   // Setup the fields to read and write the counts and starts
     _bat_count  = new IntegerField(_bat_count_offset, data).get();
     _property_start = new IntegerField(_property_start_offset,_data).get();
     _sbat_start = new IntegerField(_sbat_start_offset, _data).get();
     _sbat_count = new IntegerField(_sbat_block_count_offset, _data).get();
     _xbat_start = new IntegerField(_xbat_start_offset, _data).get();
     _xbat_count = new IntegerField(_xbat_count_offset, _data).get();
}