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


Java XSSFReader.getStylesTable方法代码示例

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


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

示例1: unmarshal

import org.apache.poi.xssf.eventusermodel.XSSFReader; //导入方法依赖的package包/类
@Override
@SuppressWarnings("unchecked")
public <T> List<T> unmarshal(Class<T> type) {
    try (OPCPackage open = OPCPackage.open(poijiFile.file())) {

        ReadOnlySharedStringsTable readOnlySharedStringsTable = new ReadOnlySharedStringsTable(open);
        XSSFReader xssfReader = new XSSFReader(open);
        StylesTable styles = xssfReader.getStylesTable();

        SheetIterator iter = (SheetIterator) xssfReader.getSheetsData();
        int index = 0;

        while (iter.hasNext()) {
            try (InputStream stream = iter.next()) {
                if (index == options.sheetIndex()) {
                    return processSheet(styles, readOnlySharedStringsTable, type, stream);
                }
            }
            ++index;
        }
        return new ArrayList<>();
    } catch (SAXException | IOException | OpenXML4JException e) {
        throw new PoijiException("Problem occurred while reading data", e);
    }
}
 
开发者ID:ozlerhakan,项目名称:poiji,代码行数:26,代码来源:XSSFUnmarshaller.java

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

示例3: processAll

import org.apache.poi.xssf.eventusermodel.XSSFReader; //导入方法依赖的package包/类
private void processAll(OPCPackage pkg)
		throws IOException, OpenXML4JException, InvalidFormatException, SAXException {
	XSSFReader xssfReader = new XSSFReader(pkg);
	mStylesTable = xssfReader.getStylesTable();
	SharedStringsTable sst = xssfReader.getSharedStringsTable();
	XMLReader parser = this.fetchSheetParser(sst);
	Iterator<InputStream> sheets = xssfReader.getSheetsData();
	while (sheets.hasNext()) {
		mCurrentRowIndex = 0;
		mSheetIndex++;
		InputStream sheet = sheets.next();
		InputSource sheetSource = new InputSource(sheet);
		parser.parse(sheetSource);
		sheet.close();
	}
	pkg.close();
}
 
开发者ID:wuwz,项目名称:ExcelKit,代码行数:18,代码来源:XlsxReader.java

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

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

示例6: LowMemXlsReader

import org.apache.poi.xssf.eventusermodel.XSSFReader; //导入方法依赖的package包/类
public LowMemXlsReader( InputStream stream ) throws IOException {
	log.debug( "reading with lo-mem xls reader" );
	sharedStrings = new ArrayList<>();
	try {
		pkg = OPCPackage.open( stream );
		reader = new XSSFReader( pkg );

		styles = reader.getStylesTable();

		sheetNameIdLkp = readSheetInfo( reader );
		populateSharedStrings( reader );
	}
	catch ( OpenXML4JException e ) {
		throw new IOException( "unexpected error" + e.getLocalizedMessage(), e );
	}
}
 
开发者ID:Ostrich-Emulators,项目名称:semtool,代码行数:17,代码来源:LowMemXlsReader.java

示例7: XlsxSheetToRowsHandler

import org.apache.poi.xssf.eventusermodel.XSSFReader; //导入方法依赖的package包/类
public XlsxSheetToRowsHandler(XlsxRowCallback callback, XSSFReader xssfReader, ExcelConfiguration configuration)
        throws Exception {
    _callback = callback;
    _configuration = configuration;

    _sharedStringTable = xssfReader.getSharedStringsTable();
    _stylesTable = xssfReader.getStylesTable();

    _value = new StringBuilder();
    _style = new StyleBuilder();
    _rowValues = new ArrayList<String>();
    _styles = new ArrayList<Style>();
    _rowNumber = -1;
    _inCell = false;
    _inFormula = false;
}
 
开发者ID:apache,项目名称:metamodel,代码行数:17,代码来源:XlsxSheetToRowsHandler.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: setUp

import org.apache.poi.xssf.eventusermodel.XSSFReader; //导入方法依赖的package包/类
@Before
public void setUp() throws Exception {
    OPCPackage pkg = OPCPackage.open(StreamingSheetTest.class.getResourceAsStream("../dates.xlsx"));
    XSSFReader reader = new XSSFReader(pkg);

    SharedStringsTable sst = reader.getSharedStringsTable();
    StylesTable styles = reader.getStylesTable();

    Iterator<InputStream> iter = reader.getSheetsData();
    XMLEventReader parser = XMLInputFactory.newInstance().createXMLEventReader(iter.next());
    final StreamingSheetReader streamingSheetReader = new StreamingSheetReader(sst, styles, parser, 10);
    streamingSheet = new StreamingSheet("name", streamingSheetReader);
}
 
开发者ID:Talend,项目名称:data-prep,代码行数:14,代码来源:StreamingSheetTest.java

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

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

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

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

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

示例15: streamSheet

import org.apache.poi.xssf.eventusermodel.XSSFReader; //导入方法依赖的package包/类
/**
 * Call
 * {@link #processSheet(org.apache.poi.xssf.model.StylesTable, org.apache.poi.xssf.eventusermodel.ReadOnlySharedStringsTable, java.io.InputStream, int)}
 * with the given stream.
 *
 * @param streamer
 * @param stream
 * @param sheetNumber
 * @throws IOException
 * @throws ParserConfigurationException
 * @throws InvalidFormatException
 * @throws SAXException
 */
private void streamSheet(XSSFReader streamer, InputStream stream, int sheetNumber) throws IOException, ParserConfigurationException, InvalidFormatException, SAXException {
    ReadOnlySharedStringsTable sharedStringsTable = new ReadOnlySharedStringsTable(pack);
    StylesTable styles = streamer.getStylesTable();
    dataCallback.onSheetBegin();
    processSheet(styles, sharedStringsTable, stream, sheetNumber);
    dataCallback.onSheetEnd();
    stream.close();
}
 
开发者ID:iMDT,项目名称:xlsx-io,代码行数:22,代码来源:XlsxStreamer.java


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