?
Solved

Export Excel file thru Spring MVC

Posted on 2010-11-24
11
Medium Priority
?
3,829 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

PowerShell Core for Advanced Linux Administrators

Understand advanced principals around Powershell Core with a focus on the Linux Administrator.  This course covers how to administer numerous environments across multiple platforms including Linux, Azure, AWS, and Google Cloud from a single shell instance.

Question has a verified solution.

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

When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
This article describes a serious pitfall that can happen when deleting shapes using VBA.
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

800 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