日期:2014-05-16  浏览次数:20433 次

java poi对excel处理 用jsp显示处理

import java.io.File;
import java.io.FileInputStream;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;

import oracle.net.aso.r;

import org.apache.openjpa.lib.conf.StringValue;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFFont;
import org.apache.poi.hssf.usermodel.HSSFPalette;
import org.apache.poi.hssf.usermodel.HSSFRichTextString;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.util.HSSFColor;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.util.CellRangeAddress;

import bsh.org.objectweb.asm.Label;

/**
?* poi-3.7
?*
?* @author Administrator
?*
?*/
public class ExcelUtils {

?public ExcelUtils() {
??
?}
???
?private int sumWidth;
?
?public static void main(String args[]) {
??ExcelUtils eu = new ExcelUtils();
??// String filepath="E:\\myproject\\eipplugin\\test.xls";
??String filepath = "D:\\1.xls";
??HSSFWorkbook workbook = eu.readExcelFile(filepath);
??String exceltitle = eu.getFirstRowContent(workbook, 0);
??// System.out.println(exceltitle);
??// StringBuffer htmlsource=eu.excelToHtmlSource(workbook, 0);
??StringBuffer htmlsource = eu.excelToHtmlJs(workbook, 0);
??StringBuffer htmlbuf = new StringBuffer("");
??htmlbuf.append(eu.headerHtmlStart(exceltitle));

??htmlbuf.append(htmlsource);

??htmlbuf.append(eu.headerHtmlEnd());

??// htmlbuf.append(eu.excelToHtmlSource(workbook, 0));

??htmlbuf.append(eu.bodyHtml());
??htmlbuf.append(eu.bodyHtmlEnd());

??try {
???FileUtils.writeFile("E:\\excel\\小学\\excel3.html ", htmlbuf);
??} catch (Exception e) {
???e.printStackTrace();
??}
??// System.out.println(htmlsource);
?}

?public StringBuffer headerHtmlStart(String title) {
??StringBuffer sb = new StringBuffer("");
??sb.append("<html>\n");
??sb.append("<head>\n");
??sb
????.append("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=gb2312\" />\n");
??sb.append("<META HTTP-EQUIV=\"pragma\" CONTENT=\"no-cache\">\n");
??sb
????.append("<META HTTP-EQUIV=\"Cache-Control\" CONTENT=\"no-cache, must-revalidate\">\n");
??sb.append("<META HTTP-EQUIV=\"expires\" CONTENT=\"0\">\n");

??sb.append("<title>" + title + "</title>\n");
?//?sb.append("<link href=\"js/style.css\" rel=\"stylesheet\" type=\"text/css\" />\n");
??sb.append("<SCRIPT type=\"text/javascript\" src=\"js/jquery-1.3.2.min.js\"></SCRIPT>\n");
??sb.append("<script type=\"text/javascript\" src=\"js/scripts-pack.js\"></script>\n");
??sb.append("<script type=\"text/javascript\" src=\"js/jquery-ui-1.7.2.custom.min.js\"></script>\n");
??sb.append("<script type=\"text/javascript\" src=\"js/jquery.chromatable.js\"></script>\n");
??return sb;
?}

?public StringBuffer headerHtmlEnd() {
??StringBuffer sb = new StringBuffer("");
??sb.append("</head>\n");
??sb.append("<body>\n");// 进入页面就刷新下

??return sb;
?}

?public StringBuffer bodyHtml() {
??StringBuffer sb = new StringBuffer("");
??sb.append("<a id=\"deldata\" href=\"#\">查看全部结果</a>\n");
??sb.append("<br/>\n");
??sb.append("<table id='exceltitletable' width=\""+this.getSumWidth()+"\"?? border=\"0\