开源 企业版 高校版 私有云 模力方舟 AI 队友
代码拉取完成,页面将自动刷新
捐赠
捐赠前请先登录
扫描微信二维码支付
取消
支付完成
支付提示
将跳转至支付宝完成支付
确定
取消
1 Star 0 Fork 1.4K

java-utils/DocSys

forked from Rainy/DocSys
加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
已有帐号? 立即登录
文件
master
分支 (22)
标签 (21)
master
dev_DocSys_AddGit_Rainy
DocSys_bld_1.18
DocSys_bld_1.15
DocSys_bld_1.16
DocSys_bld_1.14
dev_DocSys_GD_1.13
DocSys_bld_1.13
DocSys_bld_1.12
DocSys_bld_1.11
DocSys_bld_1.10
dev_DocSys_GD
DocSys_bld_1.09
DocSys_bld_1.08
DocSys_bld_1.07
DocSys_bld_1.06
DocSys_bld_1.05
DocSys_bld_1.04
DocSys_bld_1.03
DocSys_bld_1.02
DocSys_V1.17.10
DocSys_V1.17.9
DocSys_V1.17.8
DocSys_V1.17
DocSys_V1.16
DocSys_V1.15
DocSys_V1.14
DocSys_V1.13
DocSys_V1.12
DocSys_V1.11
DocSys_V1.10
DocSys_V1.09
DocSys_V1.08
DocSys_V1.07
DocSys_V1.06
DocSys_V1.05
DocSys_V1.04
DocSys_V1.03
DocSys_V1.02
DocSys_V1.01
master
分支 (22)
标签 (21)
master
dev_DocSys_AddGit_Rainy
DocSys_bld_1.18
DocSys_bld_1.15
DocSys_bld_1.16
DocSys_bld_1.14
dev_DocSys_GD_1.13
DocSys_bld_1.13
DocSys_bld_1.12
DocSys_bld_1.11
DocSys_bld_1.10
dev_DocSys_GD
DocSys_bld_1.09
DocSys_bld_1.08
DocSys_bld_1.07
DocSys_bld_1.06
DocSys_bld_1.05
DocSys_bld_1.04
DocSys_bld_1.03
DocSys_bld_1.02
DocSys_V1.17.10
DocSys_V1.17.9
DocSys_V1.17.8
DocSys_V1.17
DocSys_V1.16
DocSys_V1.15
DocSys_V1.14
DocSys_V1.13
DocSys_V1.12
DocSys_V1.11
DocSys_V1.10
DocSys_V1.09
DocSys_V1.08
DocSys_V1.07
DocSys_V1.06
DocSys_V1.05
DocSys_V1.04
DocSys_V1.03
DocSys_V1.02
DocSys_V1.01
克隆/下载
克隆/下载
提示
下载代码请复制以下命令到终端执行
为确保你提交的代码身份被 Gitee 正确识别,请执行以下命令完成配置
初次使用 SSH 协议进行代码克隆、推送等操作时,需按下述提示完成 SSH 配置
1 生成 RSA 密钥
2 获取 RSA 公钥内容,并配置到 SSH公钥
在 Gitee 上使用 SVN,请访问 使用指南
使用 HTTPS 协议时,命令行会出现如下账号密码验证步骤。基于安全考虑,Gitee 建议 配置并使用私人令牌 替代登录密码进行克隆、推送等操作
Username for 'https://gitee.com': userName
Password for 'https://userName@gitee.com': # 私人令牌
master
分支 (22)
标签 (21)
master
dev_DocSys_AddGit_Rainy
DocSys_bld_1.18
DocSys_bld_1.15
DocSys_bld_1.16
DocSys_bld_1.14
dev_DocSys_GD_1.13
DocSys_bld_1.13
DocSys_bld_1.12
DocSys_bld_1.11
DocSys_bld_1.10
dev_DocSys_GD
DocSys_bld_1.09
DocSys_bld_1.08
DocSys_bld_1.07
DocSys_bld_1.06
DocSys_bld_1.05
DocSys_bld_1.04
DocSys_bld_1.03
DocSys_bld_1.02
DocSys_V1.17.10
DocSys_V1.17.9
DocSys_V1.17.8
DocSys_V1.17
DocSys_V1.16
DocSys_V1.15
DocSys_V1.14
DocSys_V1.13
DocSys_V1.12
DocSys_V1.11
DocSys_V1.10
DocSys_V1.09
DocSys_V1.08
DocSys_V1.07
DocSys_V1.06
DocSys_V1.05
DocSys_V1.04
DocSys_V1.03
DocSys_V1.02
DocSys_V1.01
DocSys
/
src
/
poiTest.java
DocSys
/
src
/
poiTest.java
poiTest.java 12.04 KB
一键复制 编辑 原始数据 按行查看 历史
Rainy 提交于 2018年11月17日 16:09 +08:00 . 全文搜索实现: 基本搞定,需要做一下压力测试
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.text.PDFTextStripper;
import org.apache.poi.hslf.extractor.PowerPointExtractor;
import org.apache.poi.hssf.extractor.ExcelExtractor;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hwpf.HWPFDocument;
import org.apache.poi.hwpf.usermodel.Paragraph;
import org.apache.poi.hwpf.usermodel.Range;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.xslf.extractor.XSLFPowerPointExtractor;
import org.apache.poi.xslf.usermodel.XMLSlideShow;
import org.apache.poi.xssf.extractor.XSSFExcelExtractor;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.apache.poi.xwpf.extractor.XWPFWordExtractor;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
@SuppressWarnings("deprecation")
class poiTest
{
public static void main(String[] args)
{
String content = readWord("C:\\Users\\Administrator\\Downloads\\高級日本語中間テスト2016年11月送印.doc");
content = readWord("C:/Users/Administrator/Downloads/Debate (1).pptx");
System.out.println(content);
content = readWordDocx("C:/Users/Administrator/Downloads/Debate (1).pptx");
//content = readWordDocx("C:/Users/Administrator/Desktop/HashMap/ddddddddddd.docx");
System.out.println(content);
content = getTextFromExcel("C:/Users/Administrator/Downloads/Debate (1).pptx");
//content = getTextFromExcel("C:\\Users\\Administrator\\Downloads\\CommitFailTest.xls");
System.out.println(content);
content = getTextFromExcel2007("C:/Users/Administrator/Downloads/Debate (1).pptx");
//content = getTextFromExcel2007("C:\\Users\\Administrator\\Downloads\\圆图网络公司账目 (1).xlsx");
System.out.println(content);
content = readPdf("C:/Users/Administrator/Downloads/Debate (1).pptx");
//content = readPdf("C:/Users/Administrator/Downloads/111111111111111111.pdf");
System.out.println(content);
content = getTextFromPPT2007("C:/Users/Administrator/Downloads/Debate (1).pptx");
System.out.println(content);
content = readFile("C:\\Users\\Administrator\\Downloads\\ecs_migration_list_cn-hangzhou-dg-a01_2018年10月16日.csv");
System.out.println(content);
}
public static String readWord(String path) {
StringBuffer content = new StringBuffer("");// 文档内容
try {
@SuppressWarnings("resource")
HWPFDocument doc = new HWPFDocument(new FileInputStream(path));
Range range = doc.getRange();
int paragraphCount = range.numParagraphs();// 段落
for (int i = 0; i < paragraphCount; i++) {// 遍历段落读取数据
Paragraph pp = range.getParagraph(i);
content.append(pp.text());
}
} catch (Exception e) {
e.printStackTrace();
}
return content.toString().trim();
}
@SuppressWarnings("resource")
public static String readWordDocx(String path){
File file = new File(path);
String str = "";
try {
FileInputStream fis = new FileInputStream(file);
XWPFDocument xdoc = new XWPFDocument(fis);
XWPFWordExtractor extractor = new XWPFWordExtractor(xdoc);
str = extractor.getText();
fis.close();
} catch (Exception e) {
e.printStackTrace();
}
return str;
}
//直接读取Excel97-2003的全部内容 xls
public static String getTextFromExcel(String filePath){
InputStream is = null;
HSSFWorkbook wb = null;
String text="";
try {
is = new FileInputStream(filePath);
wb = new HSSFWorkbook(new POIFSFileSystem(is));
ExcelExtractor extractor=new ExcelExtractor(wb);
extractor.setFormulasNotResults(false);
extractor.setIncludeSheetNames(true);
text=extractor.getText();
extractor.close();
} catch (FileNotFoundException e) {
System.out.println("没有找到指定路径"+filePath);
e.printStackTrace();
} catch (IOException e) {
System.out.println("getTextFromExcel IO错误");
e.printStackTrace();
}
return text;
}
//读取Excel2007+的全部内容 xlsx
public static String getTextFromExcel2007(String filePath) {
InputStream is = null;
XSSFWorkbook workBook = null;
String text="";
try {
is = new FileInputStream(filePath);
workBook = new XSSFWorkbook(is);
XSSFExcelExtractor extractor=new XSSFExcelExtractor(workBook);
text=extractor.getText();
extractor.close();
} catch (FileNotFoundException e) {
System.out.println("没有找到指定路径"+filePath);
e.printStackTrace();
} catch (IOException e) {
System.out.println("getTextFromExcel2007 IO错误");
e.printStackTrace();
}
return text;
}
public static String readPdf(String path) {
File pdfFile=new File(path);
PDDocument document = null;
String content = "";
try
{
document=PDDocument.load(pdfFile);
int pages = document.getNumberOfPages();
// 读文本内容
PDFTextStripper stripper=new PDFTextStripper();
// 设置按顺序输出
stripper.setSortByPosition(true);
stripper.setStartPage(1);
stripper.setEndPage(pages);
content = stripper.getText(document);
System.out.println(content);
}
catch(Exception e)
{
System.out.println(e);
}
return content;
}
public static String getTextFromPPT(String filePath) {
InputStream is = null;
PowerPointExtractor extractor = null;
String text="";
try {
is = new FileInputStream(filePath);
extractor = new PowerPointExtractor(is);
text=extractor.getText();
extractor.close();
} catch (FileNotFoundException e) {
System.out.println("没有找到指定路径"+filePath);
e.printStackTrace();
} catch (IOException e) {
System.out.println("getTextFromPPT IO错误");
e.printStackTrace();
}
return text;
}
//抽取幻灯片2007+全部内容 pptx
public static String getTextFromPPT2007(String filePath){
InputStream is = null;
XMLSlideShow slide = null;
String text="";
try {
is = new FileInputStream(filePath);
slide = new XMLSlideShow(is);
XSLFPowerPointExtractor extractor=new XSLFPowerPointExtractor(slide);
text=extractor.getText();
extractor.close();
} catch (FileNotFoundException e) {
System.out.println("没有找到指定路径"+filePath);
e.printStackTrace();
} catch (IOException e) {
System.out.println("getTextFromPPT2007 IO错误");
e.printStackTrace();
}
return text;
}
/**
* 获取文件格式
* @param path
* @return
*/
public static String getFileEncode(String path) {
String charset ="asci";
byte[] first3Bytes = new byte[3];
BufferedInputStream bis = null;
try {
boolean checked = false;
bis = new BufferedInputStream(new FileInputStream(path));
bis.mark(0);
int read = bis.read(first3Bytes, 0, 3);
if (read == -1)
return charset;
if (first3Bytes[0] == (byte) 0xFF && first3Bytes[1] == (byte) 0xFE) {
charset = "Unicode";//UTF-16LE
checked = true;
} else if (first3Bytes[0] == (byte) 0xFE && first3Bytes[1] == (byte) 0xFF) {
charset = "Unicode";//UTF-16BE
checked = true;
} else if (first3Bytes[0] == (byte) 0xEF && first3Bytes[1] == (byte) 0xBB && first3Bytes[2] == (byte) 0xBF) {
charset = "UTF8";
checked = true;
}
bis.reset();
if (!checked) {
int len = 0;
int loc = 0;
while ((read = bis.read()) != -1) {
loc++;
if (read >= 0xF0)
break;
if (0x80 <= read && read <= 0xBF) //单独出现BF以下的,也算是GBK
break;
if (0xC0 <= read && read <= 0xDF) {
read = bis.read();
if (0x80 <= read && read <= 0xBF)
//双字节 (0xC0 - 0xDF) (0x80 - 0xBF),也可能在GB编码内
continue;
else
break;
} else if (0xE0 <= read && read <= 0xEF) { //也有可能出错,但是几率较小
read = bis.read();
if (0x80 <= read && read <= 0xBF) {
read = bis.read();
if (0x80 <= read && read <= 0xBF) {
charset = "UTF-8";
break;
} else
break;
} else
break;
}
}
//TextLogger.getLogger().info(loc + " " + Integer.toHexString(read));
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if (bis != null) {
try {
bis.close();
} catch (IOException ex) {
}
}
}
return charset;
}
/**
* 通过路径获取文件的内容,这个方法因为用到了字符串作为载体,为了正确读取文件(不乱码),只能读取文本文件,安全方法
* @param path
* @return txt
*/
public static String readFile(String path){
String data = null;
// 判断文件是否存在
File file = new File(path);
if(!file.exists()){
return data;
}
// 获取文件编码格式
String code = getFileEncode(path);
InputStreamReader isr = null;
try{
// 根据编码格式解析文件
if("asci".equals(code)){
// 这里采用GBK编码,而不用环境编码格式,因为环境默认编码不等于操作系统编码
// code = System.getProperty("file.encoding");
code = "GBK";
}
isr = new InputStreamReader(new FileInputStream(file),code);
// 读取文件内容
int length = -1 ;
char[] buffer = new char[1024];
StringBuffer sb = new StringBuffer();
while((length = isr.read(buffer, 0, 1024) ) != -1){
sb.append(buffer,0,length);
}
data = new String(sb);
}catch(Exception e){
e.printStackTrace();
}finally{
try {
if(isr != null){
isr.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
return data;
}
}
Loading...
举报
举报成功
我们将于2个工作日内通过站内信反馈结果给你!
请认真填写举报原因,尽可能描述详细。
请选择举报类型
取消
发送
误判申诉

此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。

如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。

取消
提交

简介

DocSys是基于Java开发的Web文件管理系统,旨在为个人和企业用户提供一个简单、方便、安全的文件存储方案,采用Windows桌面系统和Apple手机的用户操作习惯,支持使用SVN和GIT进行历史版本管理、支持文件加密、支持文件内容全文搜索、支持文件预览、支持文件权限管理、支持用户分组管理,支持扩展和定制。GPL 2.0开源协议.
取消

发行版

暂无发行版

贡献者

全部

近期动态

不能加载更多了
编辑仓库简介
简介内容
主页
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Java
1
https://gitee.com/java-utils/DocSys.git
git@gitee.com:java-utils/DocSys.git
java-utils
DocSys
DocSys
master
点此查找更多帮助

搜索帮助

评论
仓库举报
回到顶部
登录提示
该操作需登录 Gitee 帐号,请先登录后再操作。
立即登录
没有帐号,去注册

AltStyle によって変換されたページ (->オリジナル) /