martes, 16 de abril de 2024

Buscar por Codigo de Barras en Excel con Java Netbeans

 

import java.io.File;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
import jxl.Sheet;
import jxl.Workbook;
public class frmBBC extends javax.swing.JFrame {
    DefaultTableModel modelo = new DefaultTableModel();
    public frmBBC() {
        initComponents();
        String titu[]={"Bar Code","Nombre","Precio"};
        modelo.setColumnIdentifiers(titu);
        tblPro.setModel(modelo);
    }
private void txtBuscarActionPerformed(java.awt.event.ActionEvent evt) {                                 String cad="";
        int op = 0;
        try{
            File f = new File("C:\\Users\\miky mouse\\OneDrive\\ejemplo7.xls");
            Workbook wb = Workbook.getWorkbook(f);
            Sheet[] hojas = wb.getSheets();
            String[] datos = new String[3];
            if (hojas != null)
            {  int filas = hojas[1].getRows();
                    for (int fila = 1; fila < filas; fila++)
                    {   cad = hojas[1].getCell(0, fila).getContents();
                        if (cad.contains(txtBuscar.getText())) 
                        {
                            datos[0] = hojas[1].getCell(0, fila).getContents();
                            datos[1] = hojas[1].getCell(1, fila).getContents();
                            datos[2] = hojas[1].getCell(2, fila).getContents();
                            modelo.addRow(datos);
                            op = 1;
                         }
                    }
             }
            if (op==0) { JOptionPane.showMessageDialog(null, "No tenemos el producto "+txtBuscar.getText()); }
            txtBuscar.setText(null);
            wb.close();
        }catch(Exception e){
            JOptionPane.showMessageDialog(null, e.toString());
        }    
    }   
 
minuvasoft10@gmail.com - Miguel Nunez


  


No hay comentarios:

Publicar un comentario

Hallar las raices de Cualquier Ecuacion con Excel 365

  Se establece un intervalo de x de -20 a 20 para hallar los f(x) que cambian de signo, X aumenta en 1.   Se halla el cambio de signo de f(x...