如何使用java将包含多个工作表的单个excel文档上载到多个表

如何使用java将包含多个工作表的单个excel文档上载到多个表,java,Java,我正在尝试上载包含多张工作表的excel文档 e、 g文件名:包含 第0页 第1页等 我有一个多数据库表,如表1、表2等 现在我正在尝试将表0映射到表1 使用java的表2和etc的表1 我已经在一张桌子上用一张纸了 e、 g代码: /** * */ private static final long serialVersionUID = 1L; public File file; private int totalRecords=0; private int successRecords

我正在尝试上载包含多张工作表的excel文档 e、 g文件名:包含 第0页 第1页等

我有一个多数据库表,如表1、表2等

现在我正在尝试将表0映射到表1 使用java的表2和etc的表1

我已经在一张桌子上用一张纸了

e、 g代码:

/**
 * 
 */
private static final long serialVersionUID = 1L;
public File file;
private int totalRecords=0;
private int successRecords=0;
private int failureRecords=0;

private String totalMsg="Total No. of records processed :";
private String successMsg="No. of records succeeded :";
private String failureMsg="No. of records failed:";



@SuppressWarnings("deprecation")
public OutputStream receiveUpload(String filename, String mimeType) {
    // Create upload stream
    FileOutputStream fos = null; // Output stream to write to
    try {
        // Open the file for writing.
        file = new File("" + filename);
        fos = new FileOutputStream(file);
    } catch (final java.io.FileNotFoundException e) {
        UI.getCurrent().showNotification(
                "Could not open file<br/>", e.getMessage(),
                Notification.TYPE_ERROR_MESSAGE);
        return null;
    }
    return fos; // Return the output stream to write to
}

public void uploadSucceeded(SucceededEvent event) {
    // Show the uploaded file in the image viewer

    try{

        Session session = com.systems.payrolladmin.PayrolladminMainUI.sf.openSession();
        session.beginTransaction();
        //File excel = new File(FILE_PATH);
        FileInputStream fis = new FileInputStream(file);
        @SuppressWarnings("resource")
        XSSFWorkbook book = new XSSFWorkbook(fis);
        XSSFSheet sheet = book.getSheetAt(0);
        Row row;

        ArrayList<Resignee> ErrorDataList2 = new ArrayList<Resignee>();

        int LastRowNum=sheet.getLastRowNum();
        for(int i=1; i<=LastRowNum; i++){
            row = sheet.getRow(i);

            String vempId1 = row.getCell(1).getStringCellValue(); 
            Date vdor1=row.getCell(3).getDateCellValue();
            Date vdorr=row.getCell(4).getDateCellValue();
            String vRemark = row.getCell(5).getStringCellValue();

            int a=5;
            int b=5;

            if(a==b)
            {

            Resignee resobj = new Resignee();
            resobj.setEmpId(vempId1);
            resobj.setDOR(vdor1);
            resobj.setDOReliv(vdorr);
            resobj.setRemarks(vRemark);
            session.save(resobj);

            resobj=null;
            successRecords++;

            }else{

                Resignee error = new Resignee();
                error.setEmpId(vempId1);
                error.setDOR(vdor1);
                error.setDOReliv(vdorr);
                error.setRemarks(vRemark);
            error.setRemarks(vRemark);

                ErrorDataList2.add(error);
                error=null;
                failureRecords++;
            }

            totalRecords++;

        }
        session.getTransaction().commit();
        session.close();
        fis.close();
        //write to excel

        @SuppressWarnings("resource")
        XSSFWorkbook workbook = new XSSFWorkbook(); 
        XSSFSheet spreadsheet = workbook.createSheet("employe db");
        XSSFRow xrow=spreadsheet.createRow(0);
        XSSFCell cell;

        cell=xrow.createCell(0);
        cell.setCellValue("EMPLOYEE ID");
        cell=xrow.createCell(1);

        cell.setCellValue("DOR");
        cell=xrow.createCell(2);
        cell.setCellValue("DORELIEVE");
        cell=xrow.createCell(3);
        cell.setCellValue("REMARKS");




        int i=1;
        for (Resignee nobj : ErrorDataList2) {

             xrow=spreadsheet.createRow(i);

             cell=xrow.createCell(0);
             cell.setCellValue(nobj.getEmpId());

             cell=xrow.createCell(1);
             cell.setCellValue(nobj.getDOR());
             cell=xrow.createCell(2);
             cell.setCellValue(nobj.getDOReliv());
             cell=xrow.createCell(3);
             cell.setCellValue(nobj.getRemarks());


             i++;

        }

        FileOutputStream out = new FileOutputStream(
        new File("F:\\Error Excel\\ResingeeError.xlsx"));
        workbook.write(out);
        out.close();
/**
* 
*/
私有静态最终长serialVersionUID=1L;
公共文件;
私有int totalRecords=0;
private int successRecords=0;
专用int故障记录=0;
私有字符串totalMsg=“处理的记录总数:”;
私有字符串successsg=“成功记录数:”;
私有字符串failureMsg=“失败的记录数:”;
@抑制警告(“弃用”)
public OutputStream receiveUpload(字符串文件名、字符串mimeType){
//创建上传流
FileOutputStream fos=null;//要写入的输出流
试一试{
//打开文件进行写入。
文件=新文件(“+”文件名);
fos=新文件输出流(文件);
}捕获(最终java.io.filenotfounde异常){
UI.getCurrent().showNotification(
无法打开文件
,例如getMessage(), 通知。键入错误消息); 返回null; } return fos;//返回要写入的输出流 } 公共无效上载成功(SucceedeEvent事件){ //在图像查看器中显示上载的文件 试一试{ Session Session=com.systems.payrolladmin.PayrolladminMainUI.sf.openSession(); session.beginTransaction(); //文件excel=新文件(文件路径); FileInputStream fis=新的FileInputStream(文件); @抑制警告(“资源”) XSSF工作簿=新XSSF工作簿(fis); XSSFSheet sheet=book.getSheetAt(0); 行行; ArrayList ErrorDataList2=新的ArrayList(); int LastRowNum=sheet.getLastRowNum();
对于(int i=1;i您的问题听起来像是您的代码在为一张工作表工作。如果是这样,那么获取第一张工作表的行

XSSFSheet sheet = book.getSheetAt(0);
可以更新以查看多张图纸,如使用中所示


要获取工作簿中的工作表数量,然后分别处理每个工作表,您已经在使用工作表0了吗?

这里的上下文是什么?XSSFWorkbook
类来自哪个包?您的代码被剪裁在底部,请将其减少到显示问题的最小示例。
book.getNumberOfSheets();