我得到了一个ArrayList,它保存有关Fname,Sname和地址等员工的信息。我正在使用Apache Poi将此写入Excel工作簿。

在Excel表中,我希望一个员工上的所有信息都在同一行中。我设法在第1行和单元格0中编写名字(第0行保存标题)。一切都处于垂直良好的秩序。当尝试添加姓氏时,一切都开始在这里和那里跳跃。

如何在正确的地方写入姓氏?

这是我的Excel代码的一部分

private void writeEmployeeInfo() {

    ListIterator<Employee> employeeListIterator = Employee
            .getEmployeeList().listIterator();

    int rowIndex = 1;
    int cellIndex = 0;


    while (employeeListIterator.hasNext()) {

        Employee employee = employeeListIterator.next();

        Row row = sheet.createRow(rowIndex++);

        Cell cell = row.createCell(cellIndex);

        cell.setCellValue(employee.getfName());
.

//尝试在右侧单元格中添加员工的姓氏。

            while(employeeListIterator.hasNext()){
            Employee emp = employeeListIterator.next();
            row = sheet.createRow(rowIndex++);
            cell = row.createCell(cellIndex++);
            cell.setCellValue(emp.getsName());
        }
    }
}
.

这是我的第一篇文章,所以如果我写的或做了我糟糕的方式,请告诉我该怎么做,让你们可以容易地了解我的问题。

这里是项目的链接,如果您需要查看更多代码: http://1drv.ms/1ksgfdm

有帮助吗?

解决方案

您没有发布您如何添加另一个单元格。尝试这样的东西:

private void writeEmployeeInfo() {

    ListIterator<Employee> employeeListIterator = Employee
            .getEmployeeList().listIterator();

    int rowIndex = 1;

    while (employeeListIterator.hasNext()) {

        Employee employee = employeeListIterator.next();

        Row row = sheet.createRow(rowIndex++);

        row.createCell(0).setCellValue(employee.getfName());
        row.createCell(1).setCellValue(employee.getSName());
        row.createCell(2).setCellValue(employee.getAddress);
    }
}
.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top