效果图:

word:

BufferedInputStream bis = null;
  URL url = null;
  HttpURLConnection httpUrl = null; // 建立链接
  url = new URL(urlReal);
  httpUrl = (HttpURLConnection) url.openConnection();// 连接指定的资源
  httpUrl.connect();// 获取网络输入流
  bis = new BufferedInputStream(httpUrl.getInputStream());

String bodyText = null;
  WordExtractor ex = new WordExtractor(bis);
  bodyText = ex.getText();
  response.getWriter().write(bodyText);

excel:

BufferedInputStream bis = null;
  URL url = null;
  HttpURLConnection httpUrl = null; // 建立链接
  url = new URL(urlReal);
  httpUrl = (HttpURLConnection) url.openConnection();// 连接指定的资源
  httpUrl.connect();// 获取网络输入流
  bis = new BufferedInputStream(httpUrl.getInputStream());

content = new StringBuffer();
  HSSFWorkbook workbook = new HSSFWorkbook(bis);
  for (int numSheets = 0; numSheets < workbook.getNumberOfSheets(); numSheets++) {
   HSSFSheet aSheet = workbook.getSheetAt(numSheets);// 获得一个sheet
   content.append("/n");
   if (null == aSheet) {
    continue;
   }
   for (int rowNum = 0; rowNum <= aSheet.getLastRowNum(); rowNum++) {
    content.append("/n");
    HSSFRow aRow = aSheet.getRow(rowNum);
    if (null == aRow) {
     continue;
    }
    for (short cellNum = 0; cellNum <= aRow.getLastCellNum(); cellNum++) {
     HSSFCell aCell = aRow.getCell(cellNum);
     if (null == aCell) {
      continue;
     }
     if (aCell.getCellType() == HSSFCell.CELL_TYPE_STRING) {
      content.append(aCell.getRichStringCellValue()
        .getString());
     } else if (aCell.getCellType() == HSSFCell.CELL_TYPE_NUMERIC) {
      boolean b = HSSFDateUtil.isCellDateFormatted(aCell);
      if (b) {
       Date date = aCell.getDateCellValue();
       SimpleDateFormat df = new SimpleDateFormat(
         "yyyy-MM-dd");
       content.append(df.format(date));
      }
     }
    }
   }
  }
  response.getWriter().write(content.toString());

ppt:

BufferedInputStream bis = null;
  URL url = null;
  HttpURLConnection httpUrl = null; // 建立链接
  url = new URL(urlReal);
  httpUrl = (HttpURLConnection) url.openConnection();// 连接指定的资源
  httpUrl.connect();// 获取网络输入流
  bis = new BufferedInputStream(httpUrl.getInputStream());

StringBuffer content = new StringBuffer("");
  SlideShow ss = new SlideShow(new HSLFSlideShow(bis));
  Slide[] slides = ss.getSlides();
  for (int i = 0; i < slides.length; i++) {
   TextRun[] t = slides[i].getTextRuns();
   for (int j = 0; j < t.length; j++) {
    content.append(t[j].getText());
   }
   content.append(slides[i].getTitle());
  }
  response.getWriter().write(content.toString());

pdf:

BufferedInputStream bis = null;
  URL url = null;
  HttpURLConnection httpUrl = null; // 建立链接
  url = new URL(urlReal);
  httpUrl = (HttpURLConnection) url.openConnection();// 连接指定的资源
  httpUrl.connect();// 获取网络输入流
  bis = new BufferedInputStream(httpUrl.getInputStream());

PDDocument pdfdocument = null;
  PDFParser parser = new PDFParser(bis);
  parser.parse();
  pdfdocument = parser.getPDDocument();
  ByteArrayOutputStream out = new ByteArrayOutputStream();
  OutputStreamWriter writer = new OutputStreamWriter(out);
  PDFTextStripper stripper = new PDFTextStripper();
  stripper.writeText(pdfdocument.getDocument(), writer);
  writer.close();
  byte[] contents = out.toByteArray();

String ts = new String(contents);
  response.getWriter().write(ts);

txt:

BufferedReader bis = null;
  URL url = null;
  HttpURLConnection httpUrl = null; // 建立链接
  url = new URL(urlReal);
  httpUrl = (HttpURLConnection) url.openConnection();// 连接指定的资源
  httpUrl.connect();// 获取网络输入流
  bis = new BufferedReader( new InputStreamReader(httpUrl.getInputStream()));

StringBuffer buf=new StringBuffer();
  String temp;
  while ((temp = bis.readLine()) != null) {
   buf.append(temp);
   response.getWriter().write(temp);
   if(buf.length()>=1000){
    break;
   }
  }
  bis.close();

