Exporting data to excel file using spring mvc
<p>I am begginer java developer and I use spring mvc framework I want to export data from jsp page (that was sent from controler) I work according to this tutorial 
<a href="http://www.codejava.net/frameworks/spring/spring-mvc-with-excel-view-example-apache-poi-and-jexcelapi" rel="nofollow">http://www.codejava.net/frameworks/spring/spring-mvc-with-excel-view-example-apache-poi-and-jexcelapi</a></p>

<p>but i get this error:</p>

<p><code>HTTP Status 500 - Request processing failed; nested exception is</code>     <code>org.springframework.beans.factory.BeanCreationException: Error creating bean</code> <code>with name 'excelView': Instantiation of bean failed; nested exception is</code> <code>java.lang.NoClassDefFoundError: org/apache/poi/ss/usermodel/Font</code></p>

<p>when i want to use the "excel lib" poi-3.9.jar and put it as dependency in pom.xml</p>

<p>When i do "maven install" i got this error:</p>

<p><code>Failed to execute goal on project SpringMvcJdbcTemplate: Could not resolve</code> <code>dependencies for project net.codejava.spring:SpringMvcJdbcTemplate:war:1.0:</code> <code>Failed to collect dependencies at org.apache.poi:poi:jar:3.9: Failed to read</code> <code>artifact descriptor for org.apache.poi:poi:jar:3.9: Could not transfer artifact</code> </p>

<pre><code>org.apache.poi:poi:pom:3.9 from/to central 
(https://repo.maven.apache.org/maven2): 
sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target -&gt; [Help 1]
</code></pre>

<p>so i add the library in regular way and its seems good but when i run the app i got the error i put in the begining</p>

<p>This is my code:</p>

<p>controler:</p>

<pre><code>@RequestMapping(value = "/downloadExcel", method = RequestMethod.GET)
public ModelAndView downloadExcel() {
    // create some sample data
   // return a view which will be resolved by an excel view resolver
    return new ModelAndView("excelView", "listContactings", listContact);
}
</code></pre>

<p>MvcConfigiration:</p>

<pre><code>@Bean
    public ViewResolver getViewResolver(){
        ResourceBundleViewResolver resolver = new ResourceBundleViewResolver();
        resolver.setOrder(1);
        resolver.setBasename("views");
        return resolver;
    }
    @Bean
    public ViewResolver getViewResolver2(){
        InternalResourceViewResolver resolver = new InternalResourceViewResolver();
        resolver.setOrder(2);
        resolver.setPrefix("/WEB-INF/views/");
        resolver.setSuffix(".jsp");
        return resolver;
    }
</code></pre>

<p>views.proprties:</p>

<pre><code>excelView.(class)=net.codejava.spring.ExcelBuilder
</code></pre>

<p>ExcelBuilder.java:</p>

<pre><code>package net.codejava.spring;

import java.util.Date;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.poi.hssf.usermodel.HSSFFont;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.util.HSSFColor;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.Font;
import org.springframework.web.servlet.view.document.AbstractExcelView;

import net.codejava.spring.model.Contacting;

public class ExcelBuilder extends AbstractExcelView {

    @Override
    protected void buildExcelDocument(Map&lt;String, Object&gt; model,
            HSSFWorkbook workbook, HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        // get data model which is passed by the Spring container
        List&lt;Contacting&gt; listContactings = (List&lt;Contacting&gt;) model.get("listContactings");

        // create a new Excel sheet
        HSSFSheet sheet = workbook.createSheet("Java Books");
        sheet.setDefaultColumnWidth(30);

        // create style for header cells
        CellStyle style = workbook.createCellStyle();
        Font font = workbook.createFont();
        font.setFontName("Arial");
        style.setFillForegroundColor(HSSFColor.BLUE.index);
        style.setFillPattern(CellStyle.SOLID_FOREGROUND);
       font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
        font.setColor(HSSFColor.WHITE.index);
        style.setFont(font);

        // create header row

        HSSFRow header = sheet.createRow(0);

        header.createCell(0).setCellValue("contacting_id");
        header.getCell(0).setCellStyle(style);

        header.createCell(1).setCellValue("user_id");
        header.getCell(1).setCellStyle(style);

        header.createCell(2).setCellValue("subject");
        header.getCell(2).setCellStyle(style);

        header.createCell(3).setCellValue("location");
        header.getCell(3).setCellStyle(style);

        header.createCell(4).setCellValue("content");
        header.getCell(4).setCellStyle(style);

        header.createCell(5).setCellValue("department");
        header.getCell(5).setCellStyle(style);



        header.createCell(6).setCellValue("status");
        header.getCell(6).setCellStyle(style);




        header.createCell(7).setCellValue("contacting_date");
        header.getCell(7).setCellStyle(style);


        header.createCell(8).setCellValue("house_Number");
        header.getCell(8).setCellStyle(style);

        header.createCell(9).setCellValue("Urgency");
        header.getCell(9).setCellStyle(style);

        header.createCell(10).setCellValue("is_inspector");
        header.getCell(10).setCellStyle(style);

        header.createCell(11).setCellValue("inspectorStatus");
        header.getCell(11).setCellStyle(style);



        header.createCell(12).setCellValue("stringDate");
        header.getCell(12).setCellStyle(style);

        header.createCell(13).setCellValue("openedBy");
        header.getCell(13).setCellStyle(style);

        // create data rows
        int rowCount = 1;

        for (Contacting Contacting : listContactings) {
            HSSFRow aRow = sheet.createRow(rowCount++);
            aRow.createCell(0).setCellValue(Contacting.getContacting_id());
            aRow.createCell(1).setCellValue(Contacting.getUser_id());
            aRow.createCell(2).setCellValue(Contacting.getSubject());
            aRow.createCell(3).setCellValue(Contacting.getLocation());
            aRow.createCell(4).setCellValue(Contacting.getContent());
            aRow.createCell(5).setCellValue(Contacting.getdepartment());
            aRow.createCell(6).setCellValue(Contacting.getStatus());
            aRow.createCell(7).setCellValue(Contacting.getContacting_date());
            aRow.createCell(8).setCellValue(Contacting.getHouse_Number());
            aRow.createCell(9).setCellValue(Contacting.getUrgency());
            aRow.createCell(10).setCellValue(Contacting.getIs_inspector());
            aRow.createCell(11).setCellValue(Contacting.getInspectorStatus());
            aRow.createCell(12).setCellValue(Contacting.getStringDate());
            aRow.createCell(13).setCellValue(Contacting.getOpenedBy());



        }
    }
}
</code></pre>

<p>I think that the problem in the library using but i try many versions and many ways to use it but i always get errors.</p>

<p>someone can help me?</p>