[Original] Filter the specific string in the Excel table

xiaoxiao2021-03-06  41

Recently, the statistics are always statistically reported. These data is from many branches from the country. I have also asked them to write strings according to a specific format. For me, the results, although each record contains The keyword I want, is the only product number, but the location of this keyword is very casual, and a record may contain multiple keywords, which makes it difficult to extract them, one-stop Copy, exhausted me what. Previously used Apache's POI project, where HSSF can solve such problems, then use some of String's function, which is very simple. Eclipse is much used, which is mainly mainly Swing, and SWT is also familiar. The problem encountered when doing this applet is as follows:

1. Eclipse has Chinese in Chinese garbled code, there is no problem when writing, but today I will see a part of the Chinese becomes a small solid square, put them back PASTE to NOTEPAD, it is normal display, it seems to be Set up the java font of Eclipse: Windows-> Preference

Change the original Courier New to the Song's or the Song Song, although the problem solved, but the individual felt that there was no original look, the font is too square, or want to use the original font, what should I do? Enter the official download page of the Eclipse, go to a higher version of 3.1m4 page, download the 3.1m4 version of SWT

Then decompress the original file and restart Eclipse.

2. HSSF Chinese support in obtaining a Cell: POIFSFileSystem fs = new POIFSFileSystem (new FileInputStream ( "workbook.xls")); HSSFWorkbook wb = new HSSFWorkbook (fs); HSSFSheet sheet = wb.getSheetAt (0); HSSFRow row = Sheet.Gtrow (2); hssfcell cell = row.getcell (short) 3); write String with Chinese to this Cell, HSSF does not support Chinese, for example: Cell.setcellValue ("Hello) ;

At this time, if you open Workbook.xls will find Chinese is a number, that is, the high-level Chinese characters are cut. So add cell.setencoding (hssfcell.encoding_utf_16) before the previous sentence;

3. The representation of the path in Java is described in the J2SE API, and Windows is ////, which is the path of the Excel file, such as "c: /aa/workbook.xls", which is written in Java. "C: //aaa/Workbook.xls" (if it is a network path, "// home / tmp / workbook.xls" should be written as "home // tmp // workbook.xls"), I used to use this question. JBuilder writes in the generation PDF program already known, but this time I use the FileDialog provided by SWT to pop up a dialog box, then select Excel to be read, save the path with the variable Path, as follows: FileDialog fdlg = New FileDialog (sshell, SWT .Open; fdlg.settext ("Select Excel Document"); path = fdlg.open (); system.out.println (path); When running the program, select the file in the dialog box, the system prints the PATH For "c: /aa/workbook.xls", I feel weird, the system should be expressed as //. Then I saw the value of the PATH variable in Debug Perspective, I saw C: //aaa //workbook.xls, but no matter how it appeared. The program reads the data from Excel. After extracting the field, write the field to another column in Excel, the statement is as follows: fileoutputstream fout = null; try {3 fout = new fileoutputStream (path); // Exception, system Can't find a file. Wb.write (fout); fout.close ();} catch (ioException ex2) {ex2.printstacktrace ();} then I will change the third line to "fout = new fileoutputstream (" c: // aaa // workbook .xls "); you can find the file to write. Look as follows, this is the contradiction problem of my PATH variable in Debug Perspective:

转载请注明原文地址:https://www.9cbs.com/read-68916.html

New Post(0)