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


Java XSSFReader.getSheet方法代码示例

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


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

示例1: processBySheet

import org.apache.poi.xssf.eventusermodel.XSSFReader; //导入方法依赖的package包/类
private void processBySheet(int sheetIndex, OPCPackage pkg)
		throws IOException, OpenXML4JException, InvalidFormatException, SAXException {
	XSSFReader r = new XSSFReader(pkg);
	SharedStringsTable sst = r.getSharedStringsTable();

	XMLReader parser = fetchSheetParser(sst);

	// rId2 found by processing the Workbook
	// 根据 rId# 或 rSheet# 查找sheet
	InputStream sheet = r.getSheet("rId" + (sheetIndex + 1));
	mSheetIndex++;
	InputSource sheetSource = new InputSource(sheet);
	parser.parse(sheetSource);
	sheet.close();
	pkg.close();
}
 
开发者ID:wuwz,项目名称:ExcelKit,代码行数:17,代码来源:XlsxReader.java

示例2: processOneSheet

import org.apache.poi.xssf.eventusermodel.XSSFReader; //导入方法依赖的package包/类
public void processOneSheet(String filename, int sheetId) throws Exception {
	OPCPackage pkg = OPCPackage.open(filename);
	XSSFReader r = new XSSFReader(pkg);
	SharedStringsTable sst = r.getSharedStringsTable();

	XMLReader parser = fetchSheetParser(sst);

	// rId2 found by processing the Workbook
	// 根据 rId# 或 rSheet# 查找sheet
	InputStream sheet2 = r.getSheet("rId" + sheetId);
	sheetIndex++;
	InputSource sheetSource = new InputSource(sheet2);
	parser.parse(sheetSource);
	sheet2.close();
	pkg.close();
}
 
开发者ID:RayleighChen,项目名称:Improve,代码行数:17,代码来源:XxlsAbstract.java

示例3: readOneSheet

import org.apache.poi.xssf.eventusermodel.XSSFReader; //导入方法依赖的package包/类
/** 
 * 读取第一个工作簿的入口方法 
 * @param path 
 */  
public List<?> readOneSheet(InputStream input,String excelType) throws Exception {  
    OPCPackage pkg = OPCPackage.open(input);    
    XSSFReader r = new XSSFReader(pkg);  
    SharedStringsTable sst = r.getSharedStringsTable();  
    
    if(excelType.equals(Constant.ENITY_TYPE_ROLEPERSIONAL)){
    	
    	lists = new ArrayList<AuthRoleUser>();
    }
    
    XMLReader parser = fetchSheetParser(sst);  
          
    InputStream sheet = r.getSheet("rId1");  
  
    InputSource sheetSource = new InputSource(sheet);  
    parser.parse(sheetSource);  
    
    
    if(excelType.equals(Constant.ENITY_TYPE_ROLEPERSIONAL)){

    	return lists;
    }
    sheet.close();        
    return lists;
}
 
开发者ID:lz84,项目名称:bachelor,代码行数:30,代码来源:ParseBigDatasExcel.java

示例4: processOneSheet

import org.apache.poi.xssf.eventusermodel.XSSFReader; //导入方法依赖的package包/类
/**
 * 只遍历一个电子表格,其中sheetId为要遍历的sheet索引,从1开始,1-3
 * 
 * @param filename
 * @param sheetId
 * @throws Exception
 */
public void processOneSheet(String filename, int sheetId) throws Exception {
	OPCPackage pkg = OPCPackage.open(filename);
	XSSFReader r = new XSSFReader(pkg);
	SharedStringsTable sst = r.getSharedStringsTable();
	XMLReader parser = fetchSheetParser(sst);

	// 根据 rId# 或 rSheet# 查找sheet
	InputStream sheet2 = r.getSheet("rId" + sheetId);
	sheetIndex++;
	InputSource sheetSource = new InputSource(sheet2);
	parser.parse(sheetSource);
	sheet2.close();
}
 
开发者ID:iBase4J,项目名称:iBase4J-Common,代码行数:21,代码来源:Excel2007Reader.java

示例5: StAXBasedParser

import org.apache.poi.xssf.eventusermodel.XSSFReader; //导入方法依赖的package包/类
/**
 * Create instance
 * @param inputStream sheet input stream
 * @param pluginConfig config options
 * @param writer {@link VectorContainerWriter} for writing values into vectors.
 * @param managedBuf Workspace buffer.
 */
public StAXBasedParser(final InputStream inputStream, final ExcelFormatPluginConfig pluginConfig,
                       final VectorContainerWriter writer, final ArrowBuf managedBuf,
                       final HashSet<String> columnsToProject) throws Exception {
  pkgInputStream = OPCPackage.open(inputStream);
  this.writer = writer.rootAsMap();
  this.managedBuf = managedBuf;

  final XSSFReader xssfReader = new XSSFReader(pkgInputStream);

  // Find the sheet id of the given sheet name in workbook
  try (final InputStream wbInputStream = xssfReader.getWorkbookData()) {
    final String sheetId = ExcelUtil.getSheetId(wbInputStream, pluginConfig.sheet);
    if (sheetId == null) {
      throw new SheetNotFoundException();
    }

    // Open the InputStream for sheet
    sheetInputStream = xssfReader.getSheet(sheetId);
  }


  // WARNING: XSSFReader can actually return null instances of sst and styles
  sst = xssfReader.getSharedStringsTable();
  styles = checkNotNull(xssfReader.getStylesTable(), "Expected a valid styles table instance");

  init(pluginConfig.extractHeader, pluginConfig.hasMergedCells);

  this.columnsToProject = columnsToProject;
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:37,代码来源:StAXBasedParser.java

示例6: processSheet

import org.apache.poi.xssf.eventusermodel.XSSFReader; //导入方法依赖的package包/类
public void processSheet(InputStream inputStream, DataTable dataTable, PrintWriter tempOut) throws Exception {
    dbglog.info("entering processSheet");
    OPCPackage pkg = OPCPackage.open(inputStream);
    XSSFReader r = new XSSFReader(pkg);
    SharedStringsTable sst = r.getSharedStringsTable();

    XMLReader parser = fetchSheetParser(sst, dataTable, tempOut);

    // rId2 found by processing the Workbook
    // Seems to either be rId# or rSheet#
    InputStream sheet1 = r.getSheet("rId1");
    InputSource sheetSource = new InputSource(sheet1);
    parser.parse(sheetSource);
    sheet1.close();
}
 
开发者ID:pengchengluo,项目名称:Peking-University-Open-Research-Data-Platform,代码行数:16,代码来源:XLSXFileReader.java

示例7: run

import org.apache.poi.xssf.eventusermodel.XSSFReader; //导入方法依赖的package包/类
public void run() throws IOException, SAXException, OpenXML4JException {
	OPCPackage pkg = null;
	XSSFWorkbook wb = null;
	InputStream is = null;
	try {
		pkg = OPCPackage.open(file);
		wb = new XSSFWorkbook(file);
		XSSFReader r = new XSSFReader(pkg);
		SharedStringsTable sst = r.getSharedStringsTable();

		XSSFSheet sheet = wb.getSheet(sheetName);
		String rId = wb.getRelationId(sheet);

		is = r.getSheet(rId);
		InputSource sheetSource = new InputSource(is);
		XMLReader parser = XMLReaderFactory.createXMLReader("com.sun.org.apache.xerces.internal.parsers.SAXParser");
		handler = new SheetHandler(sst);
		parser.setContentHandler(handler);
		parser.parse(sheetSource);

		// last line (consider header line for offset)
		if (++handler.lineIndex > skip + offset + 1) {
			Log log = new SimpleLog(new Date(), logger == null ? null : logger.getFullName(), handler.data);
			pipe.onLog(logger, log);
			handler.outputCount++;
		}

		handler.totalCount++;
	} catch (SAXException e) {
		if (e.getMessage() == null || !e.getMessage().contains("max limit"))
			throw e;

	} finally {
		Io.ensureClose(is);
		Io.ensureClose(pkg);
		Io.ensureClose(wb);
	}
}
 
开发者ID:araqne,项目名称:logdb,代码行数:39,代码来源:XlsxExtractor.java

示例8: generateXSSFSpreadsheetMetadata

import org.apache.poi.xssf.eventusermodel.XSSFReader; //导入方法依赖的package包/类
public String generateXSSFSpreadsheetMetadata(URI baseRDFURI, byte[] spreadsheetData)
{
    logger.log(Level.FINE, "Generate XSSF Spreadsheet Metadata - Streamed (Data)");

    try
    {
        InputStream xssfWorkbookInputStream = new ByteArrayInputStream(spreadsheetData);
        OPCPackage  opcPackage              = OPCPackage.open(xssfWorkbookInputStream);
        XSSFReader  xssfReader              = new XSSFReader(opcPackage);
        StylesTable stylesTable             = xssfReader.getStylesTable();

        UUID     workbookUUID = UUID.randomUUID();
        Workbook workbook     = new Workbook(baseRDFURI.resolve('#' + workbookUUID.toString()), new HashMap<String, Sheet>());

        XMLReader      workbookParser  = XMLReaderFactory.createXMLReader("org.apache.xerces.parsers.SAXParser");
        ContentHandler workbookHandler = new WorkbookHandler(baseRDFURI, workbook);
        workbookParser.setContentHandler(workbookHandler);

        InputStream workbookInputStream = xssfReader.getWorkbookData();
        InputSource workbookSource = new InputSource(workbookInputStream);
        workbookParser.parse(workbookSource);
        workbookInputStream.close();

        for (Sheet sheet: workbook.sheets.values())
        {
            XMLReader      sheetParser  = XMLReaderFactory.createXMLReader("org.apache.xerces.parsers.SAXParser");
            ContentHandler sheetHandler = new SheetHandler(baseRDFURI, stylesTable, sheet);
            sheetParser.setContentHandler(sheetHandler);

            InputStream sheetInputStream = xssfReader.getSheet(sheet.refId);
            InputSource sheetSource = new InputSource(sheetInputStream);
            sheetParser.parse(sheetSource);
            sheetInputStream.close();
        }
        xssfWorkbookInputStream.close();

        XMLReader      sharedStringsParser  = XMLReaderFactory.createXMLReader("org.apache.xerces.parsers.SAXParser");
        ContentHandler sharedStringsHandler = new SharedStringsHandler(workbook);
        sharedStringsParser.setContentHandler(sharedStringsHandler);

        InputStream sharedStringsInputStream = xssfReader.getSharedStringsData();
        InputSource sharedStringsSource = new InputSource(sharedStringsInputStream);
        sharedStringsParser.parse(sharedStringsSource);
        sharedStringsInputStream.close();

        StringBuffer rdfText = new StringBuffer();
        generateXSSFWorkbookMetadata(rdfText, workbook);

        return rdfText.toString();
    }
    catch (Throwable throwable)
    {
        logger.log(Level.WARNING, "Problem Generating during XSSF Spreadsheet Metadata Scan (Data)", throwable);

        return null;
    }
}
 
开发者ID:arjuna-technologies,项目名称:Metadata_Utilities,代码行数:58,代码来源:StreamedXSSFSpreadsheetMetadataGenerator.java

示例9: buildColumns

import org.apache.poi.xssf.eventusermodel.XSSFReader; //导入方法依赖的package包/类
private void buildColumns(final MutableTable table, final String relationshipId, final XSSFReader xssfReader)
        throws Exception {
    final InputStream sheetData = xssfReader.getSheet(relationshipId);

    final XlsxRowCallback rowCallback = new XlsxRowCallback() {
        @Override
        public boolean row(int rowNumber, List<String> values, List<Style> styles) {
            final int columnNameLineNumber = _configuration.getColumnNameLineNumber();
            final boolean hasColumnNameLine = columnNameLineNumber != ExcelConfiguration.NO_COLUMN_NAME_LINE;

            if (hasColumnNameLine) {
                final int zeroBasedLineNumber = columnNameLineNumber - 1;
                if (rowNumber < zeroBasedLineNumber) {
                    // jump to read the next line
                    return true;
                }
            }

            final ColumnNamingStrategy columnNamingStrategy = _configuration.getColumnNamingStrategy();
            try (ColumnNamingSession session = columnNamingStrategy.startColumnNamingSession()) {
                for (int i = 0; i < values.size(); i++) {
                    final String intrinsicColumnName = hasColumnNameLine ? values.get(i) : null;
                    final String columnName = session.getNextColumnName(new ColumnNamingContextImpl(table,
                            intrinsicColumnName, i));

                    if (!(_configuration.isSkipEmptyColumns() && values.get(i) == null)) {
                        table.addColumn(new MutableColumn(columnName, ColumnType.STRING, table, i, true));
                    }
                }
            }

            // now we're done, no more reading
            return false;
        }
    };
    final XlsxSheetToRowsHandler handler = new XlsxSheetToRowsHandler(rowCallback, xssfReader, _configuration);

    final XMLReader sheetParser = ExcelUtils.createXmlReader();
    sheetParser.setContentHandler(handler);
    try {
        sheetParser.parse(new InputSource(sheetData));
    } catch (XlsxStopParsingException e) {
        logger.debug("Parsing stop signal thrown");
    } finally {
        FileHelper.safeClose(sheetData);
    }
}
 
开发者ID:apache,项目名称:metamodel,代码行数:48,代码来源:XlsxSpreadsheetReaderDelegate.java

示例10: StaxPoiSheet

import org.apache.poi.xssf.eventusermodel.XSSFReader; //导入方法依赖的package包/类
public StaxPoiSheet( XSSFReader reader, String sheetName, String sheetID )
    throws InvalidFormatException, IOException, XMLStreamException {
  this.sheetName = sheetName;
  xssfReader = reader;
  sheetId = sheetID;
  sst = reader.getSharedStringsTable();
  styles = reader.getStylesTable();
  sheetStream = reader.getSheet( sheetID );
  XMLInputFactory factory = XMLInputFactory.newInstance();
  sheetReader = factory.createXMLStreamReader( sheetStream );
  headerRow = new ArrayList<String>();
  while ( sheetReader.hasNext() ) {
    int event = sheetReader.next();
    if ( event == XMLStreamConstants.START_ELEMENT && sheetReader.getLocalName().equals( "dimension" ) ) {
      String dim = sheetReader.getAttributeValue( null, "ref" );
      // empty sheets have dimension with no range
      if ( StringUtils.contains( dim, ':' ) ) {
        dim = dim.split( ":" )[1];
        numRows = StaxUtil.extractRowNumber( dim );
        numCols = StaxUtil.extractColumnNumber( dim );
      }
    }
    if ( event == XMLStreamConstants.START_ELEMENT && sheetReader.getLocalName().equals( "row" ) ) {
      currentRow = Integer.parseInt( sheetReader.getAttributeValue( null, "r" ) );
      firstRow = currentRow;

      // calculate the number of columns in the header row
      while ( sheetReader.hasNext() ) {
        event = sheetReader.next();
        if ( event == XMLStreamConstants.END_ELEMENT && sheetReader.getLocalName().equals( "row" ) ) {
          // if the row has ended, break the inner while loop
          break;
        }
        if ( event == XMLStreamConstants.START_ELEMENT && sheetReader.getLocalName().equals( "c" ) ) {
          String attributeValue = sheetReader.getAttributeValue( null, "t" );
          if ( attributeValue != null && attributeValue.equals( "s" ) ) {
            // only if the type of the cell is string, we continue
            while ( sheetReader.hasNext() ) {
              event = sheetReader.next();
              if ( event == XMLStreamConstants.START_ELEMENT && sheetReader.getLocalName().equals( "v" ) ) {
                int idx = Integer.parseInt( sheetReader.getElementText() );
                String content = new XSSFRichTextString( sst.getEntryAt( idx ) ).toString();
                headerRow.add( content );
                break;
              }
            }
          } else {
            break;
          }
        }
      }
      // we have parsed the header row
      break;
    }
  }
}
 
开发者ID:pentaho,项目名称:pentaho-kettle,代码行数:57,代码来源:StaxPoiSheet.java

示例11: readSheet

import org.apache.poi.xssf.eventusermodel.XSSFReader; //导入方法依赖的package包/类
private void readSheet(XSSFReader reader, String sheetId) throws Exception {
    sh = reader.getSheet(sheetId);
    InputSource is = new InputSource(sh);
    XMLReader parser = super.createParser();
    parser.parse(is);            
}
 
开发者ID:Depter,项目名称:JRLib,代码行数:7,代码来源:XlsxTableReader.java


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