commit 8527144e729b655fae9b902926cd16badf1cd837 Author: richie Date: Tue Nov 12 10:53:23 2019 +0800 新word导出插件 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c03e859 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +*.iml +lib/report/*.jar +.DS_Store +.idea/ \ No newline at end of file diff --git a/build.xml b/build.xml new file mode 100644 index 0000000..c8ef9b5 --- /dev/null +++ b/build.xml @@ -0,0 +1,130 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/lib/finekit-10.0.jar b/lib/finekit-10.0.jar new file mode 100644 index 0000000..1b13991 Binary files /dev/null and b/lib/finekit-10.0.jar differ diff --git a/plugin.xml b/plugin.xml new file mode 100644 index 0000000..32bbb3a --- /dev/null +++ b/plugin.xml @@ -0,0 +1,27 @@ + + + com.fr.plugin.export.office.word + com.fr.plugin.export + + yes + 1.0 + 10.0 + 2019-09-25 + author + + + ]]> + + + + + + + + + + + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..c100a27 --- /dev/null +++ b/pom.xml @@ -0,0 +1,38 @@ + + + 4.0.0 + + + com.fr.plugin + starter + 10.0 + + + jar + plugin-report-export-word + + + com.fanruan.api + finekit + 10.0 + system + ${project.basedir}/lib/finekit-10.0.jar + + + + + ${project.basedir}/../webroot/WEB-INF/plugins/plugin-com.fr.plugin.export.office.word-1.0/classes + + + org.apache.maven.plugins + maven-compiler-plugin + + 6 + 6 + + + + + \ No newline at end of file diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..e982d95 --- /dev/null +++ b/readme.md @@ -0,0 +1,3 @@ +# 将报表导出为真word文件 + +报表目前导出的是一个rtf文件,不是真实的word文件,这个插件将把报表导出为真正的word文件。 \ No newline at end of file diff --git a/src/main/java/com/fr/plugin/export/office/word/WordExport.java b/src/main/java/com/fr/plugin/export/office/word/WordExport.java new file mode 100644 index 0000000..88ae110 --- /dev/null +++ b/src/main/java/com/fr/plugin/export/office/word/WordExport.java @@ -0,0 +1,23 @@ +package com.fr.plugin.export.office.word; + +import com.fr.plugin.export.office.word.fun.WordExportOperate; +import com.fr.report.fun.impl.AbstractExportOperateProvider; +import com.fr.web.core.reserve.Operate; + +/** + * @author richie + * @version 10.0 + * Created by richie on 2019/11/12 + */ +public class WordExport extends AbstractExportOperateProvider { + + @Override + public Operate operate() { + return new WordExportOperate(); + } + + @Override + public String markType() { + return "new_doc"; + } +} diff --git a/src/main/java/com/fr/plugin/export/office/word/WordExportToolbarUI.java b/src/main/java/com/fr/plugin/export/office/word/WordExportToolbarUI.java new file mode 100644 index 0000000..1aa4706 --- /dev/null +++ b/src/main/java/com/fr/plugin/export/office/word/WordExportToolbarUI.java @@ -0,0 +1,28 @@ +package com.fr.plugin.export.office.word; + +import com.fanruan.api.i18n.I18nKit; +import com.fr.design.fun.impl.AbstractToolbarItem; +import com.fr.form.ui.Widget; + +/** + * @author richie + * @version 10.0 + * Created by richie on 2019/11/12 + */ +public class WordExportToolbarUI extends AbstractToolbarItem { + + @Override + public Class classForWidget() { + return WordExtensionButton.class; + } + + @Override + public String iconPathForWidget() { + return "/com/fr/plugin/export/office/word/images/docx.png"; + } + + @Override + public String nameForWidget() { + return I18nKit.getLocText("Plugin-New_Export_Doc"); + } +} diff --git a/src/main/java/com/fr/plugin/export/office/word/WordExtensionButton.java b/src/main/java/com/fr/plugin/export/office/word/WordExtensionButton.java new file mode 100644 index 0000000..c5073a0 --- /dev/null +++ b/src/main/java/com/fr/plugin/export/office/word/WordExtensionButton.java @@ -0,0 +1,60 @@ +package com.fr.plugin.export.office.word; + +import com.fanruan.api.i18n.I18nKit; +import com.fr.form.ui.Widget; +import com.fr.js.JavaScript; +import com.fr.js.JavaScriptImpl; +import com.fr.plugin.export.office.word.fun.WordIconLoader; +import com.fr.report.fun.impl.AbstractExtensionButton; +import com.fr.stable.web.Repository; + +/** + * @author richie + * @version 10.0 + * Created by richie on 2019/11/12 + */ +public class WordExtensionButton extends AbstractExtensionButton { + + public WordExtensionButton() { + super(I18nKit.getLocText("Plugin-New_Export_Doc"), WordIconLoader.loadIcon()); + } + + public WordExtensionButton(String text) { + super(text); + } + + @Override + public Class classForDirectoryButton() { + return WordExtensionButton.class; + } + + @Override + public String getParentDirectory() { + return null; + } + + @Override + public String getType() { + return "WordExport.class"; + } + + @Override + public String getRelatedCheckBoxTitle() { + return null; + } + + @Override + public boolean isSelected() { + return false; + } + + @Override + public void setSelected(boolean b) { + + } + + @Override + protected JavaScript clickScript(Repository repository) { + return new JavaScriptImpl("_g().exportReportToNewWord()"); + } +} diff --git a/src/main/java/com/fr/plugin/export/office/word/WordFileHandler.java b/src/main/java/com/fr/plugin/export/office/word/WordFileHandler.java new file mode 100644 index 0000000..af98f90 --- /dev/null +++ b/src/main/java/com/fr/plugin/export/office/word/WordFileHandler.java @@ -0,0 +1,24 @@ +package com.fr.plugin.export.office.word; + +import com.fanruan.api.macro.EncodeConstants; +import com.fr.stable.fun.impl.AbstractJavaScriptFileHandler; + +/** + * @author richie + * @version 10.0 + * Created by richie on 2019/11/12 + */ +public class WordFileHandler extends AbstractJavaScriptFileHandler { + + @Override + public String[] pathsForFiles() { + return new String[]{ + "/com/fr/plugin/export/office/word/web/pane.extra.js" + }; + } + + @Override + public String encode() { + return EncodeConstants.ENCODING_UTF_8; + } +} diff --git a/src/main/java/com/fr/plugin/export/office/word/WordLocaleFinder.java b/src/main/java/com/fr/plugin/export/office/word/WordLocaleFinder.java new file mode 100644 index 0000000..b265551 --- /dev/null +++ b/src/main/java/com/fr/plugin/export/office/word/WordLocaleFinder.java @@ -0,0 +1,15 @@ +package com.fr.plugin.export.office.word; + +import com.fr.stable.fun.impl.AbstractLocaleFinder; + +/** + * @author richie + * @version 10.0 + * Created by richie on 2019/11/12 + */ +public class WordLocaleFinder extends AbstractLocaleFinder { + @Override + public String find() { + return "com/fr/plugin/export/office/word/locale/doc"; + } +} diff --git a/src/main/java/com/fr/plugin/export/office/word/fun/WordExportOperate.java b/src/main/java/com/fr/plugin/export/office/word/fun/WordExportOperate.java new file mode 100644 index 0000000..5d5af63 --- /dev/null +++ b/src/main/java/com/fr/plugin/export/office/word/fun/WordExportOperate.java @@ -0,0 +1,32 @@ +package com.fr.plugin.export.office.word.fun; + +import com.fanruan.api.report.export.BaseOperate; +import com.fr.general.DeclareRecordType; +import com.fr.io.collection.ExportCollection; +import com.fr.stable.web.SessionProvider; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +/** + * @author richie + * @version 10.0 + * Created by richie on 2019/11/12 + */ +public class WordExportOperate extends BaseOperate { + + @Override + public void setContent(HttpServletRequest req, HttpServletResponse res, SessionProvider sessionProvider, String fileName, boolean isEmbed) { + res.setContentType("application/octet-stream"); + res.setHeader("extension", "doc"); + res.setHeader("Content-disposition", "attachment; filename=" + fileName + ".doc"); + } + + @Override + public ExportCollection newExportCollection(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, SessionProvider sessionProvider, String s) { + ExportCollection collection = ExportCollection.create(); + collection.setExporter(new WordExporter()); + collection.setRecordType(DeclareRecordType.EXPORT_TYPE_WORD); + return collection; + } +} diff --git a/src/main/java/com/fr/plugin/export/office/word/fun/WordExporter.java b/src/main/java/com/fr/plugin/export/office/word/fun/WordExporter.java new file mode 100644 index 0000000..32521cf --- /dev/null +++ b/src/main/java/com/fr/plugin/export/office/word/fun/WordExporter.java @@ -0,0 +1,20 @@ +package com.fr.plugin.export.office.word.fun; + +import com.fanruan.api.report.export.BaseAppExporter; +import com.fr.main.workbook.ResultWorkBook; + +import java.io.OutputStream; + +/** + * @author richie + * @version 10.0 + * Created by richie on 2019/11/12 + * 在这里实现word的导出逻辑 + */ +public class WordExporter extends BaseAppExporter { + + @Override + public void export(OutputStream outputStream, ResultWorkBook resultWorkBook) throws Exception { + + } +} diff --git a/src/main/java/com/fr/plugin/export/office/word/fun/WordIconLoader.java b/src/main/java/com/fr/plugin/export/office/word/fun/WordIconLoader.java new file mode 100644 index 0000000..4689d7b --- /dev/null +++ b/src/main/java/com/fr/plugin/export/office/word/fun/WordIconLoader.java @@ -0,0 +1,17 @@ +package com.fr.plugin.export.office.word.fun; + +import com.fanruan.api.report.SundryKit; + +/** + * @author richie + * @version 10.0 + * Created by richie on 2019/11/12 + */ +public class WordIconLoader { + + public static String loadIcon() { + String name = "xml"; + SundryKit.loadToolbarIcon(name, "/com/fr/plugin/export/office/word/images/docx.png"); + return name; + } +} \ No newline at end of file diff --git a/src/main/resources/com/fr/plugin/export/office/word/images/docx.png b/src/main/resources/com/fr/plugin/export/office/word/images/docx.png new file mode 100644 index 0000000..a47d156 Binary files /dev/null and b/src/main/resources/com/fr/plugin/export/office/word/images/docx.png differ diff --git a/src/main/resources/com/fr/plugin/export/office/word/locale/doc.properties b/src/main/resources/com/fr/plugin/export/office/word/locale/doc.properties new file mode 100644 index 0000000..be77347 --- /dev/null +++ b/src/main/resources/com/fr/plugin/export/office/word/locale/doc.properties @@ -0,0 +1 @@ +Plugin-New_Export_Doc=New Doc(x) Export \ No newline at end of file diff --git a/src/main/resources/com/fr/plugin/export/office/word/locale/doc_zh_CN.properties b/src/main/resources/com/fr/plugin/export/office/word/locale/doc_zh_CN.properties new file mode 100644 index 0000000..c4b1e11 --- /dev/null +++ b/src/main/resources/com/fr/plugin/export/office/word/locale/doc_zh_CN.properties @@ -0,0 +1 @@ +Plugin-New_Export_Doc=\u5BFC\u51FAword(\u65B0) \ No newline at end of file diff --git a/src/main/resources/com/fr/plugin/export/office/word/web/pane.exta.js b/src/main/resources/com/fr/plugin/export/office/word/web/pane.exta.js new file mode 100644 index 0000000..95bd6af --- /dev/null +++ b/src/main/resources/com/fr/plugin/export/office/word/web/pane.exta.js @@ -0,0 +1,29 @@ +/** + * Created by richie on 16/1/21. + */ +(function($){ + // 你好啊,导出 + $.extend(FR.WritePane.prototype, { + exportReportToXML : function() { + if (this.fireEvent("beforenew_doc") === false) { + return; + } + var self = this; + this.saveReport(function () { + window.location = FR.servletURL + "?op=export&sessionID=" + self.currentSessionID + "&format=new_doc"; + FR.progressBar(self.currentSessionID,"new_doc"); + self.fireEvent("afternew_doc"); + }); + } + }); + $.extend(FR.PagePane.prototype, { + exportReportToXML : function() { + if (this.fireEvent("beforenew_doc") === false) { + return; + } + window.location = FR.servletURL + "?op=export&sessionID=" + this.currentSessionID + "&format=new_doc"; + FR.progressBar(this.currentSessionID, "new_doc"); + this.fireEvent("afternew_doc"); + } + }); +})(jQuery); \ No newline at end of file