Solved

Export Excel file thru Spring MVC

Posted on 2010-11-24
11
3,682 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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 

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
 

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.

813 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

14 Experts available now in Live!

Get 1:1 Help Now