本文整理汇总了Java中org.apache.poi.hssf.extractor.ExcelExtractor类的典型用法代码示例。如果您正苦于以下问题:Java ExcelExtractor类的具体用法?Java ExcelExtractor怎么用?Java ExcelExtractor使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ExcelExtractor类属于org.apache.poi.hssf.extractor包,在下文中一共展示了ExcelExtractor类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: microsoftExcelDocumentToString
import org.apache.poi.hssf.extractor.ExcelExtractor; //导入依赖的package包/类
private static String microsoftExcelDocumentToString(InputStream inputStream) throws IOException, OpenXML4JException, XmlException {
StringBuilder sb = new StringBuilder();
try (InputStream excelStream = new BufferedInputStream(inputStream)) {
if (POIFSFileSystem.hasPOIFSHeader(excelStream)) { // Before 2007 format files
POIFSFileSystem excelFS = new POIFSFileSystem(excelStream);
ExcelExtractor excelExtractor = new ExcelExtractor(excelFS);
sb.append(excelExtractor.getText());
excelExtractor.close();
} else { // New format
XSSFWorkbook workBook = new XSSFWorkbook(excelStream);
int numberOfSheets = workBook.getNumberOfSheets();
for (int i = 0; i < numberOfSheets; i++) {
XSSFSheet sheet = workBook.getSheetAt(0);
Iterator<Row> rowIterator = sheet.rowIterator();
while (rowIterator.hasNext()) {
XSSFRow row = (XSSFRow) rowIterator.next();
Iterator<Cell> cellIterator = row.cellIterator();
while (cellIterator.hasNext()) {
XSSFCell cell = (XSSFCell) cellIterator.next();
sb.append(cell.toString());
sb.append(" ");
}
sb.append("\n");
}
sb.append("\n");
}
}
}
return sb.toString();
}
示例2: excelExtractor
import org.apache.poi.hssf.extractor.ExcelExtractor; //导入依赖的package包/类
/**
* 利用 POI 提供的工具,提取文件内容为字符串
*
* @param excelFile 待提取的 excel 文件
* @return
*/
public String excelExtractor(File excelFile) {
try {
HSSFWorkbook wb = new HSSFWorkbook(new FileInputStream(excelFile));
ExcelExtractor extractor = new ExcelExtractor(wb);
extractor.setFormulasNotResults(true);
extractor.setIncludeSheetNames(true);
return extractor.getText();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return null;
}
}
示例3: extractText
import org.apache.poi.hssf.extractor.ExcelExtractor; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
public String extractText(InputStream stream, String type, String encoding) throws IOException {
try {
POIFSFileSystem fs = new POIFSFileSystem(stream);
return new ExcelExtractor(fs).getText();
} catch (RuntimeException e) {
logger.warn("Failed to extract Excel text content", e);
throw new IOException(e.getMessage(), e);
} finally {
stream.close();
}
}
示例4: getText
import org.apache.poi.hssf.extractor.ExcelExtractor; //导入依赖的package包/类
/**
* Extract text from a power point 97-2003 document.
* @throws Exception
*
* @see edu.ur.ir.index.FileTextExtractor#getText(java.io.File)
*/
public String getText(File f) throws Exception {
String text = null;
if( isFileTooLarge(f) || f.length() <= 0l )
{
return text;
}
FileInputStream inputStream = null;
try
{
inputStream = new FileInputStream(f);
HSSFWorkbook workbook = new HSSFWorkbook(inputStream);
ExcelExtractor excelExtractor = new ExcelExtractor(workbook);
String myText = excelExtractor.getText();
if( myText != null && !myText.trim().equals(""))
{
text = myText;
}
}
catch(OutOfMemoryError oome)
{
text = null;
log.error("oome could not extract text", oome);
throw(oome);
}
catch(Exception e)
{
text = null;
log.error("could not get text for power point document " + f.getAbsolutePath(), e);
throw(e);
}
finally
{
closeInputStream(inputStream);
}
return text;
}
示例5: extractHeaderFooter
import org.apache.poi.hssf.extractor.ExcelExtractor; //导入依赖的package包/类
private void extractHeaderFooter(String hf, XHTMLContentHandler xhtml)
throws SAXException {
String content = ExcelExtractor
._extractHeaderFooter(new HeaderFooterFromString(hf));
if (content.length() > 0) {
xhtml.element("p", content);
}
}
示例6: getIndexedDocument
import org.apache.poi.hssf.extractor.ExcelExtractor; //导入依赖的package包/类
public IndexDocument getIndexedDocument(File2Index fileData)
throws SolrException {
try {
POIFSFileSystem fs = new POIFSFileSystem(new ByteArrayInputStream(fileData.data));
ExcelExtractor extractor = new ExcelExtractor(fs);
String excelText = extractor.getText();
return new IndexDocument(fileData.path, excelText, null);
} catch (IOException e) {
String msg = "Failed to write to the index";
log.error(msg, e);
throw new SolrException(ErrorCode.SERVER_ERROR, msg);
}
}
示例7: officeExtractor
import org.apache.poi.hssf.extractor.ExcelExtractor; //导入依赖的package包/类
/**
* Extract metadata from Office Word
*/
public static OfficeMetadata officeExtractor(InputStream is, String mimeType) throws IOException {
POIFSFileSystem fs = new POIFSFileSystem(is);
OfficeMetadata md = new OfficeMetadata();
SummaryInformation si = null;
if (MimeTypeConfig.MIME_MS_WORD.equals(mimeType)) {
si = new WordExtractor(fs).getSummaryInformation();
} else if (MimeTypeConfig.MIME_MS_EXCEL.equals(mimeType)) {
si = new ExcelExtractor(fs).getSummaryInformation();
} else if (MimeTypeConfig.MIME_MS_POWERPOINT.equals(mimeType)) {
si = new PowerPointExtractor(fs).getSummaryInformation();
}
if (si != null) {
md.setTitle(si.getTitle());
md.setSubject(si.getSubject());
md.setAuthor(si.getAuthor());
md.setLastAuthor(si.getLastAuthor());
md.setKeywords(si.getKeywords());
md.setComments(si.getComments());
md.setTemplate(si.getTemplate());
md.setRevNumber(si.getRevNumber());
md.setApplicationName(si.getApplicationName());
md.setEditTime(si.getEditTime());
md.setPageCount(si.getPageCount());
md.setWordCount(si.getWordCount());
md.setCharCount(si.getCharCount());
md.setSecurity(si.getSecurity());
Calendar createDateTime = Calendar.getInstance();
createDateTime.setTime(si.getCreateDateTime());
md.setCreateDateTime(createDateTime);
Calendar lastSaveDateTime = Calendar.getInstance();
lastSaveDateTime.setTime(si.getLastSaveDateTime());
md.setLastSaveDateTime(lastSaveDateTime);
Calendar lastPrinted = Calendar.getInstance();
lastPrinted.setTime(si.getLastPrinted());
md.setLastPrinted(lastPrinted);
}
log.info("officeExtractor: {}", md);
return md;
}
示例8: xls2text
import org.apache.poi.hssf.extractor.ExcelExtractor; //导入依赖的package包/类
public String xls2text(InputStream is) throws IOException {
ExcelExtractor wd = new ExcelExtractor(new HSSFWorkbook(is));
String text = wd.getText();
wd.close();
return text;
}
示例9: extractHeaderFooter
import org.apache.poi.hssf.extractor.ExcelExtractor; //导入依赖的package包/类
private void extractHeaderFooter(final StringBuilder buffy, final HeaderFooter hf) {
final String content = ExcelExtractor._extractHeaderFooter(hf);
if (content.length() > 0) {
buffy.append(content).append(' ');
}
}