我想将搜索结果的jsp表导出到MSExcel'中;.xlsx'格式化文件

I want to export a jsp table of search results to an MS-Excel '.xlsx' format file

本文关键字:MSExcel 文件 格式化 xlsx 搜索结果 jsp      更新时间:2023-09-26

(已编辑)好的,让我更好地解释一下。我有一个搜索页面,可以根据不同的搜索条件查找员工。现在(由于QA阶段发生了范围蠕变),我想添加一个导出按钮,将过滤后的员工列表保存在MS Excel表格中。我一直在研究Birt报告的设计,但我不认为这是我想要的,因为它试图构建一个独立的报告。我只想把JSP页面表中显示的内容保存为excel。

 <div id="searchResultsContents">
        <p>Search Results:</p>
                <display:table class="cspTable"name="searchEmployees" sort="list"
                    pagesize="10" requestURI="employeeSearch.html" cellspacing="0" cellpadding="0"
                    defaultsort="1" defaultorder="ascending">
                    <display:column property="fullName" title="Name" class="namesColumn"
                        sortable="true" href="showUser.html" paramId="employeeId"
                        paramProperty="employeeID" />
                    <display:column property="occupationalTitle.titleName" title="Title"
                        sortable="true" />
                    <display:column property="email" title="Email"
                        sortable="true" />
                    <display:column property="cycle.cycleName" title="Cycle" 
                        sortable="true" />
                    <display:column property="realLocation.code" title="Location"
                        sortable="true" />
                    <display:column property="hireDate" title="Hire Date"
                        sortable="true" />
                </display:table>
            </div>
        </div>

感谢

Excel"知道"如何打开HTML/CSV文件,因此您可以执行以下操作:

  1. 在JSP的头上添加以下行:
    response.setHeader("Content-disposition:", "attachment; filename='excelfilename.xls';");
    response.setHeader("Authorization", request.getHeader("Authorization"));
    response.setContentType("application/vnd.ms-excel");
    response.setCharacterEncoding("UTF-8");

  2. 确保输出表是CSV或HTML"表"格式的

您正在使用DisplayTag库吗?它们包含一个导出过滤器(http://www.displaytag.org/10/export_filter.html),其可以以最小配置使用。