Tag: spring

无法用Angular JS和spring MVC打开下载文件

我在我的网站上实现了一个function,并使用Angular JS进行操作。 我已经实现了一个在服务器端 导出文件的服务 。 在客户端,我创build了一个“ EXPORT OPTION ”,然后当用户点击那个button时,用户可以下载文件(从我的服务端导出),并自动保存到本地机器的下载文件夹中。 我从这个问题的“tremendows”的答案中得到了这个想法: 如何使用AngularJS下载文件并调用MVC API? 一切都做得很好,但是,当我打开保存到下载文件夹中的文件,显示错误信息:“” Excel无法打开文件'filename.xlsx',因为文件扩展名的文件格式无效。 确认文件没有被损坏,并且文件的扩展名与文件的格式相匹配 。“ 我相信问题是从客户端出来的,因为当我在服务端运行服务(用于导出文件)时,文件被创build并正确打开,没有任何错误。 我一直在调查这个问题,然后我发现问题应该从文件path“.xlsx”中出来。 这里是在服务器端导出文件的java代码: @RequestMapping(value = "/exportFile", method = RequestMethod.GET) public String exportHRSalaryByAcc(HttpServletRequest request, HttpServletResponse response, @RequestParam(value = "month", defaultValue = "") String month) throws IOException, GeneralSecurityException, InvalidFormatException{ String rs = FALSE; response.addHeader("Access-Control-Allow-Origin", "*"); response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); //response.setContentType("application/x-felix; charset=us-ascii"); response.setHeader("Content-Transfer-Encoding", "7bit"); String […]

通过发送ajax请求下载Excel文件

我使用ajaxForm发送我的初始请求。 该方法被调用,所有的响应设置,但是当我试图打开窗口重新触发请求再次。 所以请求发送两次。以上是我的请求。 $('#reportForm').ajaxForm( { dataType :'json', type :'POST', url : 'report/initialRequest.html', beforeSubmit :validateSearchField, ifModified : true, success :function(data, textStatus, jqXHR){}, complete : function(jqXHR, textStatus) { window.location.href = "report/initialRequest.html" + "?" + $('#reportForm').formSerialize(); $.unblockUI(); return false; } }); 有办法可以阻止第二个请求被发送。 这样做的全部目的是生成的报告太大,所以当用户提交请求时,jasper报告需要很长时间才能得到文件,所以用户不知道文件到达的时间。 所以我使用了一个块UI插件,当用户点击提交button时页面被阻塞,文件一回来就解除了页面的阻塞。 或者任何机构对如何实现这一目标有更好的想法。 控制器代码 @RequestMapping( “/报告/ initialRequest.html”) public @ResponseBody Map<String, Object> handleInitialRequest (HttpSession session, HttpServletRequest request, […]

春季mvc Excel导出configuration

我有一个要求,当我们点击导出button时,使用spring mvc将数据导出到excel。 我已经使用AbstractExcelView在春季mvc导出excel表单。 遵循这个链接中提到的过程http://www.mkyong.com/spring-mvc/spring-mvc-export-data-to-excel-file-via-abstractexcelview/ 我面临的问题是configuration。 你可以解释如何configuration从jsp到控制器,然后控制器来查看导出数据到excel的类。

如何从jQuery下载excel获取ajax请求

我有一个弹簧MVC视图,它提供了一个excel文件,但是,现在我已经修改了这个过程,以便用户在下载excel之前获取一个模式框,在这个框中可以select一些选项。 这些选定的选项被发送到视图。 我的请求看起来像这样 $.get("downloadExcel", { 'foo': 'bar' }); 当这个请求,我期望文件被下载,但是,这并没有发生。 即使上面请求的响应头是: Cache-Control:private, must-revalidate Content-disposition:attachment; filename=filename.xls Content-Language:en-US Content-Type:application/vnd.ms-excel; charset=ISO-8859-1 Pragma:private Server:Jetty(6.1.14) Transfer-Encoding:chunked 注意 :当我删除对话框时,所有工作都很好,因此请求不再是ajax请求。 题 有没有办法通过ajax请求获取excel文件?

为什么我的代码跳过空白字段?

我使用Apache poi从excel文件中读取,但是当它涉及空单元格时,它会跳过单元格。 为什么这样? 我已经放了一个if else条件来捕捉它。 这是我的代码: while (cellIterator.hasNext()) { cell = (XSSFCell) cellIterator.next(); if(cell.getCellType() == Cell.CELL_TYPE_NUMERIC) { if(DateUtil.isCellDateFormatted(cell)) {

springAbstractExcelView和IE

我正在使用Spring的ContentNegotiatingViewResolver为了将数据导出到Excel文件。 这在Chrome和FireFox中是完美的,但是在IE浏览器中而不是下载文件浏览器显示乱码。 这是我的configuration片段: <bean class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver" p:order="1"> <property name="mediaTypes"> <map> <entry key="xml" value="application/xml" /> <entry key="txt" value="text/plain" /> <entry key="xls" value="application/vnd.ms-excel" /> <entry key="bin" value="multipart/form-data" /> </map> </property> <property name="defaultViews"> <list> <bean class="org.springframework.web.servlet.view.xml.MarshallingView"> <property name="marshaller" ref="oxmMarshaller" /> <property name="modelKey" value="response" /> </bean> <bean name="excel" class="myclass.MyExcelViewResolver" /> </list> </property> </bean> 有任何想法吗?

如何使用weburl中的REST API控制器返回xls excel文件响应

我需要返回x ls excel文件作为响应使用网页中的Rest API控制器在spring我没有从数据库获取数据只是设置固定值现在我写了控制器部分和服务pipe理器部分,但我发现以下错误: 在控制台中: 预计至less有1个有资格成为autowire候选人的bean。 并在浏览器中: Firefox不能在localhost:8080build立到服务器的连接。 控制器代码: @RestController @RequestMapping(value = "/excel") public class ExcelController { @CrossOrigin(origins = "*") catch (Exception e) { } return null; }

反应excel文件下载损坏

我试图通过调用Spring REST端点下载Reactjs中的Excel文件,但我遇到了一个损坏的文件的问题。 反应电话… getFile(){ axios.get('get/download') .then((response) => { var blob = new Blob([response.data], {type:'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'}); filesaver.saveAs(blob, "excel.xlsx"); }); } 弹簧控制器…. @RequestMapping(value = "/download", method = RequestMethod.GET) public void downloadExcelFile(final HttpServletResponse response) throws IOException { response.setHeader("Content-Encoding", "UTF-8"); response.setHeader("Content-Disposition", "attachment; filename="file.xlsx"); response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); final File xls = service.createExcelFile(response); final FileInputStream in = new FileInputStream(xls); final OutputStream out = response.getOutputStream(); […]

春季批 – 如何生成一个批处理作业的输出文件为Excel表

我有一个简单的弹簧批处理程序,它从INPUT文件读取数据并写入OUTPUT文件。 input文件有50000条logging,我的块大小是1000。 在input文件中有五列, 一二三四五 我的要求是创build一个Excel文件(.xls文件)作为输出。

无法使用spring + apache-poi上传excel文件

当我试图上传Excel文件( .xls / .xlsx )时,我得到以下exception: org.apache.poi.poifs.filesystem.OfficeXmlFileException: The supplied data appears to be in the Office 2007+ XML. You are calling the part of POI that deals with OLE2 Office Documents. You need to call a different part of POI to process this data (eg XSSF instead of HSSF) at org.apache.poi.poifs.storage.HeaderBlock.<init>(HeaderBlock.java:133) at org.apache.poi.poifs.storage.HeaderBlock.<init>(HeaderBlock.java:106) at org.apache.poi.poifs.filesystem.POIFSFileSystem.<init>(POIFSFileSystem.java:137) at […]