Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Export Excel file thru Spring MVC

Posted on 2010-11-24
11
Medium Priority
?
3,878 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

618 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