Java实现在线预览Word,Excel,Ppt文档的更多相关文章

  1. uploadify 下载组件使用技巧和在线预览 word,excel,ppt,pdf的方案

    http://www.cnblogs.com/wolf-sun/p/3565184.html uploadify 上传工具的使用技巧 http://www.cnblogs.com/wolf-sun/p ...

  2. 关于在线预览word,excel,ppt,pdf的需求处理方法。

    参考文档:http://www.cnblogs.com/wolf-sun/p/3574278.html 我选用的方案:先用office com组件生成pdf,然后使用pdf.js在线预览pdf文档.在 ...

  3. 在线预览word,excel,ppt

    https://view.officeapps.live.com/op/view.aspx?src=服务器地址微软提供的地址拼接自己的可以预览了拼接自己的服务器地址可以在线预览

  4. PDF/WORD/EXCEL/PPT 文档在线阅读

    查资料看了2种解决方法: 1.通过办公软件dll转换,用flans去看 2.通过Aspose转换成pdf格式,在用js前台读pdf(我用的pdf.js) 今天我解决的就是WORD/EXCEL/PPT ...

  5. word&excel&ppt文档加密方式

    ppt excel word

  6. java通过url在线预览Word、excel、ppt、pdf、txt文档

    java通过url在线预览Word.excel.ppt.pdf.txt文档中的内容[只获得其中的文字] 在页面上显示各种文档中的内容.在servlet中的逻辑 word: BufferedInputS ...

  7. java实现在线预览--poi实现word、excel、ppt转html

    java实现在线预览 - -之poi实现word.excel.ppt转html 简介 java实现在线预览功能是一个大家在工作中也许会遇到的需求,如果公司有钱,直接使用付费的第三方软件或者云在线预览服 ...

  8. java实现在线预览 - -之poi实现word、excel、ppt转html

    简介 java实现在线预览功能是一个大家在工作中也许会遇到的需求,如果公司有钱,直接使用付费的第三方软件或者云在线预览服务就可以了,例如永中office.office web 365(http://w ...

  9. Asp.net MVC 利用(aspose+pdfobject.js) 实现在线预览word、excel、ppt、pdf文件

    在线预览word.excel.ppt利用aspose动态生成html 主要代码 private bool OfficeDocumentToHtml(string sourceDoc, string s ...

随机推荐

  1. python3 之__str__

    当某个类定义了__str__方法是,打印该类的实例对象就是打印__str__方法return出来的数据 示例: class Cat: """定义了一个Cat类" ...

  2. vscodes使用(一): 常用插件,在线与离线安装

    一.常用插件 1.Live server 浏览器实时刷新 插件安装成功后,会在底部工具栏中,显示个Go Live *.html文件,点击右键,可以看到live server两条指令   2.Esasy ...

  3. ExpressMapper- The New .NET Mapper!

    推荐,据测试比手工映射的效率还高. https://www.codeproject.com/Tips/1009198/Expressmapper-The-New-NET-Mapper

  4. .NetCore 扩展封装 Expression<Func<T, bool>> 查询条件遇到的问题

    前面的文章封装了查询条件 自己去组装条件,但是对 And  Or  这种组合支持很差,但是也不是不能支持,只是要写更多的代码看起来很臃肿 根据 Where(Expression<Func< ...

  5. bnu 10809 聚餐

    Lolilu大牛又要请客了~~有些同学呢,是果断要去的,而有些同学呢,只有确定心中的大牛会参加,他才会参加.Lolilu决定请大家去吃金钱豹,因此希望你告诉他一共会有多少人参加,他才知道带多少钱比较合 ...

  6. 数学之美——HMM模型(二)解码和Forward算法

    上一篇讨论了HMM的基本概念和一些性质,HMM在现实中还是比较常见的,因此也带来一了一系列的HMM应用问题.HMM应用主要面向三个方面:预测.解码和学习.这篇主要讨论预测. 简单来说,预测就是给定HM ...

  7. 【LOJ】#2493. 「BJOI2018」染色

    题面 题解 推结论大题--然而我推不出什么结论 奇环显然是NO 如果一个联通块里有两个分离的环,也是NO 如果一个联通块里,点数为n,边数为m m <= n的时候,是YES m >= n ...

  8. ld: warning: directory not found for option '-F/Users/Jason/Project/xxx'

    解决方法: 选择项目名称----->Targets----->Build Settings----->Search Paths----->Library Search Path ...

  9. MATLAB检查指定路径中的子文件夹中的文件名中是否带有空格

    测试文件夹为: clear;close all;clc; %% %程序实现的功能 %检查指定路径中的子文件夹中的文件名中是否带有空格,并去掉文件名中的空格 %% %程序中用到的之前不清楚的函数如下 % ...

  10. P2429 制杖题

    P2429 制杖题这个题用线性筛会WA一个点,因为这个题是给定的质数集,最大的质数会比当前的倍数大,就会出现上面的情况.怎办?判重用set啊!set+线性筛就过掉了.16ms #include< ...