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


Java XSSFReader.SheetIterator方法代码示例

本文整理汇总了Java中org.apache.poi.xssf.eventusermodel.XSSFReader.SheetIterator方法的典型用法代码示例。如果您正苦于以下问题:Java XSSFReader.SheetIterator方法的具体用法?Java XSSFReader.SheetIterator怎么用?Java XSSFReader.SheetIterator使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.poi.xssf.eventusermodel.XSSFReader的用法示例。


在下文中一共展示了XSSFReader.SheetIterator方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: process

import org.apache.poi.xssf.eventusermodel.XSSFReader; //导入方法依赖的package包/类
/**
 * Initiates the processing of the XLS workbook file to CSV.
 *
 * @throws IOException
 * @throws OpenXML4JException
 * @throws ParserConfigurationException
 * @throws SAXException
 */
public List<String> process() throws IOException, OpenXML4JException, ParserConfigurationException, SAXException {
    ReadOnlySharedStringsTable strings = new ReadOnlySharedStringsTable(this.xlsxPackage);
    XSSFReader xssfReader = new XSSFReader(this.xlsxPackage);
    StylesTable styles = xssfReader.getStylesTable();
    XSSFReader.SheetIterator iter = (XSSFReader.SheetIterator) xssfReader.getSheetsData();
    int index = 0;
    while (iter.hasNext()) {
        if (blankRowNum == 10) { break; }
        InputStream stream = iter.next();
        String sheetName = iter.getSheetName();
        results.add(ExcelValidator.SHEET_NAME_PREFIX + sheetName);
        processSheet(styles, strings, new SheetToCSV(), stream);
        stream.close();
        ++index;
    }

    return results;
}
 
开发者ID:warlock-china,项目名称:azeroth,代码行数:27,代码来源:XLSX2CSV.java

示例2: execute

import org.apache.poi.xssf.eventusermodel.XSSFReader; //导入方法依赖的package包/类
public void execute(InputStream inputStream, IParseExcelRowMapper parseExcelRowMapper) throws Exception {
	OPCPackage pkg = OPCPackage.open(inputStream);
	XSSFReader xssfReader = new XSSFReader(pkg);
	sst = xssfReader.getSharedStringsTable();
	stylesTable = xssfReader.getStylesTable();

	SAXParserFactory saxFactory = SAXParserFactory.newInstance();
	SAXParser saxParser = saxFactory.newSAXParser();
	XMLReader parser = saxParser.getXMLReader();
	parser.setContentHandler(new XSSFParserHandler());

	this.parseExcelRowMapper = parseExcelRowMapper;

	XSSFReader.SheetIterator iter = (XSSFReader.SheetIterator) xssfReader.getSheetsData();
	while (iter.hasNext()) {
		curRow = 0;
		sheetIndex++;
		InputStream sheet = iter.next();
		sheetName = iter.getSheetName();
		InputSource sheetSource = new InputSource(sheet);
		parser.parse(sheetSource);
		sheet.close();
	}

}
 
开发者ID:bsteker,项目名称:bdf2,代码行数:26,代码来源:XSSFParser.java

示例3: process

import org.apache.poi.xssf.eventusermodel.XSSFReader; //导入方法依赖的package包/类
/**
 * Initiates the processing of the XLS workbook file to CSV.
 *
 * @throws IOException
 * @throws OpenXML4JException
 * @throws ParserConfigurationException
 * @throws SAXException
 */
public List<String> process() throws IOException, OpenXML4JException, ParserConfigurationException, SAXException {
	ReadOnlySharedStringsTable strings = new ReadOnlySharedStringsTable(this.xlsxPackage);
	XSSFReader xssfReader = new XSSFReader(this.xlsxPackage);
	StylesTable styles = xssfReader.getStylesTable();
	XSSFReader.SheetIterator iter = (XSSFReader.SheetIterator) xssfReader.getSheetsData();
	int index = 0;
	while (iter.hasNext()) {
		if(blankRowNum == 10)break;
		InputStream stream = iter.next();
		String sheetName = iter.getSheetName();
		results.add(ExcelValidator.SHEET_NAME_PREFIX + sheetName);
		processSheet(styles, strings, new SheetToCSV(), stream);
		stream.close();
		++index;
	}

	return results;
}
 
开发者ID:vakinge,项目名称:jeesuite-libs,代码行数:27,代码来源:XLSX2CSV.java

示例4: parseXlsxFileAndWriteTmxBody

