通过Excel中的数据导入到图形报表(不太完整,不推荐使用)
2012-03-09 16:43
375 查看
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(); } } }
相关文章推荐
- 【推荐】.NET(webform,MVC)使用NPOI组件将数据导出、导入Excel。 Aspose.Cell 控件报表
- ThinkPHP使用PHPExcel实现Excel数据导入导出完整实例
- ThinkPHP使用PHPExcel实现Excel数据导入导出完整实例
- ThinkPHP使用PHPExcel实现Excel数据导入导出完整实例
- ThinkPHP使用PHPExcel实现Excel数据导入导出完整实例
- ThinkPHP使用PHPExcel实现Excel数据导入导出完整实例
- 导入Excel的时候使用TransactionScope事务控制来进行数据
- phpexcel导入excel数据使用方法实例
- asp.net使用组件koogra读取Excel数据批量上传导入
- 将excel数据通过plsql导入oracle的问题
- SQLT导入测试数据,及SQL Profile的使用 推荐
- 少量数据通过Excel表格数据导入server SqlServer查询
- 通过上传excel导入数据到数据库
- 使用Python将Excel中的数据导入到MySQL
- 【VBA】 通过VBA脚本将EXCEL的数据导入 ORACLE
- 使用php将数据导入excel的简单方法
- C# winform 导出导入Excel/Doc 完整实例教程 使用Aspose.Cells.dll——第二篇
- 使用OPENROWSET将数据从excel导入到sql server
- 使用NPOI:Excel表向sql_server08数据库导入数据
- 使用PHP导入Excel和导出数据为Excel文件