当前位置: 首页>>代码示例>>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;未经允许,请勿转载。