import org.apache.poi.xssf.eventusermodel.XSSFReader; //导入方法依赖的package包/类
public void parseXlsxFileAndWriteTmxBody(String fileName, AbstractWriter tmxWriter, IProgressMonitor monitor)
		throws ParserConfigurationException, SAXException, IOException, OpenXML4JException {
	this.tmxWriter = tmxWriter;
	this.monitor = monitor;
	File file = new File(fileName);
	long length = file.length();
	monitor.beginTask("", countTotal(length));
	OPCPackage p = OPCPackage.open(fileName, PackageAccess.READ);
	ReadOnlySharedStringsTable strings = new ReadOnlySharedStringsTable(p);
	XSSFReader xssfReader = new XSSFReader(p);
	XSSFReader.SheetIterator iter = (XSSFReader.SheetIterator) xssfReader.getSheetsData();
	try {
		while (iter.hasNext()) {
			InputStream stream = iter.next();
			parse(stream, strings, tmxWriter);
			stream.close();
			// 目前只处理第一个sheet
			break;
		}
	} finally {
		p.close();
	}

	monitor.done();
}
 
开发者ID:heartsome,项目名称:translationstudio8,代码行数:26,代码来源:Xlsx2TmxHelper.java

示例5: readRows

import org.apache.poi.xssf.eventusermodel.XSSFReader; //导入方法依赖的package包/类
public void readRows(IProgressMonitor monitor) throws ParserConfigurationException, SAXException, IOException, OpenXML4JException {
	monitor.beginTask("", 10);
	monitor.worked(1);
	OPCPackage p = OPCPackage.open(xlsxFile, PackageAccess.READ);
	ReadOnlySharedStringsTable shareString = new ReadOnlySharedStringsTable(p);
	XSSFReader xssfReader = new XSSFReader(p);
	XSSFReader.SheetIterator iter = (XSSFReader.SheetIterator) xssfReader.getSheetsData();
	try {
		while (iter.hasNext()) {
			InputStream stream = iter.next();
			readCells(stream, shareString, new SubProgressMonitor(monitor, 9));
			stream.close();
			// 目前只处理第一个sheet
			break;
		}
	} finally {
		p.close();
		monitor.done();
	}
}
 
开发者ID:heartsome,项目名称:translationstudio8,代码行数:21,代码来源:XlsxRowReader.java

示例6: importSchema

import org.apache.poi.xssf.eventusermodel.XSSFReader; //导入方法依赖的package包/类
private SchemaSheetInformation importSchema(XSSFReader r,StylesTable styles ,ReadOnlySharedStringsTable sst ){
	try {
		XSSFReader.SheetIterator it = (XSSFReader.SheetIterator) r.getSheetsData();
		while(it.hasNext()) {
			try(InputStream sheet = it.next()){
				String name = it.getSheetName();
				if(Strings.equalsStd(PoiIO.SCHEMA_SHEET_NAME, name)){
					InputSource sheetSource = new InputSource(sheet);
					ReadSchemaSheet readSchemaSheet = new ReadSchemaSheet();
					parseSheet(styles, sst, sheetSource, readSchemaSheet);
					return readSchemaSheet.finish(report);
				}	
			}
		}	
	} catch (Exception e) {
		throw new RuntimeException(e);
	}

	return null;
}
 
开发者ID:PGWelch,项目名称:com.opendoorlogistics,代码行数:21,代码来源:XmlParserLoader.java

示例7: readSheet

import org.apache.poi.xssf.eventusermodel.XSSFReader; //导入方法依赖的package包/类
@Override
public void readSheet(int[] indexs) throws IOException, OpenXML4JException,
		SAXException {
	if (pkg == null) {
		throw new NullPointerException("OPCPackage is null");
	}
	//ImmutableCollection<Integer> sheetSelect=
	ImmutableSet.Builder<Integer> build =ImmutableSet.builder();
	for (int i : indexs) {
		if(i<0){
			throw new IllegalArgumentException("index of sheet is a number greater than 0");
		}else{
			build.add(i);
		}
	}
	ImmutableSet<Integer> setSheets = build.build();
		XSSFReader xssfReader = new XSSFReader(pkg);
	XSSFReader.SheetIterator sheets = (XSSFReader.SheetIterator) xssfReader
			.getSheetsData();
	ExcelReadOnlySharedStringsTable strings = new ExcelReadOnlySharedStringsTable(
			pkg);
	int sheetIndex = 0;
	
	ExcelXSSFSheetXMLHandler sheetXMLHandler = new ExcelXSSFSheetXMLHandler(
			xssfReader.getStylesTable(), strings, handler, false);
	// 是不按照格式化输出字符
	sheetXMLHandler.ignoreNumFormat(ignoreNumFormat);
	getParser().setContentHandler(sheetXMLHandler);
	while (sheets.hasNext()) {
		try (InputStream sheet = sheets.next()) {
			String name = sheets.getSheetName();
			if (!setSheets.contains(sheetIndex)) {
				sheetIndex++;
				continue;
			}
			
			
			excelReader.startSheet(sheetIndex, name);
			InputSource sheetSource = new InputSource(sheet);
			
			try {
				getParser().parse(sheetSource);
			} catch (SAXException e) {
				if (e instanceof BingSaxReadStopException) {
					
				} else {
					throw e;
				}
			}
			excelReader.endSheet(sheetIndex, name);
			sheetIndex++;
		}
	}
	excelReader.endWorkBook();
	pkg.revert();
}
 
