Solved

Export Excel file thru Spring MVC

Posted on 2010-11-24
11
3,667 Views
Last Modified: 2013-11-24
Hello,
Given a file already in excel format, i.e    temp.xls,
What is the best way to display this file, as a xml spreadsheet,  thru Spring MVC ?

The goal is to return new ModelAndView("?", model)
and have the excel spreadsheet rendered in a browser.

Thanks in advance..
0
Comment
Question by:Waponi
  • 5
  • 5
11 Comments
 
LVL 37

Expert Comment

by:TommySzalapski
ID: 34208873
Click "save as..." and choose ".xml file"
0
 
LVL 37

Expert Comment

by:TommySzalapski
ID: 34208898
Were you suggesting Spring as a possibility or listing it as a requirement? Your punctuation leaves it a bit ambiguous. Reading it again, I'm assuming it's a requirement, in which case my first post might not help much.
0
 
LVL 37

Expert Comment

by:TommySzalapski
ID: 34208938
Actually, saving as xml spreadsheet and then opening in Spring might be all you need.
0
 

Author Comment

by:Waponi
ID: 34209482

An existing xml file, (i.e. temp.xls  on the hard drive),
 needs to be opened by
an existing Spring/java application, (Thru some button action).

How would the ModelAndView be created to do this ?

0
 
LVL 37

Expert Comment

by:TommySzalapski
ID: 34209633
.xls files are not stored as XML. Some .xlsx files are; also you can save Excel files as XML (but the extension won't be xls)
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

Author Comment

by:Waponi
ID: 34210039
Sorry my mistake,
An existing Excel spreadsheet  file, (physically on the hard drive),
 needs to be opened by
an existing Spring/java application, (Thru some button action).

How would the ModelAndView be created to do this ?
0
 
LVL 20

Expert Comment

by:Sathish David Kumar N
ID: 34210940
You want open that file  in MS excel or Browser ?

In browser means ModeAndView will help otherwise ...



0
 
LVL 37

Expert Comment

by:TommySzalapski
ID: 34212587
He said "The goal is to return new ModelAndView("?", model) and have the excel spreadsheet rendered in a browser." in the original question. If you know Java and Spring, please take over.
0
 

Author Comment

by:Waponi
ID: 34213722
Thanks,
The requirement is to display an excel spreadsheet ,currently on the hard drive,  thru  an existing java/spring app.

I was looking for a way to display the excel file without reading the contents and building a jsp page. if possible using m+v 'AbstractExcelView'  to display in a browser popup ?

         Else

     The requirements were not specific on browser vs excel, So
What is the best way in Spring, to display the file as a MS Excel spreadsheet ?
    ( which  I would guess might be  the preferred rendering method anyway)
0
 

Accepted Solution

by:
Waponi earned 0 total points
ID: 34286871
Can be done as follows;
Where...................................
public ModelAndView redirectToSubmenu(
                  HttpServletRequest request,
                  HttpServletResponse response,
                  @RequestParam(required = false, value = "vfsubmitargument")
Case......................................
if (submitAct != null && submitAct.equals("productEditsForm.export")) {
                  int exportJobIndex = Integer.parseInt(formNumber);
                  //the job we want to export
                  JDBCJob exportJob = jdbcJobList.get(exportJobIndex - 1);
                  String outputFileName = exportJob.getJobId()+".xls";
                  outputPath = QM_TEMPDIR+outputFileName;
                  System.out.println("outputPath "+outputPath);

                  try {
                        ServletOutputStream out = response.getOutputStream();
                    response.setHeader("Content-Disposition", "attachment; filename=export.xls");
                         //request.getRequestDispatcher("C:\\cme\\export.xls").forward(request, response).
                        response.setContentType("application/vnd.ms-excel");
                        InputStream myxls;
                        myxls = new FileInputStream(outputPath);
                        HSSFWorkbook wb  = new HSSFWorkbook(myxls);
                        wb.write(out);
                        out.flush();
                    out.close();
                  } catch (FileNotFoundException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                  } catch (IOException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                  }
                  return null;
            }
0
 

Author Closing Comment

by:Waponi
ID: 34324433
can be done as above
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now