use of cn.hutool.poi.exceptions.POIException in project hutool by looly.
the class Excel03SaxReader method read.
/**
* 读取
*
* @param fs {@link POIFSFileSystem}
* @param idOrRidOrSheetName sheet id或者rid编号或sheet名称,从0开始,rid必须加rId前缀,例如rId0,如果为-1处理所有编号的sheet
* @return this
* @throws POIException IO异常包装
*/
public Excel03SaxReader read(POIFSFileSystem fs, String idOrRidOrSheetName) throws POIException {
this.rid = getSheetIndex(idOrRidOrSheetName);
formatListener = new FormatTrackingHSSFListener(new MissingRecordAwareHSSFListener(this));
final HSSFRequest request = new HSSFRequest();
if (isOutputFormulaValues) {
request.addListenerForAllRecords(formatListener);
} else {
workbookBuildingListener = new SheetRecordCollectingListener(formatListener);
request.addListenerForAllRecords(workbookBuildingListener);
}
final HSSFEventFactory factory = new HSSFEventFactory();
try {
factory.processWorkbookEvents(request, fs);
} catch (IOException e) {
throw new POIException(e);
} finally {
IoUtil.close(fs);
}
return this;
}
use of cn.hutool.poi.exceptions.POIException in project hutool by looly.
the class Excel03SaxReader method processRecord.
/**
* HSSFListener 监听方法,处理 Record
*
* @param record 记录
*/
@Override
public void processRecord(Record record) {
if (this.rid > -1 && this.curRid > this.rid) {
// 指定Sheet之后的数据不再处理
return;
}
if (record instanceof BoundSheetRecord) {
// Sheet边界记录,此Record中可以获得Sheet名
final BoundSheetRecord boundSheetRecord = (BoundSheetRecord) record;
boundSheetRecords.add(boundSheetRecord);
final String currentSheetName = boundSheetRecord.getSheetname();
if (null != this.sheetName && StrUtil.equals(this.sheetName, currentSheetName)) {
this.rid = this.boundSheetRecords.size() - 1;
}
} else if (record instanceof SSTRecord) {
// 静态字符串表
sstRecord = (SSTRecord) record;
} else if (record instanceof BOFRecord) {
BOFRecord bofRecord = (BOFRecord) record;
if (bofRecord.getType() == BOFRecord.TYPE_WORKSHEET) {
// 如果有需要,则建立子工作薄
if (workbookBuildingListener != null && stubWorkbook == null) {
stubWorkbook = workbookBuildingListener.getStubHSSFWorkbook();
}
curRid++;
}
} else if (record instanceof EOFRecord) {
if (this.rid < 0 && null != this.sheetName) {
throw new POIException("Sheet [{}] not exist!", this.sheetName);
}
processLastCellSheet();
} else if (isProcessCurrentSheet()) {
if (record instanceof MissingCellDummyRecord) {
// 空值的操作
MissingCellDummyRecord mc = (MissingCellDummyRecord) record;
addToRowCellList(mc);
} else if (record instanceof LastCellOfRowDummyRecord) {
// 行结束
processLastCell((LastCellOfRowDummyRecord) record);
} else {
// 处理单元格值
processCellValue(record);
}
}
}
use of cn.hutool.poi.exceptions.POIException in project hutool by looly.
the class Word07Writer method addPicture.
/**
* 增加图片,单独成段落,增加后图片流关闭
*
* @param in 图片流
* @param picType 图片类型,见Document.PICTURE_TYPE_XXX
* @param fileName 文件名
* @param width 宽度
* @param height 高度
* @param align 图片的对齐方式
* @return this
* @since 5.2.4
*/
public Word07Writer addPicture(InputStream in, PicType picType, String fileName, int width, int height, ParagraphAlignment align) {
final XWPFParagraph paragraph = doc.createParagraph();
paragraph.setAlignment(align);
final XWPFRun run = paragraph.createRun();
try {
run.addPicture(in, picType.getValue(), fileName, Units.toEMU(width), Units.toEMU(height));
} catch (InvalidFormatException e) {
throw new POIException(e);
} catch (IOException e) {
throw new IORuntimeException(e);
} finally {
IoUtil.close(in);
}
return this;
}
Aggregations