开发者ID:bingyulei007,项目名称:bingexcel,代码行数:57,代码来源:DefaultXSSFSaxHandler.java

示例8: process

import org.apache.poi.xssf.eventusermodel.XSSFReader; //导入方法依赖的package包/类
/**
 * 开始解析Excel文档
 *
 * @throws ReadExcelException
 */
public void process() throws ReadExcelException {
    try {
        ReadOnlySharedStringsTable strings = new ReadOnlySharedStringsTable(this.xlsxPackage);
        XSSFReader xssfReader = new XSSFReader(this.xlsxPackage);
        StylesTable styles = xssfReader.getStylesTable();
        XSSFReader.SheetIterator iter = (XSSFReader.SheetIterator) xssfReader.getSheetsData();
        while (iter.hasNext()) {
            //初始化数据
            this.initDataPerSheet();
            InputStream stream = iter.next();
            this.processSheet(styles, strings, this, stream);
            stream.close();
        }
        //解析完后,判断用户是否设置了limit,若设置了执行以下操作
        if (this.limit > 0) {
            if (!this.datas.isEmpty()) {
                if (this.callback != null) {
                    //若数据不为空且回调函数被设置,则调用回调函数
                    this.callback.callback(this.currentRowInSheet, this.currentSheetInExcel, this.realRowInSheet,
                            this.realRowInExcel, this.allSheetInExcel, this.titles, this.columns, this.datas);
                }
                this.datas.clear();
            }
        }
    } catch (Exception e) {
        throw new ReadExcelException(e.getMessage());
    }
}
 
开发者ID:FlyingHe,项目名称:UtilsMaven,代码行数:34,代码来源:XLSXReader.java

示例9: getSheetForParsing

import org.apache.poi.xssf.eventusermodel.XSSFReader; //导入方法依赖的package包/类
/**
 * Get the sheet that should be parsed
 * @param options The options
 * @param iter The sheet iterator
 * @return A sheet that matches the name if the sheet name is provided
 */
private InputStream getSheetForParsing(ExcelSourceOptions<R> options, XSSFReader.SheetIterator iter) {
    while(iter.hasNext()){
        InputStream inputStream = iter.next();
        final String sheetName = iter.getSheetName();
        if(options.getSheetName() == null){
            return inputStream;
        }else{
            if( sheetName.equals(options.getSheetName())){
                return inputStream;
            }
        }
    }
    throw new DataFrameException("No sheet found for that matched configured sheet " + options.getSheetName());
}
 
开发者ID:zavtech,项目名称:morpheus-core,代码行数:21,代码来源:ExcelSource.java

示例10: loadData

import org.apache.poi.xssf.eventusermodel.XSSFReader; //导入方法依赖的package包/类
@Override
public void loadData(List<Tuple<String, File>> files, Importer importer) throws InvalidFileException, IOException {
  try {
    RowCellHandler rowCellHandler = makeRowCellHandler(importer);
    SAXParserFactory saxFactory = SAXParserFactory.newInstance();
    saxFactory.setNamespaceAware(true);
    for (Tuple<String, File> file : files) {
      OPCPackage pkg = OPCPackage.open(file.getRight().getPath());
      XSSFReader xssfReader = new XSSFReader(pkg);

      final SharedStringsTable sharedStringsTable = xssfReader.getSharedStringsTable();
      XSSFReader.SheetIterator worksheets = (XSSFReader.SheetIterator) xssfReader.getSheetsData();

      while (worksheets.hasNext()) {
        final InputStream sheet = worksheets.next();

        XMLReader sheetParser = saxFactory.newSAXParser().getXMLReader();
        sheetParser.setContentHandler(new SheetXmlParser(sharedStringsTable, rowCellHandler));

        rowCellHandler.start(worksheets.getSheetName());
        sheetParser.parse(new InputSource(sheet));
        rowCellHandler.finish();
      }
    }
  } catch (SAXException | OpenXML4JException | ParserConfigurationException e) {
    throw new InvalidFileException("Not a valid Excel file", e);
  }
}
 
开发者ID:HuygensING,项目名称:timbuctoo,代码行数:29,代码来源:XlsxLoader.java

示例11: process

import org.apache.poi.xssf.eventusermodel.XSSFReader; //导入方法依赖的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.xssf.eventusermodel.XSSFReader.SheetIterator方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。