當前位置: 首頁>>代碼示例>>Java>>正文


Java WorkbookFactory類代碼示例

本文整理匯總了Java中org.apache.poi.ss.usermodel.WorkbookFactory的典型用法代碼示例。如果您正苦於以下問題:Java WorkbookFactory類的具體用法?Java WorkbookFactory怎麽用?Java WorkbookFactory使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


WorkbookFactory類屬於org.apache.poi.ss.usermodel包,在下文中一共展示了WorkbookFactory類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: readExcel

import org.apache.poi.ss.usermodel.WorkbookFactory; //導入依賴的package包/類
public static List<String[]> readExcel(InputStream is, int sheetIndex) throws Exception {
	Workbook workbook = WorkbookFactory.create(is);
	Sheet sheet = workbook.getSheetAt(sheetIndex);
	List<String[]> data = new ArrayList<>();
	for (int i = sheet.getFirstRowNum(); i <= sheet.getLastRowNum(); i++) {
		Row row = sheet.getRow(i);
		if (row == null) continue;
		int last = row.getLastCellNum();
		String[] rowData = new String[last];
		for (int j = 0; j < last; j++) {
			Cell cell = row.getCell(j);
			rowData[j] = cell == null ? null : getCellString(cell);
		}
		data.add(rowData);
	}
	return data;
}
 
開發者ID:21ca,項目名稱:selenium-testng-template,代碼行數:18,代碼來源:FileUtils.java

示例2: readWorkBook

import org.apache.poi.ss.usermodel.WorkbookFactory; //導入依賴的package包/類
public static void readWorkBook() throws Exception {
	// poi��ȡexcel
	// ����Ҫ������ļ���������
	final InputStream inp = new FileInputStream("d:\\workbooks.xlsx");

	// �������������������� ��������������
	final Workbook wb = WorkbookFactory.create(inp);

	for (final Sheet sheet : wb) {

		System.out.println(sheet.getSheetName());
		for (final Row row : sheet) {

			for (final Cell cell : row) {

				System.out.print(cell.toString() + "  ");
			}

			System.out.println();
		}
	}
	// �ر�������
	inp.close();
}
 
開發者ID:zylo117,項目名稱:SpotSpotter,代碼行數:25,代碼來源:Excel4J.java

示例3: loadSheetForTest

import org.apache.poi.ss.usermodel.WorkbookFactory; //導入依賴的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

示例4: fillTrie

import org.apache.poi.ss.usermodel.WorkbookFactory; //導入依賴的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

示例5: importCombination

import org.apache.poi.ss.usermodel.WorkbookFactory; //導入依賴的package包/類
public static CombinationSolver<String, String> importCombination(File file) throws Exception {
    if (file.getName().endsWith(".csv")) {
        try (Reader reader = new FileReader(file);
             TableCSVReader csvReader = new TableCSVReader(reader)) {
            csvReader.setUseHeader(true);
            return importCombination(csvReader);
        }
    } else if (file.getName().endsWith(".xls") || file.getName().endsWith(".xlsx")) {
        Workbook workbook = WorkbookFactory.create(file);
        Sheet sheet = workbook.getSheetAt(0);
        try (ExcelSheetReader sheetReader = new ExcelSheetReader(sheet)) {
            sheetReader.setUseHeader(true);
            return importCombination(sheetReader);
        }
    } else {
        throw new IllegalArgumentException("Unsupported file");
    }
}
 
開發者ID:informationsea,項目名稱:VennDraw,代碼行數:19,代碼來源:CombinationImporterExporter.java

示例6: needsNewTracker

import org.apache.poi.ss.usermodel.WorkbookFactory; //導入依賴的package包/類
public static boolean needsNewTracker() throws Exception {
    final String FILE = workbook.getAbsolutePath();
    InputStream inp = new FileInputStream(FILE);
    Workbook wb = WorkbookFactory.create(inp);
    Sheet sheet = wb.getSheetAt(0);
    Row row = sheet.getRow(1);
    Cell cell = row.getCell(1);
    Date firstCellContents = cell.getDateCellValue();
    Calendar firstDayCalendar = Calendar.getInstance();
    firstDayCalendar.setTime(firstCellContents);
    int diff = daysBetweenFirstPST(firstDayCalendar);
    if (diff < 14) {
        return false;
    } else {
        return true;
    }
}
 
開發者ID:mansueli,項目名稱:SLABot,代碼行數:18,代碼來源:Tracker.java

示例7: readExecl

import org.apache.poi.ss.usermodel.WorkbookFactory; //導入依賴的package包/類
public static List<String[]> readExecl(InputStream is, int column) throws Exception {
//    	InputStream is = new FileInputStream(path);
//    	Workbook xssfWorkbook = new XSSFWorkbook(is);//初始化失敗,暫時不解析excel2010
    	Workbook workbook = WorkbookFactory.create(is);
    	List<String[]> list = new ArrayList<String[]>();
    	for (int numSheet = 0; numSheet < workbook.getNumberOfSheets(); numSheet++) {
    		Sheet sheet = workbook.getSheetAt(numSheet);
    		if (sheet == null || sheet.getLastRowNum() <= 0) {
    			continue;
    		}
    		for(int rowNum = 1; rowNum <= sheet.getLastRowNum(); rowNum++) {
    			Row xssfRow = sheet.getRow(rowNum);
    			if (xssfRow != null) {
    				String[] dataRow = new String[column];
    				for (int i = 0; i < column; i++) {
    					Cell ic_no = xssfRow.getCell(i);
    					dataRow[i] = getCellValue(ic_no);
					}
    				list.add(dataRow);
    			}
    		}
    	}
    	return list;
    }
 
開發者ID:smart-vole,項目名稱:competition,代碼行數:25,代碼來源:ExeclUtils.java

示例8: getWorkbook

import org.apache.poi.ss.usermodel.WorkbookFactory; //導入依賴的package包/類
/**
 * Get Workbook
 * 
 * @param completeFilePath
 * @param fileExtension
 * @return workbook
 * @throws ParserException
 */
private Workbook getWorkbook(File completeFilePath, String fileExtension)
        throws ParserException {
    /* Open & Read File */
    try (FileInputStream inputStream = new FileInputStream(completeFilePath)) {
        /* Get Type Based On File Extension */
        return fileExtension.equals(Constants.EXT_XLSX) ? (XSSFWorkbook) WorkbookFactory
                .create(inputStream) : fileExtension
                .equals(Constants.EXT_XLS) ? (HSSFWorkbook) WorkbookFactory
                .create(inputStream) : null;
    } catch (Exception ex) {
        /* Catch, Log & Throw Exception */
        LOGGER.error("Error Occured While Parsing File!", ex);
        throw new ParserException(exceptionFactory.create(
                ExceptionType.PARSER, "PAR003",
                completeFilePath.getAbsolutePath()), ex);
    }
}
 
開發者ID:agrawroh,項目名稱:selemize,代碼行數:26,代碼來源:POIParser.java

示例9: scan

import org.apache.poi.ss.usermodel.WorkbookFactory; //導入依賴的package包/類
@Override
public void scan(File file, String filename, SheetSelection selection, IExcelImportFileVisitor<Workbook, Sheet, Row, Cell, CellReference> visitor) throws TableImportException {
	Validate.notNull(file, "file must not be null");
	Validate.notNull(visitor, "visitor must not be null");
	
	ApachePoiImportNavigator navigator = new ApachePoiImportNavigator(filename);
	
	try (InputStream stream = new TFileInputStream(file)) {
		Workbook workbook = WorkbookFactory.create(stream);
		
		for (int index = 0 ; index < workbook.getNumberOfSheets() ; ++index) {
			Sheet sheet = workbook.getSheetAt(index);
			if (navigator.tableHasContent(sheet) && SELECTIONS_PREDICATES.get(selection).apply(sheet)) {
				visitor.visitSheet(navigator, workbook, sheet);
			}
		}
	} catch (InvalidFormatException | IOException | IllegalArgumentException e) {
		throw new TableImportFileException(e, navigator.getLocation(null, null, null));
	}
}
 
開發者ID:openwide-java,項目名稱:owsi-core-parent,代碼行數:21,代碼來源:ApachePoiImportFileScanner.java

示例10: loadSheetForFormat

import org.apache.poi.ss.usermodel.WorkbookFactory; //導入依賴的package包/類
/**
 * 書式確認用のシートの取得
 * @param file
 * @return
 * @throws InvalidFormatException
 * @throws IOException
 */
private List<Sheet> loadSheetForFormat(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,代碼行數:30,代碼來源:POICellFormatterTest.java

示例11: loadSheetByName

import org.apache.poi.ss.usermodel.WorkbookFactory; //導入依賴的package包/類
/**
 * シート名を指定して取得する
 * @param file
 * @param name
 */
private Sheet loadSheetByName(final File file, final String name) throws InvalidFormatException, IOException {
    
    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.equals(name)) {
                return sheet;
            }
        }
    }
    
    throw new IllegalStateException("not found sheet : " + name);
}
 
開發者ID:mygreen,項目名稱:excel-cellformatter,代碼行數:24,代碼來源:POICellFormatterTest.java

示例12: generateWorkbookWithSheets

