Ich lade die Excel-Datei hoch und lese die Datei entsprechend dem Format ein, aber das Problem ist, dass die Datei nicht gelesen wird. Ich bekomme eine Ausnahme. Ich füge alle benötigten JAR-Dateien hinzu (dom4j-1.6.1,poi-3.9-20121203,poi-ooxml-3.9-20121203,poi-ooxml-schemas-3.9-20121203,xmlbeans-2.3.0). Bitte sagen Sie mir, was ich falsch mache. Die Ausnahme lautet unten.
public class Csv_Upload extends JFrame implements ActionListener
{
public static JFrame f;
JPanel panel;
JButton b1,b2,b3,b4;
JTextField txt1;
JLabel l1;
Font g,g1;
JFileChooser fc;
JTextArea log;
File file1 ;
String str;
DBConnection connect=new DBConnection();
static private final String newline = "\n";
public Csv_Upload()
{
panel=(JPanel)getContentPane();
panel.setLayout(null);
g=new Font("Georgia",Font.BOLD,22);
g1=new Font("Georgia",Font.BOLD,15);
panel.setBackground(new java.awt.Color(204, 230 , 255));
l1=new JLabel("Excel-Datei hochladen");
l1.setBounds(200, 50, 400, 30);
l1.setFont(g);
l1.setForeground(Color.RED);
panel.add(l1);
txt1=new JTextField();
txt1.setBounds(480, 150, 200, 40);
panel.add(txt1);
fc = new JFileChooser();
b1=new JButton("Datei durchsuchen");
b1.setBounds(50, 150, 200, 40);
b1.setFont(g1);
b1.setForeground(Color.RED);
panel.add(b1);
b2=new JButton("Datei hochladen");
b2.setBounds(260, 150, 200, 40);
b2.setForeground(Color.RED);
b2.setFont(g1);
panel.add(b2);
ImageIcon img=new ImageIcon("calender.png");
b3=new JButton(img);
b3.setBounds(50, 230, 50, 30);
b3.setForeground(Color.RED);
b3.setFont(g1);
panel.add(b3);
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
// b4.addActionListener(this);
}
@Override
public void actionPerformed(ActionEvent e)
{
if (e.getSource() == b1) {
int returnVal = fc.showOpenDialog(Csv_Upload.this);
if (returnVal == JFileChooser.APPROVE_OPTION) {
file1 = fc.getSelectedFile();
str=String.valueOf(file1);
System.out.println("Dateipfad"+file1);
}
//Handle save button action.
}
if(e.getSource()==b2)
{
try
{
FileInputStream file = new FileInputStream(new File(str));
System.out.println("Aktion in Datei durchgeführt"+file);
XSSFWorkbook workbook = new XSSFWorkbook(file);
XSSFSheet sheet = workbook.getSheetAt(0);
Iterator rowIterator = sheet.iterator();
while (rowIterator.hasNext())
{
Row row = rowIterator.next();
//Für jede Zeile alle Spalten durchgehen
Iterator cellIterator = row.cellIterator();
while (cellIterator.hasNext())
{
Cell cell = cellIterator.next();
switch (cell.getCellType())
{
case Cell.CELL_TYPE_NUMERIC:
System.out.print(cell.getNumericCellValue() + "\t");
break;
case Cell.CELL_TYPE_STRING:
System.out.print(cell.getStringCellValue() + "\t");
break;
}
}
System.out.println("");
}
file.close();
}
catch (Exception e1)
{
e1.printStackTrace();
}
}
if(e.getSource().equals(b3))
{
txt1.setText(new DatePicker(f).setPickedDate());
}
}
public static void main(String []s)
{
f=new Csv_Upload();
f.setVisible(true);
f.setSize(750,500);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
Stack-Trace:
Ausnahme im Thread "AWT-EventQueue-0" java.lang.NoSuchMethodError:
org.apache.poi.xssf.usermodel.XSSFWorkbook.(Ljava/io/InputStream;)V
bei ADD.Csv_Upload.actionPerformed(Csv_Upload.java:129)
bei javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
bei javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
bei javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
bei javax.swing.DefaultButtonModel.setPressed(Unknown Source)
bei javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
bei java.awt.Component.processMouseEvent(Unknown Source)
bei javax.swing.JComponent.processMouseEvent(Unknown Source)
bei java.awt.Component.processEvent(Unknown Source)
bei java.awt.Container.processEvent(Unknown Source)
bei java.awt.Component.dispatchEventImpl(Unknown Source)
bei java.awt.Container.dispatchEventImpl(Unknown Source)
bei java.awt.Component.dispatchEvent(Unknown Source)
bei java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
bei java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
bei java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
bei java.awt.Container.dispatchEventImpl(Unknown Source)
bei java.awt.Window.dispatchEventImpl(Unknown Source)
bei java.awt.Component.dispatchEvent(Unknown Source)
bei java.awt.EventQueue.dispatchEventImpl(Unknown Source)
bei java.awt.EventQueue.access$200(Unknown Source)
bei java.awt.EventQueue$3.run(Unknown Source)
bei java.awt.EventQueue$3.run(Unknown Source)
bei java.security.AccessController.doPrivileged(Native Method)
bei java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
bei java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
bei java.awt.EventQueue$4.run(Unknown Source)
bei java.awt.EventQueue$4.run(Unknown Source)
bei java.security.AccessController.doPrivileged(Native Method)
bei java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
bei java.awt.EventQueue.dispatchEvent(Unknown Source)
bei java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
bei java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
bei java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
bei java.awt.EventDispatchThread.pumpEvents(Unknown Source)
bei java.awt.EventDispatchThread.pumpEvents(Unknown Source)
bei java.awt.EventDispatchThread.run(Unknown Source)