‘壹’ java调用EXCEL中图表
oh my god 这么有难度的问题才10分,我倒,我就回答价值十分的答案吧,
1。去网上查nodes的资料(如果你对数据结构不了解的话,可以不用看了)
2。poi,apache开发的东东,不过不怎么好用,HSSF用来实现Excel 的读写.以下是HSSF的主页
http://jakarta.apache.org/poi/hssf/index.html
‘贰’ java操作word中的excel(对应的是图表,如柱状图)
我.net中也遇到了相同的问题:你可以先看一下下面代码,应该大部分你能用到,只是chart属性可能有点问题,之前尝试成功过,但是由于我不小心删除了一些系统文件里的内容,就有些运行不起来了
我是先循环的word中的shape
foreach (Microsoft.Office.Interop.Word.Shape shape in docFile.Shapes)
{
if(shape.Name=="Chart_图表")
{
shape.Chart.ChartData.Activate();
Microsoft.Office.Interop.Excel.Workbook wb = (Microsoft.Office.Interop.Excel.Workbook)shape.Chart.ChartData.Workbook;
Microsoft.Office.Interop.Excel.Worksheet wSh = (Microsoft.Office.Interop.Excel.Worksheet)wb.Worksheets[1];
//然后添加新数据
for (int r = 0; r < tempdt.Rows.Count; r++)
{
for (int k = 0; k < tempdt.Columns.Count; k++)
{
Microsoft.Office.Interop.Excel.Range Rng1 = wSh.Cells[r + 2, k + 1] as Microsoft.Office.Interop.Excel.Range;
Rng1.Value = tempdt.Rows[r][k];
}
}
wb.Application.ScreenUpdating = true;
wb.Close(Type.Missing, Type.Missing, Type.Missing);
chart.Refresh();
shape.Chart.Refresh();
}
}
‘叁’ java 中什么包可以操作excel的宏 生成图表! 高分求解!
宏可以录制你一系列的操作,录制之后,你再点宏,电脑就可以自动重复你在word或excel的一系列事件。以word为例,你可以点宏,然后点录制,然后做一系列操作,如无格式粘贴、左对齐、居中。然后点结束宏。然后你再打开一篇文档,点宏,电脑你会重复你刚才的这些操作。这样对大量文字的排版来说,非常方便。
‘肆’ java 导出Excel数据如何生成图表,如柱状图,折线图
我以前做的是利用jfreechart生成图片,导出excel的时候把图片放进去。
‘伍’ java中如何向excel中绘制柱状图
它完全使用JAVA语言编写,是为applications, applets, servlets 以及JSP等使用所设计。JFreeChart可生成饼图(pie charts)、柱状图(bar charts)、散点图(scatter plots)、时序图(time series)、甘特图(Gantt charts)等等多种图表,并且可以产生PNG和JPEG格式的输出,还可以与PDF和EXCEL关联。
‘陆’ java如何在excel中生成图表
利用POI3.5_HSSF_和XSSF_Excel操作快速入门手册。你可以看看这个,这个是在网络文库查询到的,http://wenku..com/view/0541b193daef5ef7ba0d3cb6.html,你看看这个吧,这个很好用,我一直用这个,就是不知道你希望生成的是什么样子的。
‘柒’ java如何读取excel中报表(柱状图)的信息
public class Report {
/**作用:报表样式的枚举,该类的getvalue方法返回对应值。<br>
* Columns_2DVer:2D柱状垂直报表。<br>
* Columns_3DVer:3D柱状垂直报表。<br>
* Columns_2DHor:2D柱状水平报表。<br>
* Columns_3DHor:3D柱状水平报表。
* */
public enum ReportType{
Columns_2DVer("Z2DV"),
Columns_3DVer("Z3DV"),
Columns_2DHor("Z2DH"),
Columns_3DHor("Z3DH"),
LineReport_2D("Line2D"),
LineReport_3D("Line3D"),
PieReport_2D("Pie2D"),
PieReport_3D("Pie3D");
private ReportType(String a){
this.str=a;
}
private String str;
public String getvalue(){
return this.str;
}
}
/**作用:作为创建报表时的参数。<br>
* 成员1:报表的标题。<br>
* 成员2:报表的横坐标标题。<br>
* 成员3:报表的纵坐标标题。<br>
* 成员4:JSP页面的request对象。<br>
* 成员5:报表所保存的文件名。<br>
* 成员6:报表的长度。<br>
* 成员7:报表的宽度。<br>
* 成员8:报表的背景颜色,默认为白色。<br>
* 成员9:报表网格中竖线的颜色,默认为黑色。<br>
* 成员10:报表网格中横线的颜色,默认为黑色。<br>
* 成员11:报表横轴内容的数组。<br>
* 成员12:报表纵轴内容的list数组。<br>
* 成员13:提示信息。如果写入多个提示信息,报表就变成多柱状。<br>
* 成员14:报表的模式。详见reportType枚举类<br>
* 成员15:饼状图专用的数值数组。数组的和必须等于1.<br>
* 注意1:要在JSP页面引入该类型才能使用,横纵轴数组的长度必须一致。<br>
* 注意2:如果在提示信息数组中写入了多个提示信息,那么报表纵轴内容的
* list中就必须存放入和它数量一致的int数组。否则会出错。
* */
public class ReportClass{
public String ReportTitle;
public String xTitle;
public String yTitle;
public HttpServletRequest request;
public String filename;
public int width;
public int height;
public Color BackgroundColor=Color.WHITE;
public Color ylineColor=Color.BLACK;
public Color xlineColor=Color.BLACK;
public String[] xValues;
public ArrayList<int[]> yValue=new ArrayList<int[]>();
public String[] helpstr;
public String reportType;
public double[] PieValue;
}
/**作用:创建一个指定类型和数据的图表。<br>
* 参数1:ReportClass类型,各成员具体作用参见ReportClass说明<br>
* 返回值:String类型,在JSP页面可以直接out.println显示图形。<br>
* 注意1:ReportClass类型中,必须设置的成员主要有:<br>
* 1、ReportTitle 2、request 3、filename 4、width 5、height 6、reportType<br>
* 注意2:如果要生成饼状图,还需要设置:<br>
* 1、xValues 2、PieValue 这两个数组的长度必须一致<br>
* 注意3:如果要生成柱状图或折线图,还需要设置:<br>
* 1、xValues 2、yValue 3、helpstr<br>
* yvalue数组总和必须等于1.即100%.<br>
* 如果要生成多柱状或折线图,则需要设置helpstr长度。<br>
* yvalue列表的长度必须和helpstr数组长度一致。<br>
* yvalue中的成员数组的长度必须和xvalue数组长度一致。
* */
public String CreateReport(ReportClass rc){
String s="sf";
String str="";
JFreeChart jc=null;
Font titlefont=new Font("宋体",Font.BOLD,20);
Font tickfont=new Font("宋体",0,15);
Font labelfont=new Font("宋体",Font.BOLD,15);
DefaultCategoryDataset ds=null;
DefaultPieDataset pds=null;
if (rc.ReportTitle!=null){
if (rc.reportType.indexOf("Pie")!=-1){//饼状图
pds=new DefaultPieDataset();
double[] ob=rc.PieValue;
for (int i=0;i<ob.length;i++){
pds.setValue(rc.xValues[i], ob[i]);
}
if (rc.ReportTitle!=null){
if (rc.reportType.equals("Pie2D")){
jc=ChartFactory.createPieChart(rc.ReportTitle,pds,true, true, false);
}
else if (rc.reportType.equals("Pie3D")){
jc=ChartFactory.createPieChart3D(rc.ReportTitle,pds,true, true, false);
}
jc.getTitle().setFont(titlefont);
jc.getLegend().setItemFont(labelfont);
jc.setBackgroundPaint(rc.BackgroundColor);//总背景色
jc.setBorderPaint(rc.BackgroundColor);
PiePlot plot=(PiePlot)jc.getPlot();
plot.setBackgroundPaint(rc.BackgroundColor);
plot.setLabelFont(new Font("宋体",0,15));
}
}
else { //柱状或折线图
ds=new DefaultCategoryDataset();
for (int i=0;i<rc.helpstr.length;i++){
int[] ob=rc.yValue.get(i);
for (int j=0;j<ob.length;j++){
ds.addValue(ob[j], rc.helpstr[i], rc.xValues[j]);
}
}
if (rc.reportType.indexOf("Z2D")!=-1){
PlotOrientation po=null;
if (rc.reportType.indexOf("V")!=-1){
po=PlotOrientation.VERTICAL;
}
else if (rc.reportType.indexOf("H")!=-1){
po=PlotOrientation.HORIZONTAL;
}
jc=ChartFactory.createBarChart(rc.ReportTitle, rc.xTitle, rc.yTitle,
ds, po, true, true, false);
}
else if (rc.reportType.indexOf("Z3D")!=-1){
PlotOrientation po=null;
if (rc.reportType.indexOf("V")!=-1){
po=PlotOrientation.VERTICAL;
}
else if (rc.reportType.indexOf("H")!=-1){
po=PlotOrientation.HORIZONTAL;
}
jc=ChartFactory.createBarChart3D(rc.ReportTitle, rc.xTitle, rc.yTitle,
ds, po, true, true, false);
}
else if (rc.reportType.equals("Line2D")){
PlotOrientation po=PlotOrientation.VERTICAL;
jc=ChartFactory.createLineChart(rc.ReportTitle, rc.xTitle, rc.yTitle,
ds, po, true, true, false);
}
else if (rc.reportType.equals("Line3D")){
PlotOrientation po=PlotOrientation.VERTICAL;
jc=ChartFactory.createLineChart3D(rc.ReportTitle, rc.xTitle, rc.yTitle,
ds, po, true, true, false);
}
jc.getTitle().setFont(titlefont);
jc.getLegend().setItemFont(labelfont);
jc.setBackgroundPaint(rc.BackgroundColor);//总背景色
CategoryPlot cp=jc.getCategoryPlot();
cp.setBackgroundPaint(rc.BackgroundColor);//图形框架背景色
cp.setDomainGridlinePaint(rc.ylineColor);//图形背景网格中竖线的颜色
cp.setDomainGridlinesVisible(true);
cp.setRangeGridlinePaint(rc.xlineColor);//图形背景网格中横线的颜色
cp.getDomainAxis().setTickLabelFont(tickfont);
cp.getDomainAxis().setLabelFont(labelfont);
cp.getRangeAxis().setTickLabelFont(tickfont);
cp.getRangeAxis().setLabelFont(labelfont);
}
try {
File ff=new File(rc.request.getRealPath("/")+"file");
if (!ff.exists()){
ff.mkdir();
}
File file=new File(rc.request.getRealPath("/")+"file/"+rc.filename);
if (!file.exists()){
file.createNewFile();
}
ChartUtilities.saveChartAsJPEG(file, jc, rc.width, rc.height);
str="<img src='"+file.getPath()+"'>";
return str;
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return null;
}
}
else {
return null;
}
}
}
以前写的一个报表的集成,可以生成任何形式的报表,要引入JFreeChar.你可以慢慢研究下...
‘捌’ 怎么用java实现读取excel表格里的数据生成曲线图
首先使用JXL读取excel的数据
然后使用JFreeChart把数据转成曲线图
说明:
jxl.jar是通过java操作excel表格的工具类库支持Excel 95-2000的所有版本
JFreeChart是JAVA平台上的一个开放的图表绘制类库.
效果图
‘玖’ java导出excel图表
通过Java程序导出带图表的excel吗?参考下面用spire.xls.jar来创建Excel图表的方法,这里以创建饼图为例,当然你也可以指定创建其他图表类型,如柱状图、折线图、雷达图、散点图等等:
import com.spire.xls.*;
import com.spire.xls.charts.ChartSerie;
import java.awt.*;
public class CreatePieChart {
public static void main(String[] args) {
//创建Workbook对象
Workbook workbook = new Workbook();
//获取第一个工作表
Worksheet sheet = workbook.getWorksheets().get(0);
//将图表数据写入工作表
sheet.getCellRange("A1").setValue("年份");
sheet.getCellRange("A2").setValue("2002");
sheet.getCellRange("A3").setValue("2003");
sheet.getCellRange("A4").setValue("2004");
sheet.getCellRange("A5").setValue("2005");
sheet.getCellRange("B1").setValue("销售额");
sheet.getCellRange("B2").setNumberValue(4000);
sheet.getCellRange("B3").setNumberValue(6000);
sheet.getCellRange("B4").setNumberValue(7000);
sheet.getCellRange("B5").setNumberValue(8500);
//设置单元格样式
sheet.getCellRange("A1:B1").setRowHeight(15);
sheet.getCellRange("A1:B1").getCellStyle().setColor(Color.darkGray);
sheet.getCellRange("A1:B1").getCellStyle().getExcelFont().setColor(Color.white);
sheet.getCellRange("A1:B1").getCellStyle().setVerticalAlignment(VerticalAlignType.Center);
sheet.getCellRange("A1:B1").getCellStyle().setHorizontalAlignment(HorizontalAlignType.Center);
sheet.getCellRange("B2:C5").getCellStyle().setNumberFormat(""¥"#,##0");
//添加饼图
Chart chart = sheet.getCharts().add(ExcelChartType.Pie);
//设置图表数据区域
chart.setDataRange(sheet.getCellRange("B2:B5"));
chart.setSeriesDataFromRange(false);
//设置图表位置
chart.setLeftColumn(3);
chart.setTopRow(1);
chart.setRightColumn(11);
chart.setBottomRow(20);
//设置图表标题
chart.setChartTitle("年销售额");
chart.getChartTitleArea().isBold(true);
chart.getChartTitleArea().setSize(12);
//设置系列标签
ChartSerie cs = chart.getSeries().get(0);
cs.setCategoryLabels(sheet.getCellRange("A2:A5"));
cs.setValues(sheet.getCellRange("B2:B5"));
cs.getDataPoints().getDefaultDataPoint().getDataLabels().hasValue(true);
chart.getPlotArea().getFill().setVisible(false);
//保存文档
workbook.saveToFile("output/PieChart.xlsx", ExcelVersion.Version2016);
}
}
饼图创建效果:
excel饼状图效果