import org.apache.poi.ss.usermodel.WorkbookFactory; //導入依賴的package包/類
private Workbook generateWorkbookWithSheets(ReportConfig reportConfig) throws IOException, InvalidFormatException {
    if (!reportConfig.isAppendToDestination()) {
        LOGGER.debug("creating empty workbook with sheets");
        Workbook workbook = new XSSFWorkbook();
        FileOutputStream fileOut = new FileOutputStream(reportConfig.getDestinationFile());
        generateSheets(reportConfig, workbook);
        workbook.write(fileOut);
        fileOut.close();
        LOGGER.debug("workbook created");
        return workbook;
    } else {
        LOGGER.debug("will append to destination file");
        File destFile = new File(reportConfig.getDestinationFile());
        FileInputStream fileInputStream = new FileInputStream(destFile);
        OPCPackage opc = OPCPackage.open(fileInputStream);
        return WorkbookFactory.create(opc);
    }
}
 
開發者ID:SumoLogic,項目名稱:sumo-report-generator,代碼行數:19,代碼來源:ExcelWorkbookGenerator.java

示例13: poiParserMultipleSheets

import org.apache.poi.ss.usermodel.WorkbookFactory; //導入依賴的package包/類
@org.junit.Test
public void poiParserMultipleSheets() throws Exception {

	//generate
	SheetParser parser = new PoiSheetParser();
	parser.load(getClass().getResourceAsStream("expressions-multiple-sheets.xlsx"));
	parser.process(new MVEL2Interpreter(), new User("Silva"), null, null);
	ByteArrayOutputStream bos = new ByteArrayOutputStream();
	parser.writeTo(bos);

	//check
	Workbook wb = WorkbookFactory.create(new ByteArrayInputStream(bos.toByteArray()));
	assertEquals("Name: Silva", wb.getSheetAt(0).getRow(2).getCell(1).getStringCellValue());
	assertEquals("Address: Endere�o", wb.getSheetAt(1).getRow(2).getCell(1).getStringCellValue());

}
 
開發者ID:utluiz,項目名稱:t-rex,代碼行數:17,代碼來源:SheetParserTest.java

示例14: poiParserLoopEmpty

import org.apache.poi.ss.usermodel.WorkbookFactory; //導入依賴的package包/類
@org.junit.Test
public void poiParserLoopEmpty() throws Exception {
	
	//model
	Map<String, Object> variables = new HashMap<String, Object>();
	List<Parcel> parcels = new ArrayList<Parcel>();
	variables.put("parcels", parcels);
	variables.put("client", new User("Silva"));
	
	//generate
	SheetParser parser = new PoiSheetParser();
	parser.load(getClass().getResourceAsStream("loop-rows-empty.xlsx"));
	parser.process(new MVEL2Interpreter(), null, variables, null);
	ByteArrayOutputStream bos = new ByteArrayOutputStream();
	parser.writeTo(bos);

	//check
	Workbook wb = WorkbookFactory.create(new ByteArrayInputStream(bos.toByteArray()));
	//wb.write(new FileOutputStream("target/loop-rows-empty-output.xlsx"));
	
	assertEquals("Silva", wb.getSheetAt(0).getRow(1).getCell(2).getStringCellValue());
	assertEquals(6, wb.getSheetAt(0).getLastRowNum());
	assertEquals("A", wb.getSheetAt(0).getRow(5).getCell(0).getStringCellValue());
	assertEquals("B", wb.getSheetAt(0).getRow(6).getCell(0).getStringCellValue());
	
}
 
開發者ID:utluiz,項目名稱:t-rex,代碼行數:27,代碼來源:SheetParserTest.java

示例15: main

import org.apache.poi.ss.usermodel.WorkbookFactory; //導入依賴的package包/類
public static void main(String[] args) throws Exception
{
	String dataPath = "src/featurescomparison/workingwithcellsrowscolumns/hideunhidecells/data/";
	
	InputStream inStream = new FileInputStream(dataPath + "workbook.xls");
	Workbook workbook = WorkbookFactory.create(inStream);
	Sheet sheet = workbook.createSheet();
	Row row = sheet.createRow(0);
	row.setZeroHeight(true);
	
	FileOutputStream fileOut = new FileOutputStream(dataPath + "hideUnhideCells_Apache_Out.xls");
	workbook.write(fileOut);
	fileOut.close();
	
	System.out.println("Process Completed.");
}
 
開發者ID:asposemarketplace,項目名稱:Aspose_for_Apache_POI,代碼行數:17,代碼來源:ApacheHideUnHideCells.java


注:本文中的org.apache.poi.ss.usermodel.WorkbookFactory類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。