I'm making a code for the generation of an Excel file of jTable
, however at the time of executing it I mark this error and I do not know how to remove it
Exception in thread error "AWT-EventQueue-0" java.lang.NoClassDefFoundError: org / apache / commons / collections4 / ListValuedMap
Here is the code:
public class Admin extends javax.swing.JFrame {
//DefaultTableModel model;
/**
* Creates new form Admin
*/
DefaultTableModel model;
Conexion con=new Conexion();
Connection cn=con.conexion();
public Admin() {
initComponents();
setLocationRelativeTo(null);
this.setTitle("Funciones de Administrador");
this.getContentPane().setBackground(Color.white);
cargar("");
}
//Agregar los datos de la tabla
private String getCellValue(int x, int y){
return model.getValueAt(x, y).toString();
}
//Excel
private void writeToExcel(){
XSSFWorkbook wb=new XSSFWorkbook();
XSSFSheet ws=wb.createSheet();
//Carga el TReemap
TreeMap<String, Object[]> data=new TreeMap<>();
//Agregar los titulos
data.put("-1", new Object[]{model.getColumnName(0),model.getColumnName(1),model.getColumnName(2),model.getColumnName(3),model.getColumnName(4),model.getColumnName(5)});
//Agregar los datos que se necesitan
for(int i=0;i<model.getRowCount();i++){
data.put(Integer.toString(i), new Object[]{getCellValue(i, 0),getCellValue(i, 1),getCellValue(i, 2),getCellValue(i, 3),getCellValue(i, 4),getCellValue(i, 5)});
}
//Escribirlo en un Excel
Set<String> ids=data.keySet();
XSSFRow row;
int rowID=0;
for(String key: ids){
row=ws.createRow(rowID++);
Object[] values=data.get(key);
int cellID=0;
for(Object o: values){
Cell cell=row.createCell(cellID++);
cell.setCellValue(o.toString());
}
}
// Pasarlo a un archivo
try{
FileOutputStream fos=new FileOutputStream(new File("C:/Excel/trabajadores.xlsx"));
wb.write(fos);
fos.close();
}catch(FileNotFoundException ex){
Logger.getLogger(WorkbookNSheet.class.getName()).log(Level.SEVERE,null,ex);
}catch(IOException ex){
Logger.getLogger(ExcelGUI.class.getName()).log(Level.SEVERE,null,ex);
}
}
//Cargamos los datos a la tabla
void cargar(String valor){
String [] titulos= {"Nombre", "Apellido Paterno", "Apellido Materno", "Hora de Entrada", "Hora de Salida", "Fecha"};
String [] registros= new String[6];
String sql= "Select e.NOMBRE,e.APP,e.APM,h.ENTRADA,h.SALIDA,h.FECHA From historial h, empleado e WHERE e.ID_EMPLEADO = h.ID_EMPLEADO AND CONCAT(e.NOMBRE,' ',e.APP,' ',e.APM,' ',h.ENTRADA,' ',h.SALIDA,' ',h.FECHA,' ') LIKE '%"+valor+"%'";
model =new DefaultTableModel(null, titulos);
try {
Statement st = cn.createStatement();
ResultSet rs= st.executeQuery(sql);
while(rs.next()){
registros[0]=rs.getString("e.NOMBRE");
registros[1]=rs.getString("e.APP");
registros[2]=rs.getString("e.APM");
registros[3]=rs.getString("h.ENTRADA");
registros[4]=rs.getString("h.SALIDA");
registros[5]=rs.getString("h.FECHA");
model.addRow(registros);
}
TablaHistorial.setModel(model);
} catch (SQLException ex) {
JOptionPane.showMessageDialog(null, ex);
}
}
The code according to me is fine, but it keeps marking the error.
The imports that I have are the following:
import java.awt.Color;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Random;
import java.util.Set;
import java.util.TreeMap;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
And within the project in the library I have these files:
poi-3.17; poi-examples-3.17; poi-excelant-3.17; poi-ooxml-3.17;
poi-ooxml-schemas-3.17; poi-scratchpad-3.17; curvesapi-1.04;
xmlbeans-2.6.0;