!77 xlsm等格式类型转换成HTML

Merge pull request !77 from 高雄/master
pull/78/head
kailing 2023-03-21 08:16:43 +00:00 committed by Gitee
commit c355c915f8
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
4 changed files with 615 additions and 288 deletions

View File

@ -47,7 +47,7 @@ public class OfficeFilePreviewImpl implements FilePreview {
String fileName = fileAttribute.getName(); String fileName = fileAttribute.getName();
String filePassword = fileAttribute.getFilePassword(); String filePassword = fileAttribute.getFilePassword();
String userToken = fileAttribute.getUserToken(); String userToken = fileAttribute.getUserToken();
boolean isHtml = suffix.equalsIgnoreCase("xls") || suffix.equalsIgnoreCase("xlsx") || suffix.equalsIgnoreCase("csv"); boolean isHtml = suffix.equalsIgnoreCase("xls") || suffix.equalsIgnoreCase("xlsx") || suffix.equalsIgnoreCase("csv") || suffix.equalsIgnoreCase("xlsm") || suffix.equalsIgnoreCase("xlt") || suffix.equalsIgnoreCase("xltm") || suffix.equalsIgnoreCase("et") || suffix.equalsIgnoreCase("ett") || suffix.equalsIgnoreCase("xlam");
String pdfName = fileName.substring(0, fileName.lastIndexOf(".") + 1) + (isHtml ? "html" : "pdf"); String pdfName = fileName.substring(0, fileName.lastIndexOf(".") + 1) + (isHtml ? "html" : "pdf");
String cacheFileName = userToken == null ? pdfName : userToken + "_" + pdfName; String cacheFileName = userToken == null ? pdfName : userToken + "_" + pdfName;
String outFilePath = FILE_DIR + cacheFileName; String outFilePath = FILE_DIR + cacheFileName;

View File

@ -1,4 +1,4 @@
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head> <head>
@ -45,6 +45,8 @@
</div> </div>
<div id="zoomSelect" class="select-icon" title="缩放比例"> <div id="zoomSelect" class="select-icon" title="缩放比例">
<select id="zoomValue"> <select id="zoomValue">
<option value="width"></option>
<option value="4.0">400%</option>
<option value="3.0">300%</option> <option value="3.0">300%</option>
<option value="2.0">200%</option> <option value="2.0">200%</option>
<option value="1.5">150%</option> <option value="1.5">150%</option>

View File

@ -53,6 +53,7 @@ window.onresize = function() {
} (); } ();
}; };
// 手机端,隐藏缩放比例选择框,打开文件和打印按钮
if (this.isMobile()) { if (this.isMobile()) {
if (document.getElementById("zoomSelect")) document.getElementById("zoomSelect").style.display = "none"; if (document.getElementById("zoomSelect")) document.getElementById("zoomSelect").style.display = "none";
if (document.getElementById("openFile")) document.getElementById("openFile").style.display = "none"; if (document.getElementById("openFile")) document.getElementById("openFile").style.display = "none";
@ -61,11 +62,12 @@ if (this.isMobile()) {
if (document.getElementById("separator2")) document.getElementById("separator2").style.display = "none"; if (document.getElementById("separator2")) document.getElementById("separator2").style.display = "none";
} }
// 判断手机端还是PC端
function isMobile() { function isMobile() {
var flag = navigator.userAgent.match(/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i); var flag = navigator.userAgent.match(/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i);
return flag; return flag;
} }
// 判断是否IE浏览器
function isIE() { function isIE() {
var navigator = window.navigator.userAgent; var navigator = window.navigator.userAgent;
if (navigator.indexOf("MSIE") > 0 || navigator.indexOf("Trident") > 0) { if (navigator.indexOf("MSIE") > 0 || navigator.indexOf("Trident") > 0) {
@ -96,9 +98,33 @@ data: function data() {
}; };
} }
this.pageZoomScale = "1.0";
cnofd["setScaleValue"](this.pageZoomScale);
var scale = this.getQueryVariable("scale");
if (scale && (scale == "width" || Number(scale))) {
this.pageZoomScale = scale;
cnofd["setScaleValue"](scale);
}
var file = this.getQueryVariable("file"); var file = this.getQueryVariable("file");
if (file) this.loadOfdFile(file); if (file) this.loadOfdFile(file);
if (scale && (scale == "width" || Number(scale))) {
var selectZoom = document.getElementById("zoomValue");
selectZoom.selectedIndex = -1;
if (this.pageZoomScale == "width") {
selectZoom.selectedIndex = 0;
} else {
for (var i = 1; i < selectZoom.length; i++) {
if (Math.abs(this.pageZoomScale - selectZoom.options[i].value) < 0.01) {
selectZoom.selectedIndex = i;
break;
}
}
}
}
function getQueryVariable(variable) { function getQueryVariable(variable) {
var query = window.location.search.substring(1); var query = window.location.search.substring(1);
var vars = query.split("&"); var vars = query.split("&");
@ -125,8 +151,7 @@ function loadOfdFile(ofdFile) {
that.ofdBase64 = base64String; that.ofdBase64 = base64String;
} }
}); });
ofdFile = ofdFile = decodeURIComponent(ofdFile); this.getOfdDocument(ofdFile, this.screenWidth, this.pageZoomScale);
this.getOfdDocument(ofdFile, this.screenWidth);
setPageInfo(); setPageInfo();
} }
@ -170,10 +195,12 @@ function fileChanged() {
return; return;
} }
Object(cnofd["setScaleValue"])(1.0); // 新打开OFD文件时还原成页面实际尺寸显示
//Object(cnofd["setScaleValue"])(1.0);
Object(cnofd["setScaleValue"])(this.pageZoomScale);
var selectZoom = document.getElementById("zoomValue"); var selectZoom = document.getElementById("zoomValue");
if (selectZoom) if (selectZoom)
selectZoom.value = "1.0"; selectZoom.value = this.pageZoomScale;
var that = this; var that = this;
var reader = new FileReader(); var reader = new FileReader();
@ -183,10 +210,11 @@ function fileChanged() {
that.ofdBase64 = e.target.result.split(",")[1]; that.ofdBase64 = e.target.result.split(",")[1];
}; };
this.getOfdDocument(this.file, this.screenWidth); this.getOfdDocument(this.file, this.screenWidth, this.pageZoomScale);
//$("#file")[0].value = null;
} }
function getOfdDocument(file, screenWidth) { function getOfdDocument(file, screenWidth, pageZoomScale) {
var that = this; var that = this;
$("#loading").show(); $("#loading").show();
@ -199,14 +227,18 @@ function getOfdDocument(file, screenWidth) {
that.ofdDoc = res; that.ofdDoc = res;
that.pageIndex = 1; that.pageIndex = 1;
that.pageCount = res.pageCount; that.pageCount = res.pageCount;
if (pageZoomScale == "width") {
var divs = Object(cnofd["ofdRender"])(res, screenWidth); var divs = Object(cnofd["ofdRender"])(res, screenWidth);
that.displayOfdDiv(divs); that.displayOfdDiv(divs);
} else {
var divs = Object(cnofd["ofdRenderByScale"])(res, screenWidth, pageZoomScale);
that.displayOfdDiv(divs);
}
$("#loading").hide(); $("#loading").hide();
}, },
fail: function fail(error) { fail: function fail(error) {
$("#loading").hide(); $("#loading").hide();
alert("OFD打开失败", error, {
that.$alert("OFD打开失败", error, {
confirmButtonText: "确定", confirmButtonText: "确定",
callback: function callback(action) { callback: function callback(action) {
this.$message({ this.$message({
@ -242,7 +274,7 @@ function displayOfdDiv(divs) {
function zoomIn() { function zoomIn() {
var selectZoom = document.getElementById("zoomValue"); var selectZoom = document.getElementById("zoomValue");
if (selectZoom.selectedIndex > 0) { if (selectZoom.selectedIndex > 1) {
selectZoom.selectedIndex = selectZoom.selectedIndex - 1; selectZoom.selectedIndex = selectZoom.selectedIndex - 1;
Object(cnofd["setScaleValue"])(selectZoom.options[selectZoom.selectedIndex].value); Object(cnofd["setScaleValue"])(selectZoom.options[selectZoom.selectedIndex].value);
@ -259,6 +291,7 @@ function zoomOut() {
var selectZoom = document.getElementById("zoomValue"); var selectZoom = document.getElementById("zoomValue");
if (selectZoom.selectedIndex < selectZoom.length-1) { if (selectZoom.selectedIndex < selectZoom.length-1) {
selectZoom.selectedIndex = selectZoom.selectedIndex + 1; selectZoom.selectedIndex = selectZoom.selectedIndex + 1;
if (selectZoom.selectedIndex == 0) selectZoom.selectedIndex = 1;
Object(cnofd["setScaleValue"])(selectZoom.options[selectZoom.selectedIndex].value); Object(cnofd["setScaleValue"])(selectZoom.options[selectZoom.selectedIndex].value);
var divs = Object(cnofd["ofdRenderByScale"])(this.ofdDoc); var divs = Object(cnofd["ofdRenderByScale"])(this.ofdDoc);
@ -272,6 +305,15 @@ function zoomOut() {
function zoomChange() { function zoomChange() {
var selectZoom = document.getElementById("zoomValue"); var selectZoom = document.getElementById("zoomValue");
if (selectZoom.options[selectZoom.selectedIndex].value == "width") {
Object(cnofd["setScaleValue"])(selectZoom.options[selectZoom.selectedIndex].value);
var divs = Object(cnofd["ofdRender"])(this.ofdDoc, this.screenWidth);
if (divs) {
this.displayOfdDiv(divs);
} else {
this.getOfdDocument(this.file, this.screenWidth);
}
} else {
Object(cnofd["setScaleValue"])(selectZoom.options[selectZoom.selectedIndex].value); Object(cnofd["setScaleValue"])(selectZoom.options[selectZoom.selectedIndex].value);
var divs = Object(cnofd["ofdRenderByScale"])(this.ofdDoc); var divs = Object(cnofd["ofdRenderByScale"])(this.ofdDoc);
if (divs) { if (divs) {
@ -279,6 +321,7 @@ function zoomChange() {
} else { } else {
this.getOfdDocument(this.file, this.screenWidth); this.getOfdDocument(this.file, this.screenWidth);
} }
}
} }
function scrool() { function scrool() {
@ -399,7 +442,9 @@ function print() {
} }
} }
// IE浏览器在iframe里调用打印
function printIE(printhtml) { function printIE(printhtml) {
//新建一个iframe
var iframe = document.createElement("iframe"); var iframe = document.createElement("iframe");
iframe.id = "printf"; iframe.id = "printf";
iframe.style.width = "0"; iframe.style.width = "0";
@ -407,6 +452,7 @@ function printIE(printhtml) {
iframe.style.height = "0"; iframe.style.height = "0";
iframe.style.border = "none"; iframe.style.border = "none";
//将iframe插入到printBody里
document.body.appendChild(iframe); document.body.appendChild(iframe);
setTimeout(function () { setTimeout(function () {

File diff suppressed because it is too large Load Diff