如何在不使用Maven的情况下导出java servlet中的excel表?

时间:2018-04-23 16:12:33

标签: java excel maven export

实际上我试图在excel表中导出数据,我有以下代码 -

//Blank workbook
XSSFWorkbook workbook = new XSSFWorkbook();
//Create a blank sheet
XSSFSheet sheet = workbook.createSheet("User Data");
User user = new User();
ArrayList objcets = (ArrayList) user.fetchAll(request);
// first row for header
int rowNum = 1;
Row row = sheet.createRow(rowNum++);
int cellNum = 0;

// dynamic header sumbitted from form
if(request.getParameter("id")!=null && !request.getParameter("id").isEmpty())
{
    cellNum++;
    Cell cell = row.createCell(cellNum++);
    cell.setCellValue("Id");
}
if(request.getParameter("fullName")!=null && !request.getParameter("fullName").isEmpty())
{
    cellNum++;
    Cell cell = row.createCell(cellNum++);
    cell.setCellValue("Full Name");
}
if(request.getParameter("userName")!=null && !request.getParameter("userName").isEmpty())
{
    cellNum++;
    Cell cell = row.createCell(cellNum++);
    cell.setCellValue("User Name");
}
if(request.getParameter("department")!=null && !request.getParameter("department").isEmpty())
{
    cellNum++;
    Cell cell = row.createCell(cellNum++);
    cell.setCellValue("Department");
}
if(request.getParameter("email")!=null && !request.getParameter("email").isEmpty())
{
    cellNum++;
    Cell cell = row.createCell(cellNum++);
    cell.setCellValue("Email");
}
UserEntity userObj;
for(int i=0; i<objcets.size();i++)
{
    userObj = (UserEntity) objcets.get(i);
    rowNum++;
    row = sheet.createRow(rowNum++);
    cellNum = 0;

    if(request.getParameter("id")!=null && !request.getParameter("id").isEmpty())
    {
        cellNum++;
        Cell cell = row.createCell(cellNum++);
        cell.setCellValue(userObj.getId());
    }
    if(request.getParameter("fullName")!=null && !request.getParameter("fullName").isEmpty())
    {
        cellNum++;
        Cell cell = row.createCell(cellNum++);
        cell.setCellValue(userObj.getFullName());
    }
    if(request.getParameter("userName")!=null && !request.getParameter("userName").isEmpty())
    {
        cellNum++;
        Cell cell = row.createCell(cellNum++);
        cell.setCellValue(userObj.getUserName());
    }
    if(request.getParameter("department")!=null && !request.getParameter("department").isEmpty())
    {
        cellNum++;
        Cell cell = row.createCell(cellNum++);
        cell.setCellValue(userObj.getDepartment());
    }
    if(request.getParameter("email")!=null && !request.getParameter("email").isEmpty())
    {
        cellNum++;
        Cell cell = row.createCell(cellNum++);
        cell.setCellValue(userObj.getEmail());
    }
  

但这会产生XSSFWorkbook未找到的类错误   可行的我必须使用Maven并在pom.xml中注入依赖

我为Jxls学习,这也需要POI和Meaven,我不想使用Maven。我的问题是,无论如何在不使用Maven的情况下导出excel表。

我找不到关于我的问题excel sheet without Maven的任何博客。

0 个答案:

没有答案