Advertisement
Guest User

Untitled

a guest
Nov 20th, 2019
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.38 KB | None | 0 0
  1. package xls;
  2.  
  3. import java.awt.BorderLayout;
  4. import java.awt.EventQueue;
  5. import java.io.FileInputStream;
  6. import java.io.FileNotFoundException;
  7. import java.io.FileOutputStream;
  8. import java.io.IOException;
  9. import java.io.OutputStream;
  10.  
  11. import org.apache.poi.hssf.usermodel.HSSFWorkbook;
  12. import org.apache.poi.ss.usermodel.Cell;
  13. import org.apache.poi.ss.usermodel.DataFormatter;
  14. import org.apache.poi.ss.usermodel.DateUtil;
  15. import org.apache.poi.ss.usermodel.Row;
  16. import org.apache.poi.ss.usermodel.Sheet;
  17. import org.apache.poi.ss.usermodel.Workbook;
  18. import org.apache.poi.ss.util.CellReference;
  19. import org.apache.poi.ss.usermodel.*;
  20. import java.io.Serializable;
  21. import javax.swing.JFrame;
  22. import javax.swing.JPanel;
  23. import javax.swing.border.EmptyBorder;
  24. import javax.swing.JLabel;
  25. import javax.swing.JTextField;
  26. import javax.swing.JButton;
  27. import java.awt.event.ActionListener;
  28. import java.awt.event.ActionEvent;
  29.  
  30. public class xls3 extends JFrame {
  31.  
  32. private JPanel contentPane;
  33. private JTextField tf;
  34. private JTextField tf2;
  35.  
  36. /**
  37. * Launch the application.
  38. * @throws IOException
  39. */
  40. public static void main(String[] args) throws IOException {
  41. FileInputStream fos = new FileInputStream("Myfile.xls");
  42. Workbook wb = new HSSFWorkbook(fos);
  43. DataFormatter formatter = new DataFormatter();
  44. Sheet sheet1 = wb.getSheetAt(0);
  45. EventQueue.invokeLater(new Runnable() {
  46. public void run() {
  47. try {
  48. xls3 frame = new xls3();
  49. frame.setVisible(true);
  50. } catch (Exception e) {
  51. e.printStackTrace();
  52. }
  53. }
  54. });
  55. }
  56.  
  57. /**
  58. * Create the frame.
  59. * @throws IOException
  60. */
  61. public xls3() throws IOException {
  62. FileInputStream fos = new FileInputStream("Myfile.xls");
  63.  
  64. Workbook wb = new HSSFWorkbook(fos);
  65.  
  66. DataFormatter formatter = new DataFormatter();
  67. Sheet sheet1 = wb.getSheetAt(0);
  68. setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  69. setBounds(100, 100, 541, 265);
  70. contentPane = new JPanel();
  71. contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
  72. setContentPane(contentPane);
  73. contentPane.setLayout(null);
  74.  
  75. JLabel label = new JLabel("\u0412\u0432\u0435\u0434\u0438\u0442\u0435 \u043D\u0430\u0437\u0432\u0430\u043D\u0438\u0435");
  76. label.setBounds(42, 61, 129, 14);
  77. contentPane.add(label);
  78.  
  79. tf = new JTextField();
  80. tf.setBounds(200, 58, 162, 20);
  81. contentPane.add(tf);
  82. tf.setColumns(10);
  83.  
  84. JButton btnNewButton = new JButton("\u043F\u043E\u0438\u0441\u043A");
  85. btnNewButton.addActionListener(new ActionListener() {
  86. public void actionPerformed(ActionEvent arg0) {
  87.  
  88. String a = tf.getText().toString();
  89. String b = "";
  90. String c ="Не найдено";
  91. for (Row row : sheet1) {
  92. Cell cell = row.getCell(1);
  93.  
  94. if (cell.getCellType() == Cell.CELL_TYPE_STRING) {
  95. b = cell.getStringCellValue().toString();
  96. }
  97. if (a.equals(b))
  98. {
  99. tf2.setText("Найдено");
  100.  
  101. break;
  102. }
  103. else
  104. {
  105. tf2.setText("Не найдено");
  106. }
  107.  
  108.  
  109. }
  110.  
  111. }
  112. }
  113. );
  114. btnNewButton.setBounds(417, 57, 89, 23);
  115. contentPane.add(btnNewButton);
  116.  
  117. tf2 = new JTextField();
  118. tf2.setBounds(119, 141, 149, 20);
  119. contentPane.add(tf2);
  120. tf2.setColumns(10);
  121. }
  122. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement