Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Omnipresent covered what you need in struts.xml. I'm adding an example with the Action as well:</p> <pre><code>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) &lt;write to excel file&gt; 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" } </code></pre> <p>I'm using the poi model: org.apache.poi.ss.usermodel.</p> <p>You can replace "xlsx" with "xls" if you want.</p> <p>struts.xml:</p> <pre><code>&lt;action name="myaction" class="com.example.MyAction" method="excel"&gt; &lt;result type="stream"&gt; &lt;param name="contentType"&gt;${excelContentType}&lt;/param&gt; &lt;param name="inputName"&gt;excelStream&lt;/param&gt; &lt;param name="contentDisposition"&gt;contentDisposition&lt;/param&gt; &lt;param name="bufferSize"&gt;1024&lt;/param&gt; &lt;/result&gt; &lt;/action&gt; </code></pre> <p>(add semicolons and stuff to translate to valid Java)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload