Hello , I have a controller to generate an excel file depending on some data. Now the excelfile is getting created but it is not giving me any download or opening option, it is roughly getting stacked in the web page in binary format.
this is my spring-servlet.xml for the view resolver:
and in prototype-views.xml I have :Code:<bean class="org.springframework.web.servlet.view.XmlViewResolver"> <property name="order" value="2"/> <property name="location" value="/WEB-INF/prototype-views.xml"/> </bean>
and the JXLDataSummary code is :Code:<bean id="jxlDataSummary" class="com.tcs.sbi.kycone.protype.views.JXLDataSummary"> </bean>
and part of the the controller is:Code:package com.tcs.sbi.kycone.protype.views; import java.io.IOException; import java.sql.SQLException; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.List; import java.util.Map; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import jxl.format.Alignment; import jxl.write.Label; import jxl.write.WritableCellFormat; import jxl.write.WritableFont; import jxl.write.WritableSheet; import jxl.write.WritableWorkbook; import jxl.write.WriteException; import jxl.write.biff.RowsExceededException; import org.springframework.web.servlet.view.document.AbstractJExcelView; import com.tcs.sbi.kycone.entities.KYC_Customer; import com.tcs.sbi.kycone.utils.JXLDataSummaryLayout; public class JXLDataSummary extends AbstractJExcelView { private WritableCellFormat times; private SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy"); @Override protected void buildExcelDocument(Map<String, Object> map, WritableWorkbook workbook, HttpServletRequest request, HttpServletResponse response) throws Exception { System.out.println("Invoking buildExcelDocument()"); workbook.createSheet("KYC-One Report", 0); WritableSheet sheet = JXLDataSummaryLayout.getLayout(workbook); @SuppressWarnings("unchecked") List<KYC_Customer> customers = (List<KYC_Customer>)map.get("customers"); createContent(sheet,sheet.getRows(),customers); } private void createContent(WritableSheet sheet,int row,List<KYC_Customer> customers) throws WriteException, RowsExceededException, SQLException, IOException, ClassNotFoundException, ParseException{ for (int i = row; i < customers.size()+row; i++) { System.out.println("Adding : "+customers.get(i - row)); KYC_Customer bean = (KYC_Customer) customers.get(i - row); addData(sheet, 0, i, bean.getKycId()); addData(sheet, 1, i, bean.getName()); addData(sheet, 2, i, bean.getSex().toString()); addData(sheet, 3, i, dateFormat.format(bean.getDob())); addData(sheet, 4, i, bean.getNationality().toString()); addData(sheet, 5, i, dateFormat.format(bean.getRegistrationDate())); addData(sheet, 6, i, bean.getLocation().getState()); } } private void addData(WritableSheet sheet, int column, int row, String str) throws WriteException, RowsExceededException { Label label; label = new Label(column, row, str, times); WritableCellFormat cf = new WritableCellFormat(); cf.setBorder(jxl.format.Border.ALL, jxl.format.BorderLineStyle.THIN); label.setCellFormat(cf); cf.setWrap(true); cf.setAlignment(Alignment.CENTRE); WritableFont f = new WritableFont(WritableFont.ARIAL, 10); cf.setFont(f); sheet.addCell(label); } }
It will be a great help to me if anyone help me understand , how can I get to download the generated excel file.Code:@RequestMapping(method=RequestMethod.POST) public String generateReport(@RequestParam("based_on") String based_on,@ModelAttribute("enquiryModel") KYC_Customer_Enquiry_Model enquiryModel,ModelMap modelMap){ List<KYC_Customer> customers = new ArrayList<KYC_Customer>(); ...................... System.out.println(customers); modelMap.addAttribute("customers",customers); return "jxlDataSummary";


Reply With Quote
