Tag: spring

使用spring hibernate将mysql表导出为ex​​cel

我试图导出数据在MySQL表中使用春季hibernateExcel。 我的excel导出后没有数据。 您的帮助将不胜感激。 这是我的代码below.Thanks提前 ExcelExport.java @Override protected void buildExcelDocument(Map<String, Object> model, HSSFWorkbook workbook, HttpServletRequest request, HttpServletResponse response) throws Exception { @SuppressWarnings("unchecked") List<MOH> mohs = (List<MOH>) model.get("mohs"); HSSFSheet sheet = workbook.createSheet("MOH Form") HSSFRow header = sheet.createRow(0); header.createCell(0).setCellValue("ID"); header.getCell(0).setCellStyle(style); header.createCell(1).setCellValue("Data"); header.getCell(1).setCellStyle(style); int rowCount = 1; for (MOH aBook : mohs) { HSSFRow aRow = sheet.createRow(rowCount++); aRow.createCell(0).setCellValue(aBook.getSurvey_id()); aRow.createCell(1).setCellValue(aBook.getName()); […]

使用spring批处理和apache poi写入来自多个源的数据

我目前有一个可用的Spring批处理应用程序,它使用ItemReader从Oracle数据库中读取SQL视图,并将该数据写入Excel文件。 但是,我想从多个视图中读取数据并写入同一个Excel文件 – 我该如何实现? 码: <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:batch="http://www.springframework.org/schema/batch" xmlns:context="http://www.springframework.org/schema/context" xmlns:jdbc="http://www.springframework.org/schema/jdbc" xmlns:c24="http://schema.c24.biz/spring-core" xmlns:bat-c24="http://schema.c24.biz/spring-batch" xmlns:util="http://www.springframework.org/schema/util" xsi:schemaLocation=" http://www.springframework.org/schema/batch http://www.springframework.org/schema/batch/spring-batch-2.1.xsd http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.2.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.2.xsd http://schema.c24.biz/spring-core http://schema.c24.biz/spring-core.xsd http://schema.c24.biz/spring-batch http://schema.c24.biz/spring-batch.xsd"> <bean id="launchHelper" class="com.launcher.management.DummyPreJobHelper" /> <bean id="rowMapper" class="com.exporter.DynamicComplexDataObjectRowMapper"/> <bean id="itemReader" class="com.exporter.ViewJdbcCursorItemReader" scope="step"> <property name="dataSource" ref="dataSource" /> <property name="viewName" value="V_CARS" /> <property name="fetchSize" value="5000" /> […]

如何在Spring映射中将列表的某些值设置为可选?

我想将以下列表中的某些值设置为可选,下面的映射将从Excel工作表中读取列并将其存储到数据库中。 但有些列可能不会在Excel表单中每次都出现,所以我想让一些列将remark12和remarks13为可选: <property name="remarkColumns"> <list> <value>remarks1</value> <value>remarks2</value> <value>remarks3</value> <value>remarks4</value> <value>remarks5</value> <value>remarks6</value> </list> </property> 请帮助解决scheme。

如何使用Spring响应下载excel文件

我试图通过使用Jasper Report 6.2.2来下载excel文件 这是我的spring控制器: @RequestMapping(value = "/downloadExcel", method = RequestMethod.POST) @ResponseBody public void downloadMyReportExcelFile(@RequestBody ExcelFilter excelFilter, HttpServletResponse response) { try { reportExportBo.downloadReportFile(response, excelFilter); } catch (Throwable e) { LOGGER.error("Unknown error at REST Service", e); } } 这里也是我的downloadReportFile方法代码: @Override public void downloadReportFile(HttpServletResponse response, ExcelFilter excelFilter) { List<myClassObject> myObjectList= objectRecordBo.myData(excelFilter); InputStream is = this.getClass().getClassLoader().getResourceAsStream("/my_reports.jrxml"); ExcelExporter exporter = […]

用于Java包的jar工具org.apache.poi.hssf.usermodel。*

我正在使用Spring / Hibernate(使用NetBeans 6.9.1)。 我需要将Excel工作表导入Oracle数据库(10g)。 我曾经访问过一些文章和教程,其中我find了相应的代码,但是包含此function所需的Java包org.apache.poi.hssf.usermodel.*的Jar实用程序尚未在互联网上find的这些教程中提到的任何一个。 所以只有一个问题 从哪里可以下载这个包含这个包org.apache.poi.hssf.usermodel.* jar工具? 这个包包含了Java类 org.apache.poi.hssf.usermodel.HSSFSheet; org.apache.poi.hssf.usermodel.HSSFWorkbook; org.apache.poi.hssf.usermodel.HSSFRow; org.apache.poi.hssf.usermodel.HSSFCell;

下载文件java spring rest api

我想做一个rest的API控制器(春季启动),当获得请愿将允许我下载一个Excel文件。 目前我有这个端点: @RequestMapping(value = "/download.xls", method = RequestMethod.GET) public ResponseEntity Survey_Reports(@RequestParam(value = "evaluated") String evaluated){ return surveyService.getSurveysFile(evaluated); } 最终会调用这个方法: public static ResponseEntity getDownloadResponse() { File file2Upload = new File("Survey_Reports.xls"); Path path = Paths.get(file2Upload.getAbsolutePath()); ByteArrayResource resource = null; try { resource = new ByteArrayResource(Files.readAllBytes(path)); } catch (IOException e) { logger.error("there was an error getting the file […]

要读取Excel,我们可以使用Spring批处理?

我想知道是否可以使用Spring Batch ,以便从文件Excel中读取并将其保存在数据库中。 备注:文件Excel的内容每2小时更改一次。 如果Spring Batch不可能,我还可以使用其他解决scheme

Spring,JXLS:XLS转换器不加载,尽pipe存在依赖关系。

我正在尝试使用JXLS ,这是一个Java库,用于在Spring-MVC项目中创buildexcel文件和其他操作。 当我尝试从某些数据中创build一个excel文件时,出现以下错误: 错误日志: java.lang.IllegalStateException: Cannot load XLS transformer. Please make sure a Transformer implementation is in classpath at org.jxls.util.JxlsHelper.createTransformer(JxlsHelper.java:200) at org.jxls.util.JxlsHelper.processTemplateAtCell(JxlsHelper.java:118) at com.journaldev.spring.service.GroupNotesServiceImpl.saveGroupNotesToExcel(GroupNotesServiceImpl.java:917) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:497) at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317) 代码: @Override public void saveGroupNotesToExcel(int msectionid){ List<GroupNotes> groupNotesList = this.groupNotesDAO.listGroupNotesBySectionId(msectionid); try(InputStream is = GroupNotesServiceImpl.class.getResourceAsStream("/home/path/to/jls/test.xls")) { try (OutputStream os = new […]

通用导出到Java对象的Excel

在我们的Spring项目中,我们有许多控制器接收客户端input(filter),这将从DB创builddynamic查询,结果集返回给客户端。 例如: public List<UserResultDTO> getUsers(Filter filter); public List<TransactionResultDTO> getTransactions(Filter filter); public List<ProfileResultDTO> getProfile(Filter filter); 我们的新要求非常简单:“请允许将这些结果列表导出到Excel文件中” 输出到excel文件的整个想法已经被处理了。 (我们有一个非常强大的Excel提供程序) 所以我们的目标基本上是创build一个非常通用的函数\服务,将采取一个列表,并将能够以通用的方式导出它。 任何想法什么是这种任务的最佳做法? 想法: 1)创build一个枚举,该列表将包含每个模型对象的所有configuration和列名(看起来非常冗余和维护地狱) 2)使用reflection也许? 甚至可能使用Excel列名的字段的注释 3)其他? 谢谢!

Java-Spring-JSP下载xls文件 – POST OK,GET不能正常工作

我可能会错过一些非常明显的东西,但不pipe我尝试让下载button工作,只有在完整的表单上使用POST,而不使用GET,我才需要(我不想发布该表单,因为我不回馈JSP所期望的string答案,而是一个附件下载)。 所以我得到了一个带有一个button的表单的JSP页面,用于下载一个生成的xls文件。 如果我张贴表单我得到xls下载。 这里是代码: @RequestMapping(params = "exportButton", method = RequestMethod.POST) public void exportXls(Model model, @ModelAttribute("form") XXXForm form, HttpServletResponse response) throws IOException { // generate xls… response.setContentType("application/vnd.ms-excel"); response.setHeader("Content-Disposition", "attachment; filename=xxx.xls"); workbook.write(response.getOutputStream()); //an api to generate xls workbook.close(); response.flushBuffer(); } } 所以这个工作很好张贴时: <form:form id="xxxForm" method="post" modelAttribute="xxxForm" cssClass="cleanform" action="xxx"> <button type="submit" id="exportButton" name="exportButton" class="printButton">Export</button> 但是如果我尝试使用get: <button type="button" id="exportButton" […]