日期:2014-05-19  浏览次数:20897 次

java怎样生成excel柱状图表(急)
java中用什么方法可以实现,生成excel中的柱状图,而不是jfreechart图.

------解决方案--------------------
用POI或jxl不行码?
------解决方案--------------------
利用Jacob技术。
------解决方案--------------------
package org.eagle.jexcel;

import jxl. * ;
import jxl.format.UnderlineStyle;
import jxl.write. * ;
import jxl.write.Number;
import jxl.write.Boolean;
import java.io. * ;

/** 

* <p>
* Title:
* </p>

* <p>
* Description:
* </p>

* <p>
* Copyright: Copyright (c) 2006
* </p>

* <p>
* Company:
* </p>

* @author eagle
* @version 1.0
*/ 
public class JexcelHandle {
public JexcelHandle() {
}

public static void writeExcel(OutputStream os) {
try {
WritableWorkbook wwb = Workbook.createWorkbook(os);
// 创建excel工作表 镇定名称和位置 
WritableSheet ws = wwb.createSheet( " card sheet " , 0 );
// 1.添加Label对象 
Label label = new Label( 0 , 0 , " 编号 " );
ws.addCell(label);
Label label2 = new Label( 1 , 0 , " 冲值卡号 " );
ws.addCell(label2);
Label label3 = new Label( 2 , 0 , " 冲值卡密码 " );
ws.addCell(label3);
Label label4 = new Label( 3 , 0 , " 最晚冲值时间 " );
ws.addCell(label4);
Label label5 = new Label( 4 , 0 , " 冲值的面值(TC)(1RMB=100TC) " );
ws.addCell(label5);
Label label6 = new Label( 5 , 0 , " 是否作废 " );
ws.addCell(label6);

Number labelN = new Number( 0 , 1 , 3.1415926 );
ws.addCell(labelN);
// 通过 记录集的方式可以得到数据库中的相关的记录
// WritableFont wf = new WritableFont(WritableFont.TIMES, 18,
// WritableFont.BOLD, true);
// WritableCellFormat wcf = new WritableCellFormat(wf);
// Label labelcf = new Label(1, 0, "this is a label test", wcf);
// ws.addCell(labelcf);
// // 2.添加Number对象
// Number labelN = new Number(0,1,3.1415926);
// ws.addCell(labelN);
// 
// // 添加带有formatting的Number对象
// NumberFormat nf = new NumberFormat("#.##");
// WritableCellFormat wcfN = new WritableCellFormat(nf);
// Number labelNF = new jxl.write.Number(1,1,3.1415926,wcfN);
// ws.addCell(labelNF);
// 
// // 3.添加Boolean对象
// Boolean labelB = new jxl.write.Boolean(0,2,false);
// ws.addCell(labelB);
// 
// // 4.添加DateTime对象
// jxl.write.DateTime labelDT = new jxl.write.DateTime(0,3,new
// java.util.Date());
// ws.addCell(labelDT);
// 
// // 添加带有formatting的DateFormat对象
// DateFormat df = new DateFormat("dd MM yyyy hh:mm:ss");
// WritableCellFormat wcfDF = new WritableCellFormat(df);
// DateTime labelDTF = new DateTime(1,3,new java.util.Date(),wcfDF);
// ws.addCell(labelDTF);
// 
// // 添加图片对象,jxl只支持png格式图片
// File image = new File("f:\\x.png");
// WritableImage wimage = new
// WritableImage(0,1,2,2,image); // 0,1分别代表x,y.2,2代表宽和高占的单元格数
// ws.addImage(wimage);