use of org.apache.poi.openxml4j.exceptions.InvalidFormatException in project cytoscape-impl by cytoscape.
the class ImportAttributeTableReaderTask method run.
@Override
public void run(TaskMonitor tm) throws Exception {
tm.setTitle("Loading table data");
tm.setProgress(0.0);
tm.setStatusMessage("Loading table...");
Workbook workbook = null;
// Load Spreadsheet data for preview.
if (fileType != null && (fileType.equalsIgnoreCase(SupportedFileType.EXCEL.getExtension()) || fileType.equalsIgnoreCase(SupportedFileType.OOXML.getExtension())) && workbook == null) {
try {
workbook = WorkbookFactory.create(is);
} catch (InvalidFormatException e) {
e.printStackTrace();
throw new IllegalArgumentException("Could not read Excel file. Maybe the file is broken?");
} finally {
if (is != null)
is.close();
}
}
if (this.fileType.equalsIgnoreCase(SupportedFileType.EXCEL.getExtension()) || this.fileType.equalsIgnoreCase(SupportedFileType.OOXML.getExtension())) {
// Fixed bug# 1668, Only load data from the first sheet, ignore the rest sheets
// UPDATE: From the user perspective it makes more sense to get the selected tab/sheet instead.
String networkName = amp.getName();
if (networkName == null)
networkName = workbook.getSheetName(0);
final Sheet sheet = workbook.getSheet(networkName);
if (sheet != null) {
reader = new ExcelAttributeSheetReader(sheet, amp, serviceRegistrar);
loadAnnotation(tm);
}
} else {
try {
reader = new DefaultAttributeTableReader(null, amp, this.is, serviceRegistrar);
loadAnnotation(tm);
} catch (Exception ioe) {
tm.showMessage(TaskMonitor.Level.ERROR, "Unable to read table: " + ioe.getMessage());
}
}
}
use of org.apache.poi.openxml4j.exceptions.InvalidFormatException in project my_curd by qinyou.
the class ExcelHelper method exportExcelFile.
/**
* @param head
* @param modelFile
* @param outputFile
* @param dataList
*/
public void exportExcelFile(ExcelHead head, File modelFile, File outputFile, List<?> dataList) {
// 读取导出excel模板
InputStream inp = null;
Workbook wb = null;
try {
inp = new FileInputStream(modelFile);
wb = WorkbookFactory.create(inp);
Sheet sheet = wb.getSheetAt(0);
// 生成导出数据
buildExcelData(sheet, head, dataList);
// 导出到文件中
FileOutputStream fileOut = new FileOutputStream(outputFile);
wb.write(fileOut);
fileOut.close();
} catch (FileNotFoundException ex) {
ex.printStackTrace();
} catch (InvalidFormatException ex) {
ex.printStackTrace();
} catch (IOException ex) {
ex.printStackTrace();
}
}
use of org.apache.poi.openxml4j.exceptions.InvalidFormatException in project Xlsx2Json by noahzark.
the class ExcelParserMain method parseExcelFile.
/**
* Parse the excel file and save as json
* @param targetName Excel file name without suffix
* @param sheetList Target sheet list
* @param showSheetName Whether show sheet name in result or not
*/
public static void parseExcelFile(String targetName, String[] sheetList, boolean showSheetName) {
try {
Workbook workbook = getWorkbook(targetName);
String jsonText;
if (showSheetName) {
// Get the JSON text.
JSONObject json = constructJsonObject(workbook, sheetList);
jsonText = json.toString();
} else {
// Get the JSON text.
JSONArray json = constructJsonArray(workbook, sheetList);
jsonText = json.toString();
}
saveStringToFile(targetName, jsonText);
} catch (InvalidFormatException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
use of org.apache.poi.openxml4j.exceptions.InvalidFormatException 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;
}
use of org.apache.poi.openxml4j.exceptions.InvalidFormatException in project selenium_java by sergueik.
the class TestWithData method getSpreadSheet.
public Sheet getSpreadSheet() {
File file = new File(System.getProperty("user.dir") + File.separator + "target\\classes\\Test.xlsx");
FileInputStream inputStream = null;
Workbook wb = null;
try {
inputStream = new FileInputStream(file);
wb = WorkbookFactory.create(inputStream);
System.out.println(wb.toString());
} catch (IOException ex) {
System.out.println("Error Message " + ex.getMessage());
} catch (InvalidFormatException e) {
System.out.println("Invalid File format!");
}
Sheet mySheet = wb.getSheet("MySheet");
return mySheet;
}
Aggregations