通过Excel中的数据导入到图形报表(不太完整,不推荐使用)

package com.shu.sockets;
import java.awt.Font;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartUtilities;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.StandardChartTheme;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.category.DefaultCategoryDataset;

import com.shu.model.ExcelData;

import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;

public class MyTest {
	public static void main(String[] args) {
		try {
			Workbook book=Workbook.getWorkbook(new File("E:\\my.xls"));
			Sheet[] sheets=book.getSheets();
			List<ExcelData> list=new ArrayList<ExcelData>();
			for(Sheet she : sheets){
				//先声明第一维的长度
				ExcelData ed=null;
				for(int i=0;i<she.getColumns();i++){
					ed=new ExcelData();
					Cell[] cells=she.getColumn(i);
					ed.setColName(cells[0].getContents());
					ed.setColValue(Double.valueOf(cells[1].getContents()));
					list.add(ed);
				}
				
				//Style of the theme
				StandardChartTheme standardChartTheme = new StandardChartTheme("CN");  
				//Style of the font
				standardChartTheme.setExtraLargeFont(new Font("隶书", Font.BOLD, 20));  
				//font of the list
				standardChartTheme.setRegularFont(new Font("宋体", Font.PLAIN, 15));  
				//style of tye x rax
				standardChartTheme.setLargeFont(new Font("宋体", Font.PLAIN, 15));  
				//style of the applicaion
				ChartFactory.setChartTheme(standardChartTheme); 
				
				DefaultCategoryDataset data=new DefaultCategoryDataset();
				for(ExcelData cel : list){
					data.addValue(cel.getColValue(),"", cel.getColName());
				}
				JFreeChart jfc2=ChartFactory.createLineChart(she.getName(),"班级","数据", data,PlotOrientation.VERTICAL,true,true,false);
				ChartUtilities.writeChartAsJPEG(new FileOutputStream("E://"+she.getName()+".jpg"), jfc2,list.size()*40,400);
			}
			book.close();
			System.out.println("done~");
		} catch (BiffException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}

你可能感兴趣的:(String,list,Excel,jfreechart,报表,图形)