java怎样生成excel柱状图表(急) java中用什么方法可以实现,生成excel中的柱状图,而不是jfreechart图. 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 问题补充:我想在excel中显示一张柱状图 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); // 写入工作表 wwb.write(); wwb.close(); } catch (Exception e) { System.out.println( "" + e); } } public static void modifyExcel(File file1, File file2) { try { // 先copy 在操作第二个文件修改, Workbook rwb = Workbook.getWorkbook(file1); WritableWorkbook wwb = Workbook.createWorkbook(file2, rwb); // copy WritableSheet ws = wwb.getSheet( 0 ); WritableCell wc = ws.getWritableCell( 0 , 0 ); // 判断单元格的类型,做出相应的转换 Label label = (Label) wc; label.setString( " 1 " ); wwb.write(); wwb.close(); rwb.close(); } catch (Exception e) { e.printStackTrace(); } } /** * 读取Excel * * @param filePath */ public static void readExcel(String filePath) { try { InputStream is = new FileInputStream(filePath); Workbook rwb = Workbook.getWorkbook(is); // Sheet st = rwb.getSheet("0")这里有两种方法获取sheet表,1为名字,而为下标,从0开始 Sheet st = rwb.getSheet( " original " ); Cell c00 = st.getCell( 0 , 0 ); // 通用的获取cell值的方式,返回字符串 String strc00 = c00.getContents(); // 获得cell具体类型值的方式 if (c00.getType() == CellType.LABEL) { LabelCell labelc00 = (LabelCell) c00; strc00 = labelc00.getString(); } // 输出 System.out.println(strc00); // 关闭 rwb.close(); } catch (Exception e) { e.printStackTrace(); } } public static void main(String args[]) { try { File fileWrite = new File( " f:/cardWrite.xls " ); fileWrite.createNewFile(); OutputStream os = new FileOutputStream(fileWrite); JexcelHandle.writeExcel(os); JexcelHandle.modifyExcel( new File( " f:/cardWrite.xls " ), new File( " f:/cardWrite2.xls " )); } catch (Exception e) { System.out.println(e); } }}在网上看了写源码在结合自己的。不要忘了下载jxl包哟。http://www.andykhan.com/jexcelapi/ <%@ page contentType="text/html; charset=utf-8" language="java" import="java.sql.*" errorPage="" %><%@ page import="org.eagle.gz.*"%><%@ page import="java.io.*"%><html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><title>无标题文档</title><style type="text/css"><!--body,td,th { font-size: 12px;}body { margin-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px;}--></style></head><body><%try{response.reset();//清除Bufferresponse.setContentType("application/vnd.ms-excel");File fileWrite = new File("f:/testWrite.xls");fileWrite.createNewFile();new FileOutputStream(fileWrite);JexcelHandle.writeExcel(new FileOutputStream(fileWrite));}catch(Exception e){ System.out.println(e);}%></body></html> 应该没有办法直接生成,只能用java画图生成图片插入excel中。 jcom不过,不太好用.没有api又没资料可找. 一下,POI中应该有相应的功能 我晕,jfreechart里面不是可以生成柱状的图么把它提供的demo例子运行一下然后再反编译就得到源码了,稍加修改就可以用了 我现在也有这需要,要求文件里的图表是excel的图表(用户有修改excel中图表数据的需求),这图表可不是一张图片啊 关于生成java源码的问题 如何将表单中获取的数据与数据库数据进行比较,%100结帖 数据库连接问题 WSS4J successfully in a BEA Weblogic 10 spring中,如何判断hibernate事务是否成功 请教tomcat发布网站的问题 有关MYSQL编码的郁闷问题,大家帮我看看什么原因吧?谢谢 有用过opencms的吗 hibernat异常驻机构 Tomcat4.0开发的一个Struts小程序遇到的问题,急盼高手帮助!!! web项目占用大量tomcat内存 Hibernate不能自动创建表呢?
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);
// 写入工作表
wwb.write();
wwb.close();
} catch (Exception e) {
System.out.println( "" + e);
} } public static void modifyExcel(File file1, File file2) {
try {
// 先copy 在操作第二个文件修改,
Workbook rwb = Workbook.getWorkbook(file1);
WritableWorkbook wwb = Workbook.createWorkbook(file2, rwb); // copy
WritableSheet ws = wwb.getSheet( 0 );
WritableCell wc = ws.getWritableCell( 0 , 0 ); // 判断单元格的类型,做出相应的转换
Label label = (Label) wc;
label.setString( " 1 " ); wwb.write();
wwb.close();
rwb.close();
} catch (Exception e) {
e.printStackTrace();
}
} /**
* 读取Excel
*
* @param filePath
*/
public static void readExcel(String filePath) {
try {
InputStream is = new FileInputStream(filePath);
Workbook rwb = Workbook.getWorkbook(is);
// Sheet st = rwb.getSheet("0")这里有两种方法获取sheet表,1为名字,而为下标,从0开始
Sheet st = rwb.getSheet( " original " );
Cell c00 = st.getCell( 0 , 0 );
// 通用的获取cell值的方式,返回字符串
String strc00 = c00.getContents();
// 获得cell具体类型值的方式
if (c00.getType() == CellType.LABEL) {
LabelCell labelc00 = (LabelCell) c00;
strc00 = labelc00.getString();
}
// 输出
System.out.println(strc00);
// 关闭
rwb.close();
} catch (Exception e) {
e.printStackTrace();
}
} public static void main(String args[]) {
try {
File fileWrite = new File( " f:/cardWrite.xls " );
fileWrite.createNewFile();
OutputStream os = new FileOutputStream(fileWrite);
JexcelHandle.writeExcel(os);
JexcelHandle.modifyExcel( new File( " f:/cardWrite.xls " ), new File(
" f:/cardWrite2.xls " ));
} catch (Exception e) {
System.out.println(e);
}
}}
在网上看了写源码在结合自己的。不要忘了下载jxl包哟。http://www.andykhan.com/jexcelapi/ <%@ page contentType="text/html; charset=utf-8" language="java" import="java.sql.*" errorPage="" %>
<%@ page import="org.eagle.gz.*"%>
<%@ page import="java.io.*"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>无标题文档</title>
<style type="text/css">
<!--
body,td,th {
font-size: 12px;
}
body {
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
}
-->
</style></head><body><%
try{
response.reset();//清除Buffer
response.setContentType("application/vnd.ms-excel");
File fileWrite = new File("f:/testWrite.xls");
fileWrite.createNewFile();
new FileOutputStream(fileWrite);
JexcelHandle.writeExcel(new FileOutputStream(fileWrite));
}catch(Exception e){
System.out.println(e);
}
%>
</body>
</html>
把它提供的demo例子运行一下然后再反编译就得到源码了,稍加修改就可以用了