JAVA EXCEL API¼ò½é
ʹÓÃ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»ÄÜÉú³É¹«Ê½£¬ÈκÎÀàÐ͹«Ê½×îºóµÄ¼ÆËãÖµ¶¼¿ÉÒÔ¶Á³ö£»
Ó¦ÓÃʾÀý
´Ó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)
Ïà¹ØÎĵµ£º
ÔÚJava
ÐéÄâ»úµÄ¹æ·¶Öж¨ÒåÁËһϵÁеÄ×Óϵͳ¡¢ÄÚ´æÇøÓò¡¢Êý¾ÝÀàÐͺÍʹÓÃÖ¸ÄÏ¡£ÕâЩ×é¼þ¹¹³ÉÁËJava
ÐéÄâ»úµÄÄÚ²¿½á¹¹£¬ËûÃDz»½ö½öΪJava
ÐéÄâ»úµÄʵÏÖÌṩÁËÇåÎúµÄÄÚ²¿½á¹¹£¬¸üÊÇÑϸñ¹æ¶¨ÁËJava
ÐéÄâ»úʵÏÖµÄÍⲿÐÐΪ¡£
Ã¿Ò ......
ÎÒÔÚÒ»¸öÓ¡¶ÈÍâ°ü¹«Ë¾¹¤×÷¡£ÎÒËù×öµÄϵͳ´ó²¿·ÖÊÇÓ¡¶È³ÌÐòԱдµÄ¡£
¿´ÁËËûÃǵĴúÂëÓиöÌصã¸ø´ó¼ÒÆÀÆÀ¡£
1¡¢ËûÃÇдµÄ´úÂë±È½ÏÑϽ÷£¬±ÈÈçÔÚÑ»·Ò»¸ö¼¯ºÏÇ°»á×÷nullÅжϣ¬·½·¨ÀàÃüÃûÒ²±È½Ï¹æ·¶Ò׶®¡£
2¡¢ËûÃÇ£¬×¢ÊÍдµÄ²»¶à£¬µ«logдºÜÇÚ¿ì¡£
3¡¢ËûÃǺÃÏñ²»Ì«Ï²»¶ÓÃÁÙʱ±äÁ¿£¬Äܲ»Óþ¡Á¿²»Óá£
4¡¢ËûÃǵĴúÂëÈçÅжÏÒ»¸öb ......
1.Ê÷¼¯TreeSet
TreeSetÀàÔÚjava.util°üÖÐ
Ê÷¼¯ÖеĽáµãÊÇ°´×ÅÆä´æ·ÅµÄÊý¾ÝµÄ×ÖµäÐòÒ»²ãÒ»²ãµØÒÀ´ÎÅÅÁÐ ÔÚͬһ²ãÖеĽáµã´Ó×óµ½ÓÒ°´×ÖµäÐòµÝÔöÅÅÁÐ
A.¹¹Ôì·½·¨£ºTreeSet()
B.³£Ó÷½·¨
& ......
ÏÂÔØ dom4j-1.6.1.jar¡£
1: package org.zzp.common.xml.dom4j;
2:
3: import java.io.FileWriter;
4: import java.io.IOException;
5: import org.dom4j.Document;
6: import org.dom4j.DocumentHelper;
7: import org.dom4j.Element;
8: import org.dom4j.io.OutputFormat;
9: impor ......
/**
* ÏÂÔØÎļþ
* @param filePath --ÎļþÍêÕû·¾¶
* @param response --HttpServletResponse¶ÔÏó
*/
public static void downloadFile(
String filePath,
javax.servlet.http.HttpServletResponse response) {
String fileName = ""; //ÎļþÃû£¬Êä³öµ½Óû§µÄÏÂÔضԻ°¿ò
//´ÓÎļþÍêÕû·¾¶ÖÐÌáÈ¡ÎļþÃû£¬²¢½øÐбà ......