當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。