【问题标题】:Inserting to excel file data from result set in ms access在 ms 访问中从结果集中插入到 excel 文件数据
【发布时间】:2014-05-09 13:20:55
【问题描述】:

我有一种检查员工出勤情况的方法。从数据库中检索员工的名字、姓氏、职位。每日考勤方法效果很好。现在,我还有一种方法可以从每日考勤方法创建每月考勤报告。它还检索数据库中的数据。在查询中,我使用了一个枢轴。它不起作用。该错误表示它在 from 子句中有错误。但是当我在 ms 访问中测试该查询时,它工作得很好。每个人都可以帮我解决这个问题。这是我的代码。

private void attendanceView() throws ClassNotFoundException{
        String query ="TRANSFORM COUNT(attendance.present)SELECT employees.ID,employees.firstName,employees.lastName,employees.position,employees.rate FROM employees LEFT JOIN attendance ON employees.ID = attendance.empID GROUP BY employees.ID,employees.firstName,employees.lastName,employees.position,employees.rate PIVOT attendance.dateAttended";
       Object[][] result = connectToDB(query);
       monthlyAttendanceTable.setModel(new javax.swing.table.DefaultTableModel(
               result, new String [] {"Employee ID","First Name","Last Name", "Position", "Rate","",""}
       )
       {
           Class[] types = new Class [] {
               java.lang.Integer.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.Integer.class, java.lang.Integer.class, java.lang.Integer.class, java.lang.Integer.class,java.lang.Integer.class,java.lang.Integer.class,java.lang.String.class
           };
           boolean[] canEdit = new boolean [] {
               false, false, false, false, false, false, false, false, false,false
           };

           public Class getColumnClass(int columnIndex) {
               return types [columnIndex];
           }

           public boolean isCellEditable(int rowIndex, int columnIndex) {

               return canEdit [columnIndex];
           }
       });
    }

我从一些资源中了解到可以将结果集插入到 excel 文件中。谁能帮我这个?我通过 connectToDB() 方法访问数据库,我想将数据透视查询结果插入到 excel 文件中。

【问题讨论】:

标签: java excel ms-access pivot export-to-excel


【解决方案1】:

您可以使用EasyXLS 库将结果集导出到 Excel 文件。检查一些源代码示例here

【讨论】:

    猜你喜欢
    • 2013-12-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-06
    • 1970-01-01
    • 2016-11-03
    • 2010-10-18
    • 1970-01-01
    相关资源
    最近更新 更多