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


Java XSSFReader.getWorkbookData方法代码示例

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


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

示例1: 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

示例2: consume

import org.apache.poi.xssf.eventusermodel.XSSFReader; //导入方法依赖的package包/类
public void consume(File data)
{
    try
    {
        Map<String, String> refIdMap = new HashMap<String, String>();

        OPCPackage         opcPackage         = OPCPackage.open(data);
        XSSFReader         xssfReader         = new XSSFReader(opcPackage);
        SharedStringsTable sharedStringsTable = xssfReader.getSharedStringsTable();

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

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

        XMLReader      sheetParser  = XMLReaderFactory.createXMLReader("org.apache.xerces.parsers.SAXParser");
        ContentHandler sheetHandler = new SheetHandler(sharedStringsTable);
        sheetParser.setContentHandler(sheetHandler);

        Iterator<InputStream> sheetInputStreamIterator = xssfReader.getSheetsData();
        while (sheetInputStreamIterator.hasNext())
        {
            InputStream sheetInputStream = sheetInputStreamIterator.next();
            InputSource sheetSource = new InputSource(sheetInputStream);
            sheetParser.parse(sheetSource);
            sheetInputStream.close();
        }
    }
    catch (Throwable throwable)
    {
        logger.log(Level.WARNING, "Problem processing XSSF file \"" + data.getAbsolutePath() + "\"", throwable);
    }
}
 
开发者ID:arjuna-technologies,项目名称:Apache-POI_DataBroker_PlugIn,代码行数:38,代码来源:XSSFRowToJSONDataProcessor.java

示例3: processExcelRequest

import org.apache.poi.xssf.eventusermodel.XSSFReader; //导入方法依赖的package包/类
/**
 * Method used to process the whole request.
 * 
 * @param resID unique ID of resource
 * @param requestType designator of URI scheme
 * @param sheetName name of sheet
 * @param reference table, column, row or cell reference
 * @param xssfReader package reader of POI
 * @return list of values as {@code ValueExchangeExt}
 * @throws EncodingException
 * @throws EOFException
 * @throws EntityException
 * @throws InvalidFormatException not an OOXML file
 * @throws ParseException error during parsing
 * @throws IOException can't open file
 * @throws XPathParseException error during parsing
 * @throws XPathEvalException error during XPath evaluation
 * @throws NavException error during XML navigation
 */
private ValueExchangeExt processExcelRequest(String resID, String requestType,
        String sheetName, String reference, XSSFReader xssfReader) throws EncodingException,
        EOFException, EntityException, InvalidFormatException, ParseException, IOException,
        XPathParseException, XPathEvalException, NavException {
    ValueExchangeExt valList = new ValueExchangeExt();

    this.sstData = new SharedStringsData(xssfReader);
    StylesTable styles = xssfReader.getStylesTable();
    InputStream workBook = xssfReader.getWorkbookData();

    LinkedHashMap<String, InputStream> sheets = getSheets(workBook, xssfReader, sheetName);

    String xpathExp = buildXPathExp(reference);
    Boolean allSheets = sheetName.equals("*");

    if (allSheets) {
        valList.setBaseURI("/" + resID + "/" + requestType + "/");
    } else {
        valList.setBaseURI("/" + resID + "/" + requestType + "/"
                + URLEncoder.encode(sheetName, "US-ASCII") + "/");
    }

    // iterate sheets for evaluation
    for (String curSheetName : sheets.keySet()) {
        String pathPrefix = "";
        if (allSheets)
            pathPrefix = URLEncoder.encode(curSheetName, "US-ASCII");
        InputStream sheetIS = sheets.get(curSheetName);
        byte[] sheet = IOUtils.toByteArray(sheetIS);
        // evaluate XPath expression for current sheet
        valList.addValues(evalSheet(sheet, xpathExp, reference, styles, pathPrefix));
    }
    return valList;
}
 
开发者ID:chsatgithub,项目名称:PANDA-DEEPLINKING,代码行数:54,代码来源:DataExcelVtdResource.java

示例4: buildTables

import org.apache.poi.xssf.eventusermodel.XSSFReader; //导入方法依赖的package包/类
private void buildTables(final XSSFReader xssfReader, final XlsxWorkbookToTablesHandler workbookToTables)
        throws Exception {
    final InputStream workbookData = xssfReader.getWorkbookData();
    final XMLReader workbookParser = ExcelUtils.createXmlReader();
    workbookParser.setContentHandler(workbookToTables);
    workbookParser.parse(new InputSource(workbookData));
    FileHelper.safeClose(workbookData);
}
 
开发者ID:apache,项目名称:metamodel,代码行数:9,代码来源:XlsxSpreadsheetReaderDelegate.java

示例5: readReader

import org.apache.poi.xssf.eventusermodel.XSSFReader; //导入方法依赖的package包/类
@Override
protected void readReader(XSSFReader reader) throws Exception {
    try {
        wb = reader.getWorkbookData();
        InputSource is = new InputSource(wb);
        XMLReader parser = super.createParser();
        parser.parse(is);
    } finally {
        close();
    }
}
 
开发者ID:Depter,项目名称:JRLib,代码行数:12,代码来源:XlsxWorkbookReader.java

示例6: getSheetId

import org.apache.poi.xssf.eventusermodel.XSSFReader; //导入方法依赖的package包/类
String getSheetId(String sheetName, XSSFReader reader) throws Exception {
    this.sheetName = sheetName;
    try {
        wb = reader.getWorkbookData();
        InputSource is = new InputSource(wb);
        XMLReader parser = XlsxReader.createParser(this);
        parser.parse(is);
        return  sheetId;
    } finally {
        close();
    }
}
 
开发者ID:Depter,项目名称:JRLib,代码行数:13,代码来源:SheetIdReader.java

示例7: 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


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