Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package xls;
- import java.awt.BorderLayout;
- import java.awt.EventQueue;
- import java.io.FileInputStream;
- import java.io.FileNotFoundException;
- import java.io.FileOutputStream;
- import java.io.IOException;
- import java.io.OutputStream;
- import org.apache.poi.hssf.usermodel.HSSFWorkbook;
- import org.apache.poi.ss.usermodel.Cell;
- import org.apache.poi.ss.usermodel.DataFormatter;
- import org.apache.poi.ss.usermodel.DateUtil;
- import org.apache.poi.ss.usermodel.Row;
- import org.apache.poi.ss.usermodel.Sheet;
- import org.apache.poi.ss.usermodel.Workbook;
- import org.apache.poi.ss.util.CellReference;
- import org.apache.poi.ss.usermodel.*;
- import java.io.Serializable;
- import javax.swing.JFrame;
- import javax.swing.JPanel;
- import javax.swing.border.EmptyBorder;
- import javax.swing.JLabel;
- import javax.swing.JTextField;
- import javax.swing.JButton;
- import java.awt.event.ActionListener;
- import java.awt.event.ActionEvent;
- public class xls3 extends JFrame {
- private JPanel contentPane;
- private JTextField tf;
- private JTextField tf2;
- /**
- * Launch the application.
- * @throws IOException
- */
- public static void main(String[] args) throws IOException {
- FileInputStream fos = new FileInputStream("Myfile.xls");
- Workbook wb = new HSSFWorkbook(fos);
- DataFormatter formatter = new DataFormatter();
- Sheet sheet1 = wb.getSheetAt(0);
- EventQueue.invokeLater(new Runnable() {
- public void run() {
- try {
- xls3 frame = new xls3();
- frame.setVisible(true);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- });
- }
- /**
- * Create the frame.
- * @throws IOException
- */
- public xls3() throws IOException {
- FileInputStream fos = new FileInputStream("Myfile.xls");
- Workbook wb = new HSSFWorkbook(fos);
- DataFormatter formatter = new DataFormatter();
- Sheet sheet1 = wb.getSheetAt(0);
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- setBounds(100, 100, 541, 265);
- contentPane = new JPanel();
- contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
- setContentPane(contentPane);
- contentPane.setLayout(null);
- JLabel label = new JLabel("\u0412\u0432\u0435\u0434\u0438\u0442\u0435 \u043D\u0430\u0437\u0432\u0430\u043D\u0438\u0435");
- label.setBounds(42, 61, 129, 14);
- contentPane.add(label);
- tf = new JTextField();
- tf.setBounds(200, 58, 162, 20);
- contentPane.add(tf);
- tf.setColumns(10);
- JButton btnNewButton = new JButton("\u043F\u043E\u0438\u0441\u043A");
- btnNewButton.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent arg0) {
- String a = tf.getText().toString();
- String b = "";
- String c ="Не найдено";
- for (Row row : sheet1) {
- Cell cell = row.getCell(1);
- if (cell.getCellType() == Cell.CELL_TYPE_STRING) {
- b = cell.getStringCellValue().toString();
- }
- if (a.equals(b))
- {
- tf2.setText("Найдено");
- break;
- }
- else
- {
- tf2.setText("Не найдено");
- }
- }
- }
- }
- );
- btnNewButton.setBounds(417, 57, 89, 23);
- contentPane.add(btnNewButton);
- tf2 = new JTextField();
- tf2.setBounds(119, 141, 149, 20);
- contentPane.add(tf2);
- tf2.setColumns(10);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement