<tfoot id='qHLOQ'></tfoot>
    <bdo id='qHLOQ'></bdo><ul id='qHLOQ'></ul>

<small id='qHLOQ'></small><noframes id='qHLOQ'>

<i id='qHLOQ'><tr id='qHLOQ'><dt id='qHLOQ'><q id='qHLOQ'><span id='qHLOQ'><b id='qHLOQ'><form id='qHLOQ'><ins id='qHLOQ'></ins><ul id='qHLOQ'></ul><sub id='qHLOQ'></sub></form><legend id='qHLOQ'></legend><bdo id='qHLOQ'><pre id='qHLOQ'><center id='qHLOQ'></center></pre></bdo></b><th id='qHLOQ'></th></span></q></dt></tr></i><div id='qHLOQ'><tfoot id='qHLOQ'></tfoot><dl id='qHLOQ'><fieldset id='qHLOQ'></fieldset></dl></div>

      <legend id='qHLOQ'><style id='qHLOQ'><dir id='qHLOQ'><q id='qHLOQ'></q></dir></style></legend>

      1. 如何在 Struts2 结果中返回 excel?

        how to return excel in Struts2 result?(如何在 Struts2 结果中返回 excel?)

          <legend id='rhQ2A'><style id='rhQ2A'><dir id='rhQ2A'><q id='rhQ2A'></q></dir></style></legend>

            <small id='rhQ2A'></small><noframes id='rhQ2A'>

            <i id='rhQ2A'><tr id='rhQ2A'><dt id='rhQ2A'><q id='rhQ2A'><span id='rhQ2A'><b id='rhQ2A'><form id='rhQ2A'><ins id='rhQ2A'></ins><ul id='rhQ2A'></ul><sub id='rhQ2A'></sub></form><legend id='rhQ2A'></legend><bdo id='rhQ2A'><pre id='rhQ2A'><center id='rhQ2A'></center></pre></bdo></b><th id='rhQ2A'></th></span></q></dt></tr></i><div id='rhQ2A'><tfoot id='rhQ2A'></tfoot><dl id='rhQ2A'><fieldset id='rhQ2A'></fieldset></dl></div>
              • <bdo id='rhQ2A'></bdo><ul id='rhQ2A'></ul>

              • <tfoot id='rhQ2A'></tfoot>
                  <tbody id='rhQ2A'></tbody>

                1. 本文介绍了如何在 Struts2 结果中返回 excel?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在尝试从我的 struts2 操作类返回 Excel 工作表.

                  I am trying to return an Excel sheet from my struts2 action class.

                  我不确定我应该使用什么结果类型?有没有人尝试从 struts2 动作类返回一个 excel?
                  我希望向用户显示打开/保存/取消对话框

                  I am not sure what result-type should I be using? Has anyone tried to return an excel from struts2 action class?
                  I would like the user to be presented with open/save/cancel dialog box

                  推荐答案

                  Omnipresent 涵盖了您在 struts.xml 中所需要的内容.我也在添加一个带有 Action 的示例:

                  Omnipresent covered what you need in struts.xml. I'm adding an example with the Action as well:

                  InputStream excelStream
                  String contentDisposition
                  String documentFormat = "xlsx"
                  
                  String excel() {
                  
                      ServletContext servletContext = ServletActionContext.getServletContext()
                      String filePath = servletContext.getRealPath("/WEB-INF/template/excel/mytemplate.${documentFormat}")
                  
                      File file = new File(filePath)
                      Workbook wb = WorkbookFactory.create(new FileInputStream(file))
                  
                      Sheet sheet = wb.getSheetAt(0)
                  
                  <write to excel file>
                  
                      ByteArrayOutputStream baos = new ByteArrayOutputStream()
                      wb.write(baos)
                      excelStream = new ByteArrayInputStream(baos.toByteArray())
                      contentDisposition = "filename="myfilename.${documentFormat}""
                  
                      return SUCCESS
                  }
                  
                  String getExcelContentType() {
                      return documentFormat == "xlsx" ? "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" : "application/vnd.ms-excel"
                  }
                  

                  我正在使用 poi 模型:org.apache.poi.ss.usermodel.

                  I'm using the poi model: org.apache.poi.ss.usermodel.

                  您可以根据需要将xlsx"替换为xls".

                  You can replace "xlsx" with "xls" if you want.

                  struts.xml:

                  struts.xml:

                  <action name="myaction" class="com.example.MyAction" method="excel">
                          <result type="stream">
                              <param name="contentType">${excelContentType}</param>
                              <param name="inputName">excelStream</param>
                              <param name="contentDisposition">contentDisposition</param>
                              <param name="bufferSize">1024</param>
                          </result>
                      </action>
                  

                  (添加分号和其他内容以转换为有效的 Java)

                  (add semicolons and stuff to translate to valid Java)

                  这篇关于如何在 Struts2 结果中返回 excel?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Java Bytecode Manipulation Library Suggestions(Java 字节码操作库建议)
                  Java CLI UI-design: frameworks or libraries?(Java CLI UI 设计:框架还是库?)
                  About the use of Beans.xml configuration file in Spring Framework application(关于Spring Framework应用中Beans.xml配置文件的使用)
                  What is the difference between Spring, Struts, Hibernate, JavaServer Faces, Tapestry?(Spring、Struts、Hibernate、JavaServer Faces、Tapestry 有什么区别?)
                  Are there any android application framework like spring?(有没有像spring这样的android应用程序框架?)
                  Java Swing based game framework. Any advice?(基于 Java Swing 的游戏框架.有什么建议吗?)
                  <legend id='yMXeR'><style id='yMXeR'><dir id='yMXeR'><q id='yMXeR'></q></dir></style></legend>
                      <tbody id='yMXeR'></tbody>

                    <tfoot id='yMXeR'></tfoot>
                    <i id='yMXeR'><tr id='yMXeR'><dt id='yMXeR'><q id='yMXeR'><span id='yMXeR'><b id='yMXeR'><form id='yMXeR'><ins id='yMXeR'></ins><ul id='yMXeR'></ul><sub id='yMXeR'></sub></form><legend id='yMXeR'></legend><bdo id='yMXeR'><pre id='yMXeR'><center id='yMXeR'></center></pre></bdo></b><th id='yMXeR'></th></span></q></dt></tr></i><div id='yMXeR'><tfoot id='yMXeR'></tfoot><dl id='yMXeR'><fieldset id='yMXeR'></fieldset></dl></div>
                        <bdo id='yMXeR'></bdo><ul id='yMXeR'></ul>

                          <small id='yMXeR'></small><noframes id='yMXeR'>