org.apache.poi.xssf.eventusermodel.XSSFReader Java Examples

The following examples show how to use org.apache.poi.xssf.eventusermodel.XSSFReader. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Excel2007Reader.java    From o2oa with GNU Affero General Public License v3.0 7 votes vote down vote up
/**只遍历一个电子表格,其中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();
}
 
Example #2
Source File: Excel2007Reader.java    From o2oa with GNU Affero General Public License v3.0 7 votes vote down vote up
/**
 * 遍历工作簿中所有的电子表格
 * @param filename
 * @param fileKey 
 * @throws Exception
 */
public void process( String filename ) throws Exception {
	OPCPackage pkg = OPCPackage.open( filename );
	XSSFReader r = new XSSFReader(pkg);
	SharedStringsTable sst = r.getSharedStringsTable();
	XMLReader parser = fetchSheetParser(sst);
	Iterator<InputStream> sheets = r.getSheetsData();
	while (sheets.hasNext()) {
		curRow = 0;
		sheetIndex++;
		InputStream sheet = sheets.next();
		InputSource sheetSource = new InputSource(sheet);
		parser.parse( sheetSource );
		sheet.close();
	}
	//数据读取完成
}
 
Example #3
Source File: Excel2007Reader.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * 遍历工作簿中所有的电子表格
 * @param is
 * @param fileKey 
 * @throws Exception
 */
public void process( InputStream is ) throws Exception {
	OPCPackage pkg = OPCPackage.open( is );
	XSSFReader r = new XSSFReader(pkg);
	SharedStringsTable sst = r.getSharedStringsTable();
	XMLReader parser = fetchSheetParser(sst);
	Iterator<InputStream> sheets = r.getSheetsData();
	while (sheets.hasNext()) {
		curRow = 0;
		sheetIndex++;
		InputStream sheet = sheets.next();
		InputSource sheetSource = new InputSource(sheet);
		parser.parse( sheetSource );
		sheet.close();
	}
	//数据读取完成
}
 
Example #4
Source File: Excel2007Reader.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * 遍历工作簿中所有的电子表格
 * @param filename
 * @param fileKey 
 * @throws Exception
 */
public void process( String filename ) throws Exception {
	OPCPackage pkg = OPCPackage.open(filename);
	XSSFReader r = new XSSFReader(pkg);
	SharedStringsTable sst = r.getSharedStringsTable();
	XMLReader parser = fetchSheetParser(sst);
	Iterator<InputStream> sheets = r.getSheetsData();
	while (sheets.hasNext()) {
		curRow = 0;
		sheetIndex++;
		InputStream sheet = sheets.next();
		InputSource sheetSource = new InputSource(sheet);
		parser.parse( sheetSource );
		sheet.close();
	}
	//数据读取完成
}
 
Example #5
Source File: SaxExcelReader.java    From myexcel with Apache License 2.0 6 votes vote down vote up
/**
 * Initiates the processing of the XLS workbook file to CSV.
 *
 * @throws IOException  If reading the data from the package fails.
 * @throws SAXException if parsing the XML data fails.
 */
private void process(OPCPackage xlsxPackage) throws IOException, OpenXML4JException, SAXException {
    long startTime = System.currentTimeMillis();
    StringsCache stringsCache = new StringsCache();
    try {
        ReadOnlySharedStringsTable strings = new ReadOnlySharedStringsTable(xlsxPackage, stringsCache);
        XSSFReader xssfReader = new XSSFReader(xlsxPackage);
        XSSFReader.SheetIterator iter = (XSSFReader.SheetIterator) xssfReader.getSheetsData();
        if (readConfig.readAllSheet) {
            while (iter.hasNext()) {
                try (InputStream stream = iter.next()) {
                    processSheet(strings, new XSSFSaxReadHandler<>(result, readConfig), stream);
                }
            }
        } else if (!readConfig.sheetNames.isEmpty()) {
            while (iter.hasNext()) {
                try (InputStream stream = iter.next()) {
                    if (readConfig.sheetNames.contains(iter.getSheetName())) {
                        processSheet(strings, new XSSFSaxReadHandler<>(result, readConfig), stream);
                    }
                }
            }
        } else {
            int index = 0;
            while (iter.hasNext()) {
                try (InputStream stream = iter.next()) {
                    if (readConfig.sheetIndexs.contains(index)) {
                        processSheet(strings, new XSSFSaxReadHandler<>(result, readConfig), stream);
                    }
                    ++index;
                }
            }
        }
    } finally {
        stringsCache.clearAll();
    }
    log.info("Sax import takes {} ms", System.currentTimeMillis() - startTime);
}
 
Example #6
Source File: Xlsx2TmxHelper.java    From tmxeditor8 with GNU General Public License v2.0 6 votes vote down vote up
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();
}
 
Example #7
Source File: Excel2007Reader.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * 遍历工作簿中所有的电子表格
 * @param filename
 * @param fileKey 
 * @throws Exception
 */
public void process( InputStream is ) throws Exception {
	OPCPackage pkg = OPCPackage.open( is );
	XSSFReader r = new XSSFReader(pkg);
	SharedStringsTable sst = r.getSharedStringsTable();
	XMLReader parser = fetchSheetParser(sst);
	Iterator<InputStream> sheets = r.getSheetsData();
	while (sheets.hasNext()) {
		curRow = 0;
		sheetIndex++;
		InputStream sheet = sheets.next();
		InputSource sheetSource = new InputSource(sheet);
		parser.parse( sheetSource );
		sheet.close();
	}
}
 
Example #8
Source File: StaxPoiSheetTest.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
@Test
public void testNullDateCell() throws Exception {
  // cell had null value instead of being null
  final String sheetId = "1";
  final String sheetName = "Sheet 1";
  XSSFReader reader = mockXSSFReader( sheetId, SHEET_DATE_NO_V,
    mockSharedStringsTable( "Some Date" ),
    mockStylesTable(
      Collections.singletonMap( 2, 165 ),
      Collections.singletonMap( 165, "M/D/YYYY" ) ) );
  StaxPoiSheet spSheet = spy( new StaxPoiSheet( reader, sheetName, sheetId ) );
  doReturn( true ).when( spSheet ).isDateCell( any() );
  KCell cell = spSheet.getRow( 1 )[ 0 ];
  assertNotNull( cell );
  assertEquals( KCellType.DATE, cell.getType() );
  cell = spSheet.getRow( 2 )[ 0 ];
  assertNull( "cell must be null", cell );
}
 
Example #9
Source File: StaxPoiSheetTest.java    From hop with Apache License 2.0 6 votes vote down vote up
@Test
public void testNullDateCell() throws Exception {
  // cell had null value instead of being null
  final String sheetId = "1";
  final String sheetName = "Sheet 1";
  XSSFReader reader = mockXSSFReader( sheetId, SHEET_DATE_NO_V,
    mockSharedStringsTable( "Some Date" ),
    mockStylesTable(
      Collections.singletonMap( 2, 165 ),
      Collections.singletonMap( 165, "M/D/YYYY" ) ) );
  StaxPoiSheet spSheet = spy( new StaxPoiSheet( reader, sheetName, sheetId ) );
  doReturn( true ).when( spSheet ).isDateCell( any() );
  IKCell cell = spSheet.getRow( 1 )[ 0 ];
  assertNotNull( cell );
  assertEquals( KCellType.DATE, cell.getType() );
  cell = spSheet.getRow( 2 )[ 0 ];
  assertNull( "cell must be null", cell );
}
 
Example #10
Source File: XLSX2CSV.java    From azeroth with Apache License 2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example #11
Source File: StaxPoiSheetTest.java    From hop with Apache License 2.0 6 votes vote down vote up
@Test
public void testInlineString() throws Exception {
  final String sheetId = "1";
  final String sheetName = "Sheet 1";
  XSSFReader reader = mockXSSFReader( sheetId, SHEET_INLINE_STRINGS,
    mock( SharedStringsTable.class ),
    mock( StylesTable.class ) );
  StaxPoiSheet spSheet = new StaxPoiSheet( reader, sheetName, sheetId );
  KCell[] rowCells = spSheet.getRow( 0 );
  assertEquals( "Test1", rowCells[ 0 ].getValue() );
  assertEquals( KCellType.STRING_FORMULA, rowCells[ 0 ].getType() );
  assertEquals( "Test2", rowCells[ 1 ].getValue() );
  assertEquals( KCellType.STRING_FORMULA, rowCells[ 1 ].getType() );
  rowCells = spSheet.getRow( 1 );
  assertEquals( "value 1 1", rowCells[ 0 ].getValue() );
  assertEquals( KCellType.STRING_FORMULA, rowCells[ 0 ].getType() );
  assertEquals( "value 2 1", rowCells[ 1 ].getValue() );
  assertEquals( KCellType.STRING_FORMULA, rowCells[ 1 ].getType() );
  rowCells = spSheet.getRow( 2 );
  assertEquals( "value 1 2", rowCells[ 0 ].getValue() );
  assertEquals( KCellType.STRING_FORMULA, rowCells[ 0 ].getType() );
  assertEquals( "value 2 2", rowCells[ 1 ].getValue() );
  assertEquals( KCellType.STRING_FORMULA, rowCells[ 1 ].getType() );
}
 
Example #12
Source File: XLSX2CSV.java    From bdf3 with Apache License 2.0 6 votes vote down vote up
public void 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()) {
        InputStream stream = iter.next();
        String sheetName = iter.getSheetName();
        this.output.println();
        this.output.println(sheetName + " [index=" + index + "]:");
        processSheet(styles, strings, stream);
        stream.close();
        ++index;
    }
    close();
}
 
Example #13
Source File: XSSFUtil.java    From javautils with Apache License 2.0 6 votes vote down vote up
public void processAllSheets(String filename) throws Exception {
    OPCPackage pkg = OPCPackage.open(filename);
    XSSFReader r = new XSSFReader( pkg );
    SharedStringsTable sst = r.getSharedStringsTable();

    XMLReader parser = fetchSheetParser(sst);

    Iterator<InputStream> sheets = r.getSheetsData();
    while(sheets.hasNext()) {
        System.out.println("Processing new sheet:\n");
        InputStream sheet = sheets.next();
        InputSource sheetSource = new InputSource(sheet);
        parser.parse(sheetSource);
        sheet.close();
        System.out.println("");
    }
}
 
Example #14
Source File: StaxPoiSheetTest.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
@Test
public void testInlineString() throws Exception {
  final String sheetId = "1";
  final String sheetName = "Sheet 1";
  XSSFReader reader = mockXSSFReader( sheetId, SHEET_INLINE_STRINGS,
    mock( SharedStringsTable.class ),
    mock( StylesTable.class ) );
  StaxPoiSheet spSheet = new StaxPoiSheet( reader, sheetName, sheetId );
  KCell[] rowCells = spSheet.getRow( 0 );
  assertEquals( "Test1", rowCells[ 0 ].getValue() );
  assertEquals( KCellType.STRING_FORMULA, rowCells[ 0 ].getType() );
  assertEquals( "Test2", rowCells[ 1 ].getValue() );
  assertEquals( KCellType.STRING_FORMULA, rowCells[ 1 ].getType() );
  rowCells = spSheet.getRow( 1 );
  assertEquals( "value 1 1", rowCells[ 0 ].getValue() );
  assertEquals( KCellType.STRING_FORMULA, rowCells[ 0 ].getType() );
  assertEquals( "value 2 1", rowCells[ 1 ].getValue() );
  assertEquals( KCellType.STRING_FORMULA, rowCells[ 1 ].getType() );
  rowCells = spSheet.getRow( 2 );
  assertEquals( "value 1 2", rowCells[ 0 ].getValue() );
  assertEquals( KCellType.STRING_FORMULA, rowCells[ 0 ].getType() );
  assertEquals( "value 2 2", rowCells[ 1 ].getValue() );
  assertEquals( KCellType.STRING_FORMULA, rowCells[ 1 ].getType() );
}
 
Example #15
Source File: StaxPoiSheetTest.java    From hop with Apache License 2.0 6 votes vote down vote up
@Test
public void testNullDateCell() throws Exception {
  // cell had null value instead of being null
  final String sheetId = "1";
  final String sheetName = "Sheet 1";
  XSSFReader reader = mockXSSFReader( sheetId, SHEET_DATE_NO_V,
    mockSharedStringsTable( "Some Date" ),
    mockStylesTable(
      Collections.singletonMap( 2, 165 ),
      Collections.singletonMap( 165, "M/D/YYYY" ) ) );
  StaxPoiSheet spSheet = spy( new StaxPoiSheet( reader, sheetName, sheetId ) );
  doReturn( true ).when( spSheet ).isDateCell( any() );
  KCell cell = spSheet.getRow( 1 )[ 0 ];
  assertNotNull( cell );
  assertEquals( KCellType.DATE, cell.getType() );
  cell = spSheet.getRow( 2 )[ 0 ];
  assertNull( "cell must be null", cell );
}
 
Example #16
Source File: XLSX2CSV.java    From jeesuite-libs with Apache License 2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example #17
Source File: Excel2007Reader.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * 遍历工作簿中所有的电子表格
 * @param filename
 * @param fileKey 
 * @throws Exception
 */
public void process( String filename ) throws Exception {
	OPCPackage pkg = OPCPackage.open( filename );
	XSSFReader r = new XSSFReader(pkg);
	SharedStringsTable sst = r.getSharedStringsTable();
	XMLReader parser = fetchSheetParser(sst);
	Iterator<InputStream> sheets = r.getSheetsData();
	while (sheets.hasNext()) {
		curRow = 0;
		sheetIndex++;
		InputStream sheet = sheets.next();
		InputSource sheetSource = new InputSource(sheet);
		parser.parse( sheetSource );
		sheet.close();
	}
	//数据读取完成
}
 
Example #18
Source File: XLSX2CSV.java    From DBus with Apache License 2.0 6 votes vote down vote up
/**
 * Initiates the processing of the XLS workbook file to CSV.
 *
 * @throws IOException
 * @throws OpenXML4JException
 * @throws ParserConfigurationException
 * @throws SAXException
 */
public void 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()) {
        InputStream stream = iter.next();
        //String sheetName = iter.getSheetName();
        //this.output.println();
        //this.output.println(sheetName + " [index=" + index + "]:");
        processSheet(styles, strings, stream);
        stream.close();
        //++index;
    }
}
 
Example #19
Source File: Excel2007Reader.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * 遍历工作簿中所有的电子表格
 * @param filename
 * @param fileKey 
 * @throws Exception
 */
public void process( InputStream is ) throws Exception {
	OPCPackage pkg = OPCPackage.open( is );
	XSSFReader r = new XSSFReader(pkg);
	SharedStringsTable sst = r.getSharedStringsTable();
	XMLReader parser = fetchSheetParser(sst);
	Iterator<InputStream> sheets = r.getSheetsData();
	while (sheets.hasNext()) {
		curRow = 0;
		sheetIndex++;
		InputStream sheet = sheets.next();
		InputSource sheetSource = new InputSource(sheet);
		parser.parse( sheetSource );
		sheet.close();
	}
}
 
Example #20
Source File: Excel2007Reader.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * 遍历工作簿中所有的电子表格
 * @param is
 * @param fileKey 
 * @throws Exception
 */
public void process( InputStream is ) throws Exception {
	OPCPackage pkg = OPCPackage.open( is );
	XSSFReader r = new XSSFReader(pkg);
	SharedStringsTable sst = r.getSharedStringsTable();
	XMLReader parser = fetchSheetParser(sst);
	Iterator<InputStream> sheets = r.getSheetsData();
	while (sheets.hasNext()) {
		curRow = 0;
		sheetIndex++;
		InputStream sheet = sheets.next();
		InputSource sheetSource = new InputSource(sheet);
		parser.parse( sheetSource );
		sheet.close();
	}
	//数据读取完成
}
 
Example #21
Source File: Excel2007Reader.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * 遍历工作簿中所有的电子表格
 * @param filename
 * @param fileKey 
 * @throws Exception
 */
public void process( String filename ) throws Exception {
	OPCPackage pkg = OPCPackage.open( filename );
	XSSFReader r = new XSSFReader(pkg);
	SharedStringsTable sst = r.getSharedStringsTable();
	XMLReader parser = fetchSheetParser(sst);
	Iterator<InputStream> sheets = r.getSheetsData();
	while (sheets.hasNext()) {
		curRow = 0;
		sheetIndex++;
		InputStream sheet = sheets.next();
		InputSource sheetSource = new InputSource(sheet);
		parser.parse( sheetSource );
		sheet.close();
	}
	//数据读取完成
}
 
Example #22
Source File: Excel2007Reader.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * 遍历工作簿中所有的电子表格
 * @param is
 * @param fileKey 
 * @throws Exception
 */
public void process( InputStream is ) throws Exception {
	OPCPackage pkg = OPCPackage.open( is );
	XSSFReader r = new XSSFReader(pkg);
	SharedStringsTable sst = r.getSharedStringsTable();
	XMLReader parser = fetchSheetParser(sst);
	Iterator<InputStream> sheets = r.getSheetsData();
	while (sheets.hasNext()) {
		curRow = 0;
		sheetIndex++;
		InputStream sheet = sheets.next();
		InputSource sheetSource = new InputSource(sheet);
		parser.parse( sheetSource );
		sheet.close();
	}
	//数据读取完成
}
 
Example #23
Source File: XlsxRowReader.java    From translationstudio8 with GNU General Public License v2.0 6 votes vote down vote up
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();
	}
}
 
Example #24
Source File: Excel2007Reader.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * 遍历工作簿中所有的电子表格
 * @param filename
 * @param fileKey 
 * @throws Exception
 */
public void process( String filename ) throws Exception {
	OPCPackage pkg = OPCPackage.open( filename );
	XSSFReader r = new XSSFReader(pkg);
	SharedStringsTable sst = r.getSharedStringsTable();
	XMLReader parser = fetchSheetParser(sst);
	Iterator<InputStream> sheets = r.getSheetsData();
	while (sheets.hasNext()) {
		curRow = 0;
		sheetIndex++;
		InputStream sheet = sheets.next();
		InputSource sheetSource = new InputSource(sheet);
		parser.parse( sheetSource );
		sheet.close();
	}
	//数据读取完成
}
 
Example #25
Source File: Excel2007Reader.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * 遍历工作簿中所有的电子表格
 * @param is
 * @param fileKey 
 * @throws Exception
 */
public void process( InputStream is ) throws Exception {
	OPCPackage pkg = OPCPackage.open( is );
	XSSFReader r = new XSSFReader(pkg);
	SharedStringsTable sst = r.getSharedStringsTable();
	XMLReader parser = fetchSheetParser(sst);
	Iterator<InputStream> sheets = r.getSheetsData();
	while (sheets.hasNext()) {
		curRow = 0;
		sheetIndex++;
		InputStream sheet = sheets.next();
		InputSource sheetSource = new InputSource(sheet);
		parser.parse( sheetSource );
		sheet.close();
	}
	//数据读取完成
}
 
Example #26
Source File: Xlsx2TmxHelper.java    From translationstudio8 with GNU General Public License v2.0 6 votes vote down vote up
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();
}
 
Example #27
Source File: Excel2007Reader.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * 遍历工作簿中所有的电子表格
 * @param filename
 * @param fileKey 
 * @throws Exception
 */
public void process( String filename ) throws Exception {
	OPCPackage pkg = OPCPackage.open( filename );
	XSSFReader r = new XSSFReader(pkg);
	SharedStringsTable sst = r.getSharedStringsTable();
	XMLReader parser = fetchSheetParser(sst);
	Iterator<InputStream> sheets = r.getSheetsData();
	while (sheets.hasNext()) {
		curRow = 0;
		sheetIndex++;
		InputStream sheet = sheets.next();
		InputSource sheetSource = new InputSource(sheet);
		parser.parse( sheetSource );
		sheet.close();
	}
	//数据读取完成
}
 
Example #28
Source File: Excel2007Reader.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * 遍历工作簿中所有的电子表格
 * @param is
 * @param fileKey 
 * @throws Exception
 */
public void process( InputStream is ) throws Exception {
	OPCPackage pkg = OPCPackage.open( is );
	XSSFReader r = new XSSFReader(pkg);
	SharedStringsTable sst = r.getSharedStringsTable();
	XMLReader parser = fetchSheetParser(sst);
	Iterator<InputStream> sheets = r.getSheetsData();
	while (sheets.hasNext()) {
		curRow = 0;
		sheetIndex++;
		InputStream sheet = sheets.next();
		InputSource sheetSource = new InputSource(sheet);
		parser.parse( sheetSource );
		sheet.close();
	}
	//数据读取完成
}
 
Example #29
Source File: ExcelReader.java    From frpMgr with MIT License 6 votes vote down vote up
/**
 * 遍历工作簿中所有的电子表格
 * @param filename
 * @throws Exception
 */
public void process(String filename) throws Exception {
	OPCPackage pkg = OPCPackage.open(filename);
	XSSFReader r = new XSSFReader(pkg);
	SharedStringsTable sst = r.getSharedStringsTable();
	XMLReader parser = fetchSheetParser(sst);
	Iterator<InputStream> sheets = r.getSheetsData();
	while (sheets.hasNext()) {
		curRow = 0;
		sheetIndex++;
		InputStream sheet = sheets.next();
		InputSource sheetSource = new InputSource(sheet);
		parser.parse(sheetSource);
		sheet.close();
	}
}
 
Example #30
Source File: Excel2007Reader.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * 遍历工作簿中所有的电子表格
 * @param filename
 * @param fileKey 
 * @throws Exception
 */
public void process( String filename ) throws Exception {
	OPCPackage pkg = OPCPackage.open(filename);
	XSSFReader r = new XSSFReader(pkg);
	SharedStringsTable sst = r.getSharedStringsTable();
	XMLReader parser = fetchSheetParser(sst);
	Iterator<InputStream> sheets = r.getSheetsData();
	while (sheets.hasNext()) {
		curRow = 0;
		sheetIndex++;
		InputStream sheet = sheets.next();
		InputSource sheetSource = new InputSource(sheet);
		parser.parse( sheetSource );
		sheet.close();
	}
	//数据读取完成
}