• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java NotOfficeXmlFileException类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.apache.poi.openxml4j.exceptions.NotOfficeXmlFileException的典型用法代码示例。如果您正苦于以下问题:Java NotOfficeXmlFileException类的具体用法?Java NotOfficeXmlFileException怎么用?Java NotOfficeXmlFileException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



NotOfficeXmlFileException类属于org.apache.poi.openxml4j.exceptions包,在下文中一共展示了NotOfficeXmlFileException类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: extractFromXLSX

import org.apache.poi.openxml4j.exceptions.NotOfficeXmlFileException; //导入依赖的package包/类
/**
    Uses Apache POI to extract information from xlsx file into a 2D array.
    Here is where we got our starter code: http://www.mkyong.com/java/apache-poi-reading-and-writing-excel-file-in-java/
    Look at example number 4, Apache POI library – Reading an Excel file.

    This file originally just printed data, that is why there are several commented out lines in the code.
    We have repurposed this method to put all data into a 2D String array and return it.
 */
public String[][] extractFromXLSX(InputStream excelFile) throws NotOfficeXmlFileException {
    try {
        Workbook workbook = new XSSFWorkbook(excelFile);
        Sheet datatypeSheet = workbook.getSheetAt(0);

        String[][] cellValues = new String[datatypeSheet.getLastRowNum() + 1]
                [max(max(datatypeSheet.getRow(1).getLastCellNum(), datatypeSheet.getRow(2).getLastCellNum()),
                datatypeSheet.getRow(3).getLastCellNum())];

        for (Row currentRow : datatypeSheet) {
            //cellValues[currentRow.getRowNum()] = new String[currentRow.getLastCellNum()];

            for (Cell currentCell : currentRow) {

                //getCellTypeEnum shown as deprecated for version 3.15
                //getCellTypeEnum ill be renamed to getCellType starting from version 4.0
                if (currentCell.getCellTypeEnum() == CellType.STRING) {
                    cellValues[currentCell.getRowIndex()][currentCell.getColumnIndex()] = currentCell.getStringCellValue();
                } else if (currentCell.getCellTypeEnum() == CellType.NUMERIC) {
                    cellValues[currentCell.getRowIndex()][currentCell.getColumnIndex()] =
                            Integer.toString((int) Math.round(currentCell.getNumericCellValue()));
                }

            }

        }
        return cellValues;
    } catch (IOException e) {
        System.out.println("EVERYTHING BLEW UP STOP STOP STOP");
        e.printStackTrace();
        return null; //TODO: this should not return null. This should continue.
    }

}
 
开发者ID:UMM-CSci-3601-S17,项目名称:digital-display-garden-iteration-4-revolverenguardia-1,代码行数:43,代码来源:ExcelParser.java


示例2: readAsXLS

import org.apache.poi.openxml4j.exceptions.NotOfficeXmlFileException; //导入依赖的package包/类
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);
    }
}
 
开发者ID:warlock-china,项目名称:azeroth,代码行数:15,代码来源:ExcelPerfModeReader.java


示例3: testEmptyDoc

import org.apache.poi.openxml4j.exceptions.NotOfficeXmlFileException; //导入依赖的package包/类
@Test(expected = NotOfficeXmlFileException.class)
public void testEmptyDoc() throws InvalidFormatException, IOException {
    final File file = new File("resources/document/empty/empty-template.docx");
    assertTrue(file.exists());
    try (FileInputStream is = new FileInputStream(file);
            OPCPackage oPackage = OPCPackage.open(is);
            XWPFDocument document = new XWPFDocument(oPackage);) {
        TokenIterator iterator = new TokenIterator(document);

        assertTrue(!iterator.hasNext());
    }
}
 
开发者ID:ObeoNetwork,项目名称:M2Doc,代码行数:13,代码来源:RunIteratorTests.java


示例4: readAsXLS

import org.apache.poi.openxml4j.exceptions.NotOfficeXmlFileException; //导入依赖的package包/类
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);
	}
}
 
开发者ID:vakinge,项目名称:jeesuite-libs,代码行数:15,代码来源:ExcelPerfModeReader.java


示例5: openFileAsWorkBook

import org.apache.poi.openxml4j.exceptions.NotOfficeXmlFileException; //导入依赖的package包/类
private Workbook openFileAsWorkBook(MultipartFile file, FileParserMessage<DataFileColumn> msg) throws IOException {
    try {
        String fileName = file.getOriginalFilename();
        if (".xlsx".equals(fileName.substring(fileName.lastIndexOf(".")))) {
            return new XSSFWorkbook(file.getInputStream());
        }
        if (".xls".equals(fileName.substring(fileName.lastIndexOf(".")))) {
            return new HSSFWorkbook(file.getInputStream());
        }
        throw new NotOfficeXmlFileException("Not recognized type");
    } catch (NotOfficeXmlFileException e) {
        msg.addFileParseError(new FileParseError(0, "Invalid file type"));
        throw new IOException();
    }
}
 
开发者ID:abixen,项目名称:abixen-platform,代码行数:16,代码来源:ExcelParserServiceImpl.java


示例6: process

import org.apache.poi.openxml4j.exceptions.NotOfficeXmlFileException; //导入依赖的package包/类
/**
 * Reads a list of POJOs from the given excel file.
 *
 * @param file Excel file to read from
 * @param sheetName The sheet to extract from in the workbook
 * @param reader The reader class to use to load the file from the sheet
 */
public static void process(File file, String sheetName, ZeroCellReader reader) {
    try (FileInputStream fis = new FileInputStream(file);
         OPCPackage opcPackage = OPCPackage.open(fis)) {

        DataFormatter dataFormatter = new DataFormatter();
        ReadOnlySharedStringsTable strings = new ReadOnlySharedStringsTable(opcPackage);
        XSSFReader xssfReader = new XSSFReader(opcPackage);
        StylesTable stylesTable = xssfReader.getStylesTable();
        InputStream sheetInputStream = null;
        XSSFReader.SheetIterator sheets = (XSSFReader.SheetIterator) xssfReader.getSheetsData();
        while (sheets.hasNext()) {
            sheetInputStream = sheets.next();
            if (sheets.getSheetName().equalsIgnoreCase(sheetName)) {
                break;
            } else {
                sheetInputStream = null;
            }
        }

        if (Objects.isNull(sheetInputStream)) {
            throw new SheetNotFoundException(sheetName);
        }

        XMLReader xmlReader = SAXHelper.newXMLReader();
        xmlReader.setContentHandler(new XSSFSheetXMLHandler(stylesTable, strings, reader, dataFormatter, false));
        xmlReader.parse(new InputSource(sheetInputStream));
        sheetInputStream.close();
        xmlReader = null;
        sheetInputStream = null;
        stylesTable = null;
        strings = null;
        xssfReader = null;
    } catch(org.apache.poi.openxml4j.exceptions.InvalidFormatException | NotOfficeXmlFileException ife) {
        throw new ZeroCellException("Cannot load file. The file must be an Excel 2007+ Workbook (.xlsx)");
    } catch(SheetNotFoundException ex) {
        throw new ZeroCellException(ex.getMessage());
    } catch (ZeroCellException ze) {
        throw ze; // Rethrow the Exception
    } catch (Exception e) {
        throw new ZeroCellException("Failed to process file", e);
    }
}
 
开发者ID:creditdatamw,项目名称:zerocell,代码行数:50,代码来源:ReaderUtil.java



注:本文中的org.apache.poi.openxml4j.exceptions.NotOfficeXmlFileException类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java SOAPDocumentImpl类代码示例发布时间:2022-05-23
下一篇:
Java OwnerParam类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap