当前位置: 首页>>代码示例>>Java>>正文


Java InvalidFormatException类代码示例

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


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

示例1: testDown

import org.apache.poi.openxml4j.exceptions.InvalidFormatException; //导入依赖的package包/类
@RequestMapping(value = "/test2.xlsx", produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
@ResponseBody
byte[] testDown() throws IOException, InvalidFormatException {
    Workbook workbook = new SXSSFWorkbook();
    Sheet sheet = workbook.createSheet();
    for (int i = 0; i < 60000; i++) {
        Row newRow = sheet.createRow(i);
        for (int j = 0; j < 100; j++) {
            newRow.createCell(j).setCellValue("test" + Math.random());
        }
    }
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    workbook.write(os);
    byte[] bytes = os.toByteArray();
    return bytes;
}
 
开发者ID:Yuiffy,项目名称:file-download-upload-zip-demo,代码行数:17,代码来源:FileController.java

示例2: testAccessEmptyIterator

import org.apache.poi.openxml4j.exceptions.InvalidFormatException; //导入依赖的package包/类
@Test(expected = NoSuchElementException.class)
public void testAccessEmptyIterator() throws InvalidFormatException, IOException {
    try (FileInputStream is = new FileInputStream("resources/document/notEmpty/notEmpty-template.docx");
            OPCPackage oPackage = OPCPackage.open(is);
            XWPFDocument document = new XWPFDocument(oPackage);) {
        TokenProvider iterator = new TokenProvider(document);
        iterator.next().getRun();
        iterator.next().getRun();
        iterator.next().getRun();
        iterator.next().getRun();
        iterator.next().getRun();
        iterator.next().getRun();
        iterator.next().getRun();
        iterator.next().getRun();
        iterator.next().getRun();
    }
}
 
开发者ID:ObeoNetwork,项目名称:M2Doc,代码行数:18,代码来源:RunProviderTests.java

示例3: getMissingVariables

import org.apache.poi.openxml4j.exceptions.InvalidFormatException; //导入依赖的package包/类
@Test
public void getMissingVariables() throws IOException, InvalidFormatException {
    try (XWPFDocument document = POIServices.getInstance().getXWPFDocument(URIConverter.INSTANCE,
            URI.createFileURI("resources/document/properties/missingVariables.docx"));) {
        final TemplateCustomProperties properties = new TemplateCustomProperties(document);
        final List<String> missingVariables = properties.getMissingVariables();

        assertEquals(16, missingVariables.size());
        assertEquals("linkNamelinkText", missingVariables.get(0));
        assertEquals("bookmarkName", missingVariables.get(1));
        assertEquals("queryInBookmark", missingVariables.get(2));
        assertEquals("ifCondition", missingVariables.get(3));
        assertEquals("queryInIf", missingVariables.get(4));
        assertEquals("elseIfCondition", missingVariables.get(5));
        assertEquals("queryInElseIf", missingVariables.get(6));
        assertEquals("queryInElse", missingVariables.get(7));
        assertEquals("letExpression", missingVariables.get(8));
        assertEquals("queryInLet", missingVariables.get(9));
        assertEquals("forExpression", missingVariables.get(10));
        assertEquals("queryInFor", missingVariables.get(11));
        assertEquals("queryExpression", missingVariables.get(12));
        assertEquals("aqlInSelect", missingVariables.get(13));
        assertEquals("aqlLetExpression", missingVariables.get(14));
        assertEquals("aqlLetBody", missingVariables.get(15));
    }
}
 
开发者ID:ObeoNetwork,项目名称:M2Doc,代码行数:27,代码来源:TemplateCustomPropertiesTests.java

示例4: getNumberOfSheets

import org.apache.poi.openxml4j.exceptions.InvalidFormatException; //导入依赖的package包/类
/**
 * Returns the number of sheets in the excel file
 *
 * @return
 * @throws IOException
 * @throws BiffException
 * @throws InvalidFormatException
 */
public int getNumberOfSheets() throws BiffException, IOException, InvalidFormatException, UserError {
	if (getFile().getAbsolutePath().endsWith(XLSX_FILE_ENDING)) {
		// excel 2007 file
		try (ZipFile zipFile = new ZipFile(getFile().getAbsolutePath())) {
			try {
				return getNumberOfSheets(parseWorkbook(zipFile));
			} catch (ParserConfigurationException | SAXException e) {
				throw new UserError(null, e, "xlsx_content_malformed");
			}
		}
	} else {
		// excel pre 2007 file
		if (workbookJXL == null) {
			createWorkbookJXL();
		}
		return workbookJXL.getNumberOfSheets();
	}
}
 
开发者ID:transwarpio,项目名称:rapidminer,代码行数:27,代码来源:ExcelResultSetConfiguration.java

示例5: ImportExcel

import org.apache.poi.openxml4j.exceptions.InvalidFormatException; //导入依赖的package包/类
/**
 * 构造函数
 *
 * @param fileName   导入文件对象
 * @param headerNum  标题行号,数据行号=标题行号+1
 * @param sheetIndex 工作表编号
 * @throws InvalidFormatException
 * @throws IOException
 */
public ImportExcel(String fileName, InputStream is, int headerNum, int sheetIndex)
        throws InvalidFormatException, IOException {
    if (StringUtils.isBlank(fileName)) {
        throw new RuntimeException("Import file is empty!");
    } else if (fileName.toLowerCase().endsWith("xls")) {
        this.wb = new HSSFWorkbook(is);
    } else if (fileName.toLowerCase().endsWith("xlsx")) {
        this.wb = new XSSFWorkbook(is);
    } else {
        throw new RuntimeException("Invalid import file type!");
    }
    if (this.wb.getNumberOfSheets() < sheetIndex) {
        throw new RuntimeException("No sheet in Import file!");
    }
    this.sheet = this.wb.getSheetAt(sheetIndex);
    this.headerNum = headerNum;
    log.debug("Initialize success.");
}
 
开发者ID:sombie007,项目名称:ExcelHandle,代码行数:28,代码来源:ImportExcel.java

示例6: testNonEmptyDoc

import org.apache.poi.openxml4j.exceptions.InvalidFormatException; //导入依赖的package包/类
@Test
public void testNonEmptyDoc() throws InvalidFormatException, IOException {
    try (FileInputStream is = new FileInputStream("resources/document/notEmpty/notEmpty-template.docx");
            OPCPackage oPackage = OPCPackage.open(is);
            XWPFDocument document = new XWPFDocument(oPackage);) {
        TokenProvider iterator = new TokenProvider(document);
        XWPFRun run = iterator.next().getRun();
        assertEquals("P1Run1 ", run.getText(run.getTextPosition()));
        run = iterator.next().getRun();
        assertEquals("P1Run2", run.getText(run.getTextPosition()));
        run = iterator.next().getRun();
        assertEquals(" P1Run3", run.getText(run.getTextPosition()));
        run = iterator.next().getRun();
        assertEquals("P2Run1 ", run.getText(run.getTextPosition()));
        run = iterator.next().getRun();
        assertEquals("P2Run2", run.getText(run.getTextPosition()));
        run = iterator.next().getRun();
        assertEquals(" ", run.getText(run.getTextPosition()));
        run = iterator.next().getRun();
        assertEquals("P2Run3", run.getText(run.getTextPosition()));
        run = iterator.next().getRun();
        assertEquals("", run.getText(run.getTextPosition()));
        assertTrue(!iterator.hasNext());
    }
}
 
开发者ID:ObeoNetwork,项目名称:M2Doc,代码行数:26,代码来源:RunProviderTests.java

示例7: testLookaheadEmptyIterator

import org.apache.poi.openxml4j.exceptions.InvalidFormatException; //导入依赖的package包/类
@Test
public void testLookaheadEmptyIterator() throws InvalidFormatException, IOException {
    try (FileInputStream is = new FileInputStream("resources/document/notEmpty/notEmpty-template.docx");
            OPCPackage oPackage = OPCPackage.open(is);
            XWPFDocument document = new XWPFDocument(oPackage);) {
        TokenProvider iterator = new TokenProvider(document);
        iterator.next().getRun();
        iterator.next().getRun();
        iterator.next().getRun();
        iterator.next().getRun();
        iterator.next().getRun();
        iterator.next().getRun();
        iterator.next().getRun();
        iterator.next().getRun();
        assertNull(iterator.lookAhead(1));
    }
}
 
开发者ID:ObeoNetwork,项目名称:M2Doc,代码行数:18,代码来源:RunProviderTests.java

示例8: testNextWitLookAhead

import org.apache.poi.openxml4j.exceptions.InvalidFormatException; //导入依赖的package包/类
@Test
public void testNextWitLookAhead() throws InvalidFormatException, IOException {
    try (FileInputStream is = new FileInputStream("resources/document/notEmpty/notEmpty-template.docx");
            OPCPackage oPackage = OPCPackage.open(is);
            XWPFDocument document = new XWPFDocument(oPackage);) {
        TokenProvider iterator = new TokenProvider(document);
        // CHECKSTYLE:OFF
        assertTrue(iterator.hasElements(7));
        // CHECKSTYLE:ON
        XWPFRun run;
        run = iterator.lookAhead(1).getRun();
        assertEquals("P1Run1 ", run.getText(run.getTextPosition()));
        run = iterator.next().getRun();
        assertEquals("P1Run1 ", run.getText(run.getTextPosition()));
        run = iterator.lookAhead(1).getRun();
        assertEquals("P1Run2", run.getText(run.getTextPosition()));
        run = iterator.lookAhead(2).getRun();
        assertEquals(" P1Run3", run.getText(run.getTextPosition()));
        run = iterator.next().getRun();
        assertEquals("P1Run2", run.getText(run.getTextPosition()));
        run = iterator.next().getRun();
        assertEquals(" P1Run3", run.getText(run.getTextPosition()));
        assertTrue(iterator.hasElements(4));
    }
}
 
开发者ID:ObeoNetwork,项目名称:M2Doc,代码行数:26,代码来源:RunProviderTests.java

示例9: testNonEmptyDoc

import org.apache.poi.openxml4j.exceptions.InvalidFormatException; //导入依赖的package包/类
@Test
public void testNonEmptyDoc() throws InvalidFormatException, IOException {
    try (FileInputStream is = new FileInputStream("resources/document/notEmpty/notEmpty-template.docx");
            OPCPackage oPackage = OPCPackage.open(is);
            XWPFDocument document = new XWPFDocument(oPackage);) {
        TokenIterator iterator = new TokenIterator(document);
        XWPFRun run = iterator.next().getRun();
        assertEquals("P1Run1 ", run.getText(run.getTextPosition()));
        run = iterator.next().getRun();
        assertEquals("P1Run2", run.getText(run.getTextPosition()));
        run = iterator.next().getRun();
        assertEquals(" P1Run3", run.getText(run.getTextPosition()));
        run = iterator.next().getRun();
        assertEquals("P2Run1 ", run.getText(run.getTextPosition()));
        run = iterator.next().getRun();
        assertEquals("P2Run2", run.getText(run.getTextPosition()));
        run = iterator.next().getRun();
        assertEquals(" ", run.getText(run.getTextPosition()));
        run = iterator.next().getRun();
        assertEquals("P2Run3", run.getText(run.getTextPosition()));
        run = iterator.next().getRun();
        assertEquals("", run.getText(run.getTextPosition()));
        assertTrue(!iterator.hasNext());
    }
}
 
开发者ID:ObeoNetwork,项目名称:M2Doc,代码行数:26,代码来源:RunIteratorTests.java

示例10: testAccessEmptyIterator

import org.apache.poi.openxml4j.exceptions.InvalidFormatException; //导入依赖的package包/类
@Test
public void testAccessEmptyIterator() throws InvalidFormatException, IOException {
    try (FileInputStream is = new FileInputStream("resources/document/notEmpty/notEmpty-template.docx");
            OPCPackage oPackage = OPCPackage.open(is);
            XWPFDocument document = new XWPFDocument(oPackage);) {
        TokenIterator iterator = new TokenIterator(document);
        assertNotNull(iterator.next());
        assertNotNull(iterator.next());
        assertNotNull(iterator.next());
        assertNotNull(iterator.next());
        assertNotNull(iterator.next());
        assertNotNull(iterator.next());
        assertNotNull(iterator.next());
        assertNotNull(iterator.next());
        assertFalse(iterator.hasNext());
        boolean hasException = false;
        try {
            iterator.next();
        } catch (NoSuchElementException e) {
            assertTrue(e instanceof NoSuchElementException);
            hasException = true;
        }
        assertTrue(hasException);
    }
}
 
开发者ID:ObeoNetwork,项目名称:M2Doc,代码行数:26,代码来源:RunIteratorTests.java

示例11: loadSheetForTest

import org.apache.poi.openxml4j.exceptions.InvalidFormatException; //导入依赖的package包/类
/**
 * テスト用のシートの取得
 * <p>修正したりするためのシート
 */
private List<Sheet> loadSheetForTest(final File file) throws InvalidFormatException, IOException {
    
    List<Sheet> list = new ArrayList<>();
    try(InputStream in = new FileInputStream(file)) {
        Workbook workbook = WorkbookFactory.create(in);
    
        final int sheetNum = workbook.getNumberOfSheets();
        for(int i=0; i < sheetNum; i++) {
            
            final Sheet sheet = workbook.getSheetAt(i);
            final String sheetName = sheet.getSheetName();
            if(!sheetName.startsWith("テスト")) {
                continue;
            }
            
            list.add(sheet);
            
        }
    }
    
    return list;
}
 
开发者ID:mygreen,项目名称:excel-cellformatter,代码行数:27,代码来源:POICellFormatterTest.java

示例12: generateReport

import org.apache.poi.openxml4j.exceptions.InvalidFormatException; //导入依赖的package包/类
@Override
public void generateReport(ReportConfig reportConfig) throws ReportGenerationException {
    try {
        LOGGER.info("starting report generation");
        long start = System.currentTimeMillis();
        LOGGER.debug("using config: " + reportConfig);
        Workbook workbook = getWorkbook(reportConfig);
        workbookPopulator.populateWorkbookWithData(reportConfig, workbook);
        LOGGER.info("updating formulas");
        XSSFFormulaEvaluator.evaluateAllFormulaCells((XSSFWorkbook) workbook);
        FileOutputStream fileOut = new FileOutputStream(reportConfig.getDestinationFile());
        workbook.write(fileOut);
        fileOut.close();
        String timeTaken = new SimpleDateFormat("mm:ss").format(new Date(System.currentTimeMillis() - start));
        LOGGER.info("report successfully generated in " + timeTaken);
    } catch (IOException | InvalidFormatException e ) {
        LOGGER.error("unabe to generate report!");
        throw new ReportGenerationException(e);
    }
}
 
开发者ID:SumoLogic,项目名称:sumo-report-generator,代码行数:21,代码来源:ExcelReportGenerator.java

示例13: getSheetNames

import org.apache.poi.openxml4j.exceptions.InvalidFormatException; //导入依赖的package包/类
/**
 * Returns the names of all sheets in the excel file
 *
 * @return
 * @throws IOException
 * @throws BiffException
 * @throws InvalidFormatException
 */
public String[] getSheetNames() throws BiffException, IOException, InvalidFormatException, UserError {
	if (getFile().getAbsolutePath().endsWith(XLSX_FILE_ENDING)) {
		// excel 2007 file
		try (ZipFile zipFile = new ZipFile(getFile().getAbsolutePath())) {
			XlsxWorkbook workbook;
			try {
				workbook = parseWorkbook(zipFile);
				String[] sheetNames = new String[getNumberOfSheets(workbook)];
				for (int i = 0; i < getNumberOfSheets(); i++) {
					sheetNames[i] = workbook.xlsxWorkbookSheets.get(i).name;
				}
				return sheetNames;
			} catch (ParserConfigurationException | SAXException e) {
				throw new UserError(null, e, "xlsx_content_malformed");
			}

		}
	} else {
		// excel pre 2007 file
		if (workbookJXL == null) {
			createWorkbookJXL();
		}
		return workbookJXL.getSheetNames();
	}
}
 
开发者ID:transwarpio,项目名称:rapidminer,代码行数:34,代码来源:ExcelResultSetConfiguration.java

示例14: fillTrie

import org.apache.poi.openxml4j.exceptions.InvalidFormatException; //导入依赖的package包/类
@Override
protected void fillTrie(Logger logger, Trie<List<String>> trie, Corpus corpus) throws IOException, ModuleException {
	Iterator<InputStream> inputStreams = xlsFile.getInputStreams();
	while (inputStreams.hasNext()) {
		try (InputStream is = inputStreams.next()) {
			Workbook wb = WorkbookFactory.create(is);
			for (int sheetNumber : sheets) {
				Sheet sheet = wb.getSheetAt(sheetNumber);
				fillSheetEntries(trie, sheet);
			}
		}
		catch (EncryptedDocumentException|InvalidFormatException e) {
			rethrow(e);
		}
	}
}
 
开发者ID:Bibliome,项目名称:alvisnlp,代码行数:17,代码来源:XLSProjector.java

示例15: remapContentType

import org.apache.poi.openxml4j.exceptions.InvalidFormatException; //导入依赖的package包/类
void remapContentType(BleachSession session, PackagePart part) throws InvalidFormatException {
    String oldContentType = part.getContentType();
    if (!REMAPPED_CONTENT_TYPES.containsKey(oldContentType)) {
        return;
    }

    String newContentType = REMAPPED_CONTENT_TYPES.get(part.getContentType());
    part.setContentType(newContentType);

    LOGGER.debug("Content type of '{}' changed from '{}' to '{}'", part.getPartName(), oldContentType, newContentType);

    Threat threat = threat()
            .type(ThreatType.UNRECOGNIZED_CONTENT)
            .severity(ThreatSeverity.LOW)
            .action(ThreatAction.DISARM)
            .location(part.getPartName().getName())
            .details("Remapped content type: " + oldContentType)
            .build();

    session.recordThreat(threat);
}
 
开发者ID:docbleach,项目名称:DocBleach,代码行数:22,代码来源:OOXMLBleach.java


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