ÀûÓÃJAVA²Ù×÷EXCELÎļþ
2003 Äê 1 ÔÂ 11 ÈÕ
ʹÓÃWindows²Ù×÷ϵͳµÄÅóÓѶÔExcel£¨µç×Ó±í¸ñ£©Ò»¶¨²»»áÄ°Éú£¬µ«ÊÇҪʹÓÃJavaÓïÑÔÀ´²Ù×ÝExcelÎļþ²¢²»ÊÇÒ»¼þÈÝÒ×µÄÊ¡£ÔÚWebÓ¦ÓÃÈÕÒæÊ¢ÐеĽñÌ죬ͨ¹ýWebÀ´²Ù×÷ExcelÎļþµÄÐèÇóÔ½À´Ô½Ç¿ÁÒ£¬Ä¿Ç°½ÏΪÁ÷ÐеIJÙ×÷ÊÇÔÚJSP»òServlet Öд´½¨Ò»¸öCSV £¨comma separated values£©Îļþ£¬²¢½«Õâ¸öÎļþÒÔMIME£¬text/csvÀàÐÍ·µ»Ø¸øä¯ÀÀÆ÷£¬½Ó×Åä¯ÀÀÆ÷µ÷ÓÃExcel²¢ÇÒÏÔʾCSVÎļþ¡£ÕâÑùÖ»ÊÇ˵¿ÉÒÔ·ÃÎʵ½ExcelÎļþ£¬µ«ÊÇ»¹²»ÄÜÕæÕýµÄ²Ù×ÝExcelÎļþ£¬±¾ÎĽ«¸ø´ó¼ÒÒ»¸ö¾ªÏ²£¬Ïò´ó¼Ò½éÉÜÒ»¸ö¿ª·ÅÔ´ÂëÏîÄ¿£¬Java Excel API£¬Ê¹ÓÃËü´ó¼Ò¾Í¿ÉÒÔ·½±ãµØ²Ù×ÝExcelÎļþÁË¡£
JAVA EXCEL API¼ò½é
Java ExcelÊÇÒ»¿ª·ÅÔ´ÂëÏîÄ¿£¬Í¨¹ýËüJava¿ª·¢ÈËÔ±¿ÉÒÔ¶ÁÈ¡ExcelÎļþµÄÄÚÈÝ¡¢´´½¨ÐµÄExcelÎļþ¡¢¸üÐÂÒѾ´æÔÚµÄExcelÎļþ¡£Ê¹ÓøÃAPI·ÇWindows²Ù×÷ϵͳҲ¿ÉÒÔͨ¹ý´¿JavaÓ¦ÓÃÀ´´¦ÀíExcelÊý¾Ý±í¡£ÒòΪÊÇʹÓÃJava±àдµÄ£¬ËùÒÔÎÒÃÇÔÚWebÓ¦ÓÃÖпÉÒÔͨ¹ýJSP¡¢ServletÀ´µ÷ÓÃAPIʵÏÖ¶ÔExcelÊý¾Ý±íµÄ·ÃÎÊ¡£
ÏÖÔÚ·¢²¼µÄÎȶ¨°æ±¾ÊÇV2.0£¬ÌṩÒÔϹ¦ÄÜ£º
´ÓExcel 95¡¢97¡¢2000µÈ¸ñʽµÄÎļþÖжÁÈ¡Êý¾Ý£»
¶ÁÈ¡Excel¹«Ê½£¨¿ÉÒÔ¶ÁÈ¡Excel 97ÒÔºóµÄ¹«Ê½£©£»
Éú³ÉExcelÊý¾Ý±í£¨¸ñʽΪExcel 97£©£»
Ö§³Ö×ÖÌå¡¢Êý×Ö¡¢ÈÕÆڵĸñʽ»¯£»
Ö§³Öµ¥Ôª¸ñµÄÒõÓ°²Ù×÷£¬ÒÔ¼°ÑÕÉ«²Ù×÷£»
ÐÞ¸ÄÒѾ´æÔÚµÄÊý¾Ý±í£»
ÏÖÔÚ»¹²»Ö§³ÖÒÔϹ¦ÄÜ£¬µ«²»¾Ã¾Í»áÌṩÁË£º
²»Äܹ»¶Áȡͼ±íÐÅÏ¢£»
¿ÉÒÔ¶Á£¬µ«ÊDz»ÄÜÉú³É¹«Ê½£¬ÈκÎÀàÐ͹«Ê½×îºóµÄ¼ÆËãÖµ¶¼¿ÉÒÔ¶Á³ö£»
»ØÒ³Ê×
Ó¦ÓÃʾÀý
1 ´ÓExcelÎļþ¶ÁÈ¡Êý¾Ý±í
Java Excel API¼È¿ÉÒÔ´Ó±¾µØÎļþϵͳµÄÒ»¸öÎļþ(.xls)£¬Ò²¿ÉÒÔ´ÓÊäÈëÁ÷ÖжÁÈ¡ExcelÊý¾Ý±í¡£¶ÁÈ¡ExcelÊý¾Ý±íµÄµÚÒ»²½ÊÇ´´½¨Workbook(ÊõÓ¹¤×÷±¡)£¬ÏÂÃæµÄ´úÂëƬ¶Î¾ÙÀý˵Ã÷ÁËÓ¦¸ÃÈçºÎ²Ù×÷£º(ÍêÕû´úÂë¼ûExcelReading.java)
import java.io.*;
import jxl.*;
… … … …
try
{
//¹¹½¨Workbook¶ÔÏó, Ö»¶ÁWorkbook¶ÔÏó
//Ö±½Ó´Ó±¾µØÎļþ´´½¨Workbook
//´ÓÊäÈëÁ÷´´½¨Workbook
InputStream is = new FileInputStream(sourcefile);
jxl.Workbook rwb = Workbook.getWorkbook(is);
}
catch (Exception e)
{
e.printStackTrace();
}
Ò»µ©´´½¨ÁËWorkbook£¬ÎÒÃǾͿÉÒÔͨ¹ýËüÀ´·ÃÎÊExcel Sheet(ÊõÓ¹¤×÷±í)¡£²Î¿¼ÏÂÃæµÄ´úÂëƬ¶Î£º
//»ñÈ¡µÚÒ»ÕÅSheet±í
Sheet rs = rwb.getSheet(0);
ÎÒÃǼȿÉÄÜͨ¹ýSheetµÄÃû³ÆÀ´·ÃÎÊËü£¬Ò²¿ÉÒÔͨ¹ýϱêÀ´·
Ïà¹ØÎĵµ£º
1.¼ÆËãijһÔ·ݵÄ×î´óÌìÊý
1Calendar time=Calendar.getInstance();
2time.clear();
3time.set(Calendar.YEAR,year); //year Ϊ int
4time.set(Calendar.MONTH,i-1);//×¢Òâ,Calendar¶ÔÏóĬÈÏÒ»ÔÂΪ0
5int day=time.getActualMaximum(Calendar.DAY_OF_MONTH);//±¾Ô·ݵÄÌìÊý
×¢£ºÔÚʹÓÃset·½·¨Ö®Ç°£¬±ØÐë ......
Java Web Start ÊÇÒ»¸öhelperÓ¦ÓóÌÐò£¬ËüºÍWEBä¯ÀÀÆ÷¹ØÁªÔÚÒ»Æð¡£µ±Óû§µã»÷Ö¸ÏòÒ»¸öÌض¨µÄlaunchÎļþ(JNLPÎļþ)ʱ£¬»á´Ùʹä¯ÀÀÆ÷×°ÔØJava Web Start, JAWSÈ»ºó×Ô¶¯ÏÂÔØ¡¢»º³å¡¢ÔËÐиø¶¨µÄ»ùÓÚJAVA¼¼ÊõµÄÓ¦ÓóÌÐò¡£Õû¸ö¹ý³ÌÎÞÐèºÍÓû§½øÐн»»¥¡£
JNLP URLsÒ²¿ÉÒÔ´ÓJAWSÓ¦ÓóÌÐò¹ÜÀíÖ±½Ó´ò¿ª²¢ÇÒÄÜÖƳÉÊéÇ©,´ËÍ⣠......
ת£º http://hi.baidu.com/jiong0818/blog/item/93f9b21641294b4d20a4e971.html JavaÖÐÈÕÆÚ¸ñʽת»» /** * ×Ö·û´®×ª»»Îªjava.util.Date
* Ö§³Ö¸ñʽΪ yyyy.MM.dd G 'at' hh:mm:ss z Èç '2002-1-1 AD at 22:10:59 PSD'
* yy/MM/dd HH:mm:ss Èç '2002/1/1 17:55:00'
* yy/MM/dd HH:mm:ss pm Èç '2002/1/1 17:55:00 p ......
javaÐéÄâ»ú±àÒë»úÖÆ£¬¾²Ì¬³£Á¿ÔÚ±àÒëºó£¬³ÉΪÁ˳£Á¿£¬¶ø²»ÊÇÔÏȵĴúÂ룬ÀýÈ磺
ÓÐÒ»¸öÀà
Contant.java
ÀïÃæÓÐһЩ¾²Ì¬³£Á¿
public static final String GONGDAN = "gongdan@ceopen.cn";
public static final String ICT = "ictnetwork@ceopen.cn";
È»ºóÔÚ³ÌÐòÖÐÓÐʹÓÃÕâЩ³£Á¿£¬Contant.GONGDAN
ÔÚÄÇЩ³ÌÐò±àÒëºóµÄ ......