Here, I use something called Java Excel API, similar to Jakarta Poi, but I feel that it is too complicated. Moreover, JXL is quite good for Chinese support, at least in the process of using it, there is no problem.
First, download address http://www.andykhan.com/jexcelapi/
Second, the feature can read the Excel 95, 97, 2000 files to read or write Excel 97 and its subsequent version of the formula (but I find it seems to have bugs to generate the spread of Excel 97 format support font, numbers, and date format support Cell color and shadow can edit existing files
Third, read the file // declare, remember to turn it off later. . Workbook workbook = NULL;
Try {workbook = workbook.getworkbook (new file ("D: //temp/testRead.xls"));} catch (exception e) {throw new exception ("File to Import Not Found!");
Sheet Sheet = Workbook.getsheet (0); Cell Cell = NULL;
INT columncount = 3; int Rowcount = Sheet.Getrows (); for (int i = 0; i Write: Wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww WWW Wwwwwwwwwwwwwwwwwwwwwwwwwwwwww Write the content to the Excel file in Java 4. Export data to the following example in the Excel file, set the number, date format, and font, color, etc. File tempfile = new file ("d: /temp/output.xls"); Writableworkbook workbook = workbook.createworkbook (tempfile); Writablesheet Sheet = Workbook.createsheet ("TestcreateExcel", 0); // Some temporary variables are used to write Label L = NULL in Excel; jxl.write.Number n = null; jxl.write.datetime d = null; // Some fonts and formats, the same Excel Do not have too many good format WritableFont headerFont = new WritableFont (WritableFont.ARIAL, 12, WritableFont.BOLD, false, Underlinestyle.NO_UNDERLINE, jxl.format.Colour.BLUE); WritableCellformat headerformat = new WritableCellformat (headerFont); WritableFont titleFont = new WritableFont (WritableFont.ARIAL, 10, WritableFont.NO_BOLD, false, Underlinestyle.NO_UNDERLINE, jxl.format.Colour.RED); WritableCellformat titleformat = new WritableCellformat (titleFont); WritableFont detFont = new WritableFont (WritableFont.ARIAL, 10, WritableFont.NO_BOLD, false, Underlinestyle.NO_UNDERLINE, jxl.format.Colour.BLACK); WritableCellformat detformat = new WritableCellformat (detFont); Numberformat NF = New NumberFormat ("0.00000"); // WritablecellFormat PriceFormat = New WritableCellFormat (Detfont, NF); DETFONT, NF); DateFormat DF = New DateFormat ("YYYY-MM-DD"); // WritablecellFormat DateFormat = New WritableCellFormat (Detfont, DF) for the date; // The remaining thing is to create some cells with the content and format above, and then add L = New label (0, 0, "for testing Excel file", headerformat; Sheet.Addcell (L ); // add titleint column = 0; l = new label (Column , 2, "Title", titleFormat); Sheet.Addcell (L); L = New Label (Column , 2, "Date", titleFormat; Sheet.Addcell (l); L = New Label (Column , 2, "Currency", TitleFormat; Sheet.Addcell (L); L = New Label (Column , 2, "Price", TitleFormat); Sheet.Addcell (L); // add detailint i = 0; column = 0; l = new label (Column , i 3, "title" i, detformat; sheet.addcell (L); D = new datetime (Column , i 3, New java.util.date (), dateformat; sheet.addcell (d); l = new label (Column , i 3, "CNY", DETFORMAT); Sheet.Addcell (L); n = new jxl.write .Number (Column , I 3, 5.678, PriceFormat); Sheet.Addcell (n); i ; column = 0; L = New Label (Column , i 3, "Title" i, Detformat; Sheet.Addcell (l); D = new datetime (column , i 3, new java.util.date (), dateformat); Sheet.Addcell (D); L = New Label (Column , i 3, "SGD", Detformat ); Sheet.Addcell (L); N = new jxl.write.Number (Column , i 3, 98832, PriceFormat); Sheet.Addcell (n); // Set the width of the column Column = 0; Sheet.SetColumnView (Column , 20); Sheet.SetColumnView (Column , 20); Sheet.SetColumnView (Column , 10); Sheet.SetColumnView (Column , 20); Workbook.write (); workbook.close ();