本文整理汇总了Java中org.apache.poi.poifs.filesystem.POIFSFileSystem类的典型用法代码示例。如果您正苦于以下问题:Java POIFSFileSystem类的具体用法?Java POIFSFileSystem怎么用?Java POIFSFileSystem使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
POIFSFileSystem类属于org.apache.poi.poifs.filesystem包,在下文中一共展示了POIFSFileSystem类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: microsoftWordDocumentToString
import org.apache.poi.poifs.filesystem.POIFSFileSystem; //导入依赖的package包/类
private static String microsoftWordDocumentToString(InputStream inputStream) throws IOException {
String strRet;
try (InputStream wordStream = new BufferedInputStream(inputStream)) {
if (POIFSFileSystem.hasPOIFSHeader(wordStream)) {
WordExtractor wordExtractor = new WordExtractor(wordStream);
strRet = wordExtractor.getText();
wordExtractor.close();
} else {
XWPFWordExtractor wordXExtractor = new XWPFWordExtractor(new XWPFDocument(wordStream));
strRet = wordXExtractor.getText();
wordXExtractor.close();
}
}
return strRet;
}
示例2: convertEncryptedXlsx2DecryptedXlsx
import org.apache.poi.poifs.filesystem.POIFSFileSystem; //导入依赖的package包/类
public static InputStream convertEncryptedXlsx2DecryptedXlsx(InputStream is)
throws IOException {
POIFSFileSystem fs = new POIFSFileSystem(is);
EncryptionInfo info = new EncryptionInfo(fs);
Decryptor d = Decryptor.getInstance(info);
try {
d.verifyPassword(Decryptor.DEFAULT_PASSWORD);
InputStream dataStream = d.getDataStream(fs);
return dataStream;
} catch (GeneralSecurityException e) {
throw new IOException(e);
}
}
示例3: saveDoc
import org.apache.poi.poifs.filesystem.POIFSFileSystem; //导入依赖的package包/类
/**
* Method to save the file by parameters in doc format
*
* @param toSave The file where the information will be saved
*/
private void saveDoc(File toSave) {
try {
POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream("down/empty.doc"));
HWPFDocument doc = new HWPFDocument(fs);
Range range = doc.getRange();
Paragraph parContainer = range.insertAfter(new ParagraphProperties(), 0);
for (String para : paragraphs) {
parContainer.setSpacingAfter(200);
parContainer.insertAfter(para);
parContainer = range.insertAfter(new ParagraphProperties(), 0);
}
FileOutputStream fos = new FileOutputStream(toSave);
doc.write(fos);
fos.close();
} catch (Exception e) {
Logger.getGlobal().log(Level.SEVERE, e.getMessage() + "\n" + Arrays.toString(e.getStackTrace()));
}
}
示例4: decrypt
import org.apache.poi.poifs.filesystem.POIFSFileSystem; //导入依赖的package包/类
public static XSSFWorkbook decrypt(InputStream input, String password)
throws IOException {
POIFSFileSystem filesystem = new POIFSFileSystem(input);
EncryptionInfo info = new EncryptionInfo(filesystem);
Decryptor d = Decryptor.getInstance(info);
try {
if (!d.verifyPassword(password)) {
throw new RuntimeException(
"Unable to process: document is encrypted");
}
InputStream dataStream = d.getDataStream(filesystem);
// parse dataStream
return new XSSFWorkbook(dataStream);
} catch (GeneralSecurityException ex) {
throw new RuntimeException("Unable to process encrypted document",
ex);
}
}
示例5: reader
import org.apache.poi.poifs.filesystem.POIFSFileSystem; //导入依赖的package包/类
public static void reader(String filePath) {
try {
POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream(filePath));
HSSFWorkbook wb = new HSSFWorkbook(fs);
HSSFSheet sheet = wb.getSheetAt(0);
HSSFRow row = sheet.getRow(3);
HSSFCell cell = row.getCell((short) 0);
int type = cell.getCellType();
String msg = getCellStringValue(cell);
System.out.println(type + ":" + msg);
} catch (IOException e) {
e.printStackTrace();
}
}
示例6: execute
import org.apache.poi.poifs.filesystem.POIFSFileSystem; //导入依赖的package包/类
public void execute(InputStream inputStream, IParseExcelRowMapper parseExcelRowMapper) throws IOException {
this.fs = new POIFSFileSystem(inputStream);
this.minColumns = -1;
this.parseExcelRowMapper = parseExcelRowMapper;
MissingRecordAwareHSSFListener listener = new MissingRecordAwareHSSFListener(this);
formatListener = new FormatTrackingHSSFListener(listener);
HSSFEventFactory factory = new HSSFEventFactory();
HSSFRequest request = new HSSFRequest();
if (outputFormulaValues) {
request.addListenerForAllRecords(formatListener);
} else {
workbookBuildingListener = new SheetRecordCollectingListener(formatListener);
request.addListenerForAllRecords(workbookBuildingListener);
}
factory.processWorkbookEvents(request, fs);
}
示例7: microsoftExcelDocumentToString
import org.apache.poi.poifs.filesystem.POIFSFileSystem; //导入依赖的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();
}
示例8: readExcel
import org.apache.poi.poifs.filesystem.POIFSFileSystem; //导入依赖的package包/类
public static void readExcel(String filePth) throws Exception {
InputStream is = new FileInputStream(filePth);
//创建工作薄
//XSSFWorkbook hwb = new XSSFWorkbook(is);
HSSFWorkbook hwb = new HSSFWorkbook(new POIFSFileSystem(is));
//得到sheet
for (int i = 0; i < hwb.getNumberOfSheets(); i++) {
HSSFSheet sheet = hwb.getSheetAt(i);
int rows = sheet.getPhysicalNumberOfRows();
//遍历每一行
for (int j = 0; j < rows; j++) {
HSSFRow hr = sheet.getRow(j);
Iterator<?> it = hr.iterator();
while(it.hasNext()){
String context = it.next().toString();
System.out.println(context);
}
}
}
hwb.close();
}
示例9: create
import org.apache.poi.poifs.filesystem.POIFSFileSystem; //导入依赖的package包/类
/**
* @param file
* @param excelReader
* @param ignoreNumFormat 是否忽略数据格式 (default=false,按照格式读取)
* @return
* @throws Exception
*/
public static ReadHandler create(File file, ExcelReadListener excelReader,
boolean ignoreNumFormat) throws Exception {
if (!file.exists()) {
throw new FileNotFoundException(file.toString());
}
try {
POIFSFileSystem fs = new POIFSFileSystem(file);
return create(fs, excelReader, ignoreNumFormat);
} catch (OfficeXmlFileException e) {
OPCPackage pkg = OPCPackage.open(file, PackageAccess.READ);
try {
return create(pkg, excelReader, ignoreNumFormat);
} catch (IllegalArgumentException | IOException e1) {
pkg.revert();
throw e1;
}
}
}
示例10: testReadByDoc
import org.apache.poi.poifs.filesystem.POIFSFileSystem; //导入依赖的package包/类
@Test
public void testReadByDoc() throws Exception {
InputStream is = new FileInputStream("E://video/doc/xiuParty/90Xiu-NEW/oss/90秀--oss与服务器端接口文档.doc");
POIFSFileSystem pfilesystem = new POIFSFileSystem(is);
HWPFDocument doc = new HWPFDocument(pfilesystem);
// // 输出书签信息
// this.printInfo(doc.getBookmarks());
// // 输出文本
// System.out.println(doc.getDocumentText());
Range range = doc.getRange();
// this.insertInfo(range);
this.printInfo(range);
// 读表格
this.readTable(range);
// 读列表
this.readList(range);
// 删除range
Range r = new Range(2, 5, doc);
r.delete();// 在内存中进行删除,如果需要保存到文件中需要再把它写回文件
// 把当前HWPFDocument写到输出流中
doc.write(new FileOutputStream("D:\\test.doc"));
IOUtils.closeQuietly(is);
}
示例11: createOleObject
import org.apache.poi.poifs.filesystem.POIFSFileSystem; //导入依赖的package包/类
/**
* Create OleObject using a sample.
*
* @param from File to embed
* @param to Destination file
*/
private void createOleObject(File from, File to) throws IOException, Ole10NativeException {
File existingOleObject = new File(templateDirectory, "word/embeddings/oleObject.bin");
OutputStream os = null;
try {
// When
POIFSFileSystem fs = new POIFSFileSystem(FileUtils.openInputStream(existingOleObject));
fs.getRoot().getEntry(Ole10Native.OLE10_NATIVE).delete();
Ole10Native ole = new Ole10Native(from.getName(), from.getName(), from.getName(), IOUtils.toByteArray(FileUtils.openInputStream(from)));
ByteArrayOutputStream stream = new ByteArrayOutputStream();
ole.writeOut(stream);
fs.getRoot().createDocument(Ole10Native.OLE10_NATIVE, new ByteArrayInputStream(stream.toByteArray()));
os = FileUtils.openOutputStream(to);
fs.writeFilesystem(os);
} finally {
IOUtils.closeQuietly(os);
}
}
示例12: processarArquivoIO
import org.apache.poi.poifs.filesystem.POIFSFileSystem; //导入依赖的package包/类
/**
* L� arquivo enviado e gera mensagens JMS.
*
* Instancia request e starta leitura do arquivo com esta inst�ncia (this) de
* objeto como listener
*
* @param inputStream
* @throws IOException
*
*/
protected void processarArquivoIO(InputStream inputStream) throws IOException {
POIFSFileSystem poifs = new POIFSFileSystem(inputStream);
InputStream din = poifs.createDocumentInputStream("Workbook");
try {
HSSFRequest req = new HSSFRequest();
req.addListenerForAllRecords(this);
HSSFEventFactory factory = new HSSFEventFactory();
factory.processEvents(req, din);
}catch(Throwable t){
log.fatal("Erro fatal ao tentar executar o Processamento das mensagens!",t);
t.printStackTrace();
}
finally {
inputStream.close();
din.close();
}
}
示例13: createWorkbook
import org.apache.poi.poifs.filesystem.POIFSFileSystem; //导入依赖的package包/类
public Workbook createWorkbook() throws UserAdminException {
String filename = config.getFileName();
InputStream ins = config.getInStream();
Workbook wb = null;
try {
if (filename.endsWith(".xlsx")) {
wb = new XSSFWorkbook(ins);
} else {
POIFSFileSystem fs = new POIFSFileSystem(ins);
wb = new HSSFWorkbook(fs);
}
} catch (Exception e) {
log.error("Bulk import failed" + e.getMessage(), e);
throw new UserAdminException("Bulk import failed" + e.getMessage(), e);
} finally {
IdentityIOStreamUtils.closeInputStream(ins);
}
return wb;
}
示例14: readContent
import org.apache.poi.poifs.filesystem.POIFSFileSystem; //导入依赖的package包/类
@Override
protected String readContent(final VFSLeaf leaf) throws IOException, DocumentException {
BufferedInputStream bis = null;
final StringBuilder sb = new StringBuilder();
try {
bis = new BufferedInputStream(leaf.getInputStream());
final POIFSFileSystem filesystem = new POIFSFileSystem(bis);
final Iterator<?> entries = filesystem.getRoot().getEntries();
while (entries.hasNext()) {
final Entry entry = (Entry) entries.next();
final String name = entry.getName();
if (!(entry instanceof DocumentEntry)) {
// Skip directory entries
} else if ("WordDocument".equals(name)) {
collectWordDocument(filesystem, sb);
}
}
return sb.toString();
} catch (final Exception e) {
throw new DocumentException(e.getMessage());
} finally {
if (bis != null) {
bis.close();
}
}
}
示例15: BookController
import org.apache.poi.poifs.filesystem.POIFSFileSystem; //导入依赖的package包/类
/**
* コンストラクタ<BR>
* ファイルの形式を判定してWorkbookを生成する
*
* @param filepath ファイルパス
* @throws IOException ファイルの読み込みに失敗した場合
*/
public BookController( String filepath) throws IOException {
if ( log.isInfoEnabled()) {
log.info( filepath + "の読み込みを開始します");
}
if ( filepath.endsWith( XSSF_SUFFIX)) {
// XSSF形式
workbook = new XSSFWorkbook( filepath);
} else {
// HSSF形式
FileInputStream stream = new FileInputStream( filepath);
POIFSFileSystem fs = new POIFSFileSystem( stream);
workbook = new HSSFWorkbook( fs);
stream.close();
}
// シート名を解析
int numOfSheets = workbook.getNumberOfSheets();
for ( int sheetCnt = 0; sheetCnt < numOfSheets; sheetCnt++) {
String sheetName = workbook.getSheetName( sheetCnt);
sheetNames.add( sheetName);
}
}