Solved

Export Excel file thru Spring MVC

Posted on 2010-11-24
11
3,625 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
Comment Utility
Click "save as..." and choose ".xml file"
0
 
LVL 37

Expert Comment

by:TommySzalapski
Comment Utility
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
Comment Utility
Actually, saving as xml spreadsheet and then opening in Spring might be all you need.
0
 

Author Comment

by:Waponi
Comment Utility

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
Comment Utility
.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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 

Author Comment

by:Waponi
Comment Utility
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
Comment Utility
You want open that file  in MS excel or Browser ?

In browser means ModeAndView will help otherwise ...



0
 
LVL 37

Expert Comment

by:TommySzalapski
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
can be done as above
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Introduction This Article is a follow-up to my Mappit! Addin Article (http://www.experts-exchange.com/A_2613.html), it was inspired by an email posting I made to EUSPRIG (http://www.eusprig.org/index.htm), I will briefly cover: 1) An overvie…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.

771 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