本篇文章給大家分享的是有關(guān)Pageoffice如何結(jié)合fastdfs在線編輯及預(yù)覽office文檔,小編覺得挺實(shí)用的,因此分享給大家學(xué)習(xí),希望大家閱讀完這篇文章后可以有所收獲,話不多說,跟著小編一起來看看吧。
創(chuàng)新互聯(lián)建站"三網(wǎng)合一"的企業(yè)建站思路。企業(yè)可建設(shè)擁有電腦版、微信版、手機(jī)版的企業(yè)網(wǎng)站。實(shí)現(xiàn)跨屏營銷,產(chǎn)品發(fā)布一步更新,電腦網(wǎng)絡(luò)+移動網(wǎng)絡(luò)一網(wǎng)打盡,滿足企業(yè)的營銷需求!創(chuàng)新互聯(lián)建站具備承接各種類型的網(wǎng)站設(shè)計(jì)制作、成都網(wǎng)站設(shè)計(jì)項(xiàng)目的能力。經(jīng)過10余年的努力的開拓,為不同行業(yè)的企事業(yè)單位提供了優(yōu)質(zhì)的服務(wù),并獲得了客戶的一致好評。
背景:我們項(xiàng)目的文檔是存放在fastdfs服務(wù)器上面的,現(xiàn)有需求需要實(shí)現(xiàn)將fastdfs上面的各種office文檔在網(wǎng)站頁面進(jìn)行預(yù)覽和編輯保存
方案:由于fastdfs目前是不支持文檔的更新的,所以只能通過插入新文檔,刪除老文檔的方式來實(shí)現(xiàn),同時(shí)需要將原有數(shù)據(jù)庫表中存儲的文件uuid給更新掉,然后pageoffice只能支持文檔在本服務(wù)器內(nèi)的預(yù)覽和編輯,因此需要在應(yīng)用服務(wù)器中先下載fastdfs服務(wù)器中的文件,然后本地保存為臨時(shí)文件,然后給pageoffice預(yù)覽編輯,保存后再通過刪除和插入來更新fastdfs的文件,從而達(dá)到目的。
補(bǔ)充:需要定時(shí)清理由此產(chǎn)生的應(yīng)用服務(wù)器下載的臨時(shí)文件
大部分代碼可以參考pageoffice官網(wǎng)文檔中的
PageOffice 4.5 for JAVA (同時(shí)支持IE、Chrome、Firefox版)
PageOffice 4.5 for Spring Boot[示例代碼]
放代碼:
pageoffice初始配置類
@Configuration
public class PageOfficeConfiguration {
/**
* 添加PageOffice的服務(wù)器端授權(quán)程序Servlet(必須)
*/
@Bean
public ServletRegistrationBean servletRegistrationBean() {
com.zhuozhengsoft.pageoffice.poserver.Server poserver = new com.zhuozhengsoft.pageoffice.poserver.Server();
//設(shè)置PageOffice注冊成功后,license.lic文件存放的目錄
//服務(wù)器可以存放在/geelyapp/pageoffice
poserver.setSysPath("d:\\lic\\");
ServletRegistrationBean srb = new ServletRegistrationBean(poserver);
srb.addUrlMappings("/xx/pageoffice/poserver.zz");
srb.addUrlMappings("/xx/pageoffice/posetup.exe");
srb.addUrlMappings("/xx/pageoffice/pageoffice.js");
srb.addUrlMappings("/xx/pageoffice/jquery.min.js");
srb.addUrlMappings("/xx/pageoffice/pobstyle.css");
srb.addUrlMappings("/xx/pageoffice/sealsetup.exe");
return srb;//
}
}
應(yīng)用controller類
@Controller
@RequestMapping("/xx/pageoffice")
@Api(value = "文檔在線編輯接口")
public class PageOfficeController {
@Value("${pageoffice.path.doc:'D:/doc/'}")
private String pageofficeDocPath;
@Autowired
private StorageService storageService;//fastdfs封裝服務(wù)類
@Autowired
private ICommonUtilService commonUtilService;
private static final Logger LOGGER = LoggerFactory.getLogger(PageOfficeController.class);
@RequestMapping(value="/index", method=RequestMethod.GET)
public ModelAndView showIndex(
@ApiParam(name = "busi", required = true, value = "業(yè)務(wù)代碼")
@RequestParam(name = "busi", required = true) String busi,
@ApiParam(name = "filePath", required = true, value = "文件遠(yuǎn)程路徑(相對路徑,不是包含http的全路徑)")
@RequestParam(name = "filePath", required = true) String filePath,
Map<String,Object> map) {
map.put("busi",busi);
map.put("filePath",filePath);
ModelAndView mv = new ModelAndView("Index");
return mv;
}
@RequestMapping(value="/word", method=RequestMethod.GET)
public ModelAndView showWord(HttpServletRequest request, Map<String,Object> map,
@ApiParam(name = "busi", required = false, value = "業(yè)務(wù)代碼")
@RequestParam(name = "busi", required = false) String busi,
@ApiParam(name = "filePath", required = false, value = "文件遠(yuǎn)程路徑(相對路徑,不是包含http的全路徑)")
@RequestParam(name = "filePath", required = false) String filePath){
String[] param = busi.split("%");//這里因?yàn)槭褂?amp;符合傳遞多個(gè)參數(shù)時(shí)會導(dǎo)致被編譯為&導(dǎo)致無法調(diào)用成功
busi = param[0];
filePath = param[2];
// pageofficeDocPath = "D:\\doc\\"; //本地開發(fā)環(huán)境時(shí)可使用
String[] filePathArr = filePath.split("/");
String url = pageofficeDocPath+filePathArr[filePathArr.length-1];
LOGGER.info("showWord url:"+url);
File tmpFile = new File(url);
try (FileOutputStream fos = new FileOutputStream(tmpFile)){
fos.write(this.storageService.readFileContent(filePath));
} catch (Exception e) {
LOGGER.error("預(yù)覽臨時(shí)文件生成錯(cuò)誤",e);
throw BusinessException.withErrorCode(Errors.System.ILLEAGAL_DATA);
}
//--- PageOffice的調(diào)用代碼 開始 -----
PageOfficeCtrl poCtrl=new PageOfficeCtrl(request);
poCtrl.setServerPage("/xx/pageoffice/poserver.zz");//設(shè)置授權(quán)程序servlet
poCtrl.addCustomToolButton("保存","Save",1); //添加自定義按鈕
poCtrl.setSaveFilePage("/xx/pageoffice/save?filePath="+filePath+"&busi="+busi+"&url="+url);//設(shè)置保存時(shí)的action
String prefix = "file://";//linux服務(wù)器查找文件需要額外前綴
url = prefix + url;
LOGGER.info("showWord pageoffice url:"+url);
if(filePath.endsWith(".doc")||filePath.endsWith(".docx")) {
poCtrl.webOpen(url,OpenModeType.docAdmin,SessionContextUtil.getSrmUserName());
}else if(filePath.endsWith(".xls")||filePath.endsWith(".xlsx")) {
poCtrl.webOpen(url,OpenModeType.xlsNormalEdit,SessionContextUtil.getSrmUserName());
}else if(filePath.endsWith(".ppt")||filePath.endsWith(".pptx")) {
poCtrl.webOpen(url,OpenModeType.pptNormalEdit,SessionContextUtil.getSrmUserName());
}
map.put("pageoffice",poCtrl.getHtmlCode("PageOfficeCtrl1"));
//--- PageOffice的調(diào)用代碼 結(jié)束 -----
ModelAndView mv = new ModelAndView("Word");
return mv;
}
@RequestMapping("/save")
public void saveFile(HttpServletRequest request, HttpServletResponse response,
@ApiParam(name = "busi", required = true, value = "業(yè)務(wù)代碼")
@RequestParam(name = "busi", required = true) String busi,
@ApiParam(name = "url", required = false, value = "臨時(shí)文件url")
@RequestParam(name = "url", required = false) String url,
@ApiParam(name = "filePath", required = true, value = "文件遠(yuǎn)程路徑(相對路徑,不是包含http的全路徑)")
@RequestParam(name = "filePath", required = true) String filePath){
FileSaver fs = new FileSaver(request, response);
//由于fastdfs并不支持文件更新
//目前考慮刪除原有的文件,重新生成文件
//TODO 后面可以考慮支持文件的更新,即框架來做刪除插入,并且新插入的uuid需要跟刪除的一致
String newCode = this.storageService.store(fs.getFileName(), fs.getFileStream());
//將原來業(yè)務(wù)表中的文檔uuid更新
commonUtilService.updateFilePath(busi,filePath,newCode);
this.storageService.delete(filePath);
// fs.saveToFile(url);
fs.close();
File tmpFile = new File(url);
tmpFile.delete();
}
}
Index.ftl
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Index</title>
<script type="text/javascript" src="jquery.min.js"></script>
<script type="text/javascript" src="pageoffice.js" id="po_js_main"></script>
</head>
<body>
<h2>PageOffice預(yù)覽準(zhǔn)備</h2>
<a href="javascript:POBrowser.openWindowModeless('/xx/pageoffice/word?busi=${busi}%filePath%${filePath}','width=1200px;height=800px;');">打開文件 </a>
</body>
</html>
Word.ftl
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Hello World!</title>
<script type="text/javascript">
function Save() {
document.getElementById("PageOfficeCtrl1").WebSave();
}
</script>
<script type="text/javascript">
function AddSeal() {
try{
document.getElementById("PageOfficeCtrl1").ZoomSeal.AddSeal();
}catch (e){ };
}
</script>
</head>
<body>
<div >${pageoffice}</div>
</body>
</html>
以上就是Pageoffice如何結(jié)合fastdfs在線編輯及預(yù)覽office文檔,小編相信有部分知識點(diǎn)可能是我們?nèi)粘9ぷ鲿姷交蛴玫降?。希望你能通過這篇文章學(xué)到更多知識。更多詳情敬請關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。
文章名稱:Pageoffice如何結(jié)合fastdfs在線編輯及預(yù)覽office文檔
當(dāng)前路徑:http://muchs.cn/article16/jchdgg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供標(biāo)簽優(yōu)化、云服務(wù)器、移動網(wǎng)站建設(shè)、企業(yè)網(wǎng)站制作、Google、App設(shè)計(jì)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)