简体   繁体   English

从MS Access中的结果集中插入Excel文件数据

[英]Inserting to excel file data from result set in ms access

I have a method for checking the attendance of the employees. 我有一种检查员工出勤的方法。 The firstnames,lastnames, position of employees are retrieve from a database. 从数据库中检索员工的名字,姓氏,职位。 the daily attendance method works fine. 日常出勤方法效果很好。 now, I also have a method that creates a monthly attendance report from the daily attendance method. 现在,我还有一种方法可以根据每日出勤方法创建每月出勤报告。 it also retrieves the data in the database. 它还会检索数据库中的数据。 In querying, I used a pivot. 在查询中,我使用了枢轴。 It doesn't work. 没用 The error says that it has an error in the from clause. 该错误表明在from子句中有错误。 but when I test that query in ms access, It works perfectly. 但是,当我在ms access中测试该查询时,它可以完美运行。 Can everyone help me with this. 大家可以帮我吗? this is my code. 这是我的代码。

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];
           }
       });
    }

I've read from some resources that the result set can be inserted to a excel file. 我从一些资源中读取到可以将结果集插入到excel文件中。 Can anyone help me with this? 谁能帮我这个? I'm accessing the database through the connectToDB() method, I want to insert to the excel file the pivot query result. 我正在通过connectToDB()方法访问数据库,我想将数据透视查询结果插入到excel文件中。

You can use EasyXLS library to export the result set to the Excel file. 您可以使用EasyXLS库将结果集导出到Excel文件。 Check some source code sample here . 在此处检查一些源代码示例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM