请问如何将JTable表的内容输出到Excel
如题!能把代码贴出来么,我需要代码,小弟在此先行谢过来访的各位高手了用(POI包)作急急急!!!!把代码帖出来好么...
如题 ! 能把代码贴出来么,我需要代码,小弟在此先行谢过来访的各位高手了 用(POI包)作 急 急 急 !!!! 把代码帖出来好么
展开
2013-11-08
展开全部
用jxl.jar把很方便好用 http://hi.baidu.com/zbzb/blog/item/95c4ac1804a8600734fa4100.html 这是包下载地址。 这是例子: import jxl.*; import jxl.write.*; import java.io.*; import java.io.File.*; import java.util.*; public class excel { public static void main(String[] args) { String targetfile = "c:/out.xls";//输出的excel文件名 String worksheet = "List";//输出的excel文件工作表名 String[] title = {"ID","NAME","DESCRIB"};//excel工作表的标题 WritableWorkbook workbook; try { //创建可写入的Excel工作薄,运行生成的文件在tomcat/bin下 //workbook = Workbook.createWorkbook(new File("output.xls")); System.out.println("begin"); OutputStream os=new FileOutputStream(targetfile); workbook=Workbook.createWorkbook(os); WritableSheet sheet = workbook.createSheet(worksheet, 0); //添加第一个工作表 //WritableSheet sheet1 = workbook.createSheet("MySheet1", 1); //可添加第二个工作 /* jxl.write.Label label = new jxl.write.Label(0, 2, "A label record"); //put a label in cell A3, Label(column,row) sheet.addCell(label); */ jxl.write.Label label; for (int i=0; i<title.length; i++) { //Label(列号,行号 ,内容 ) label = new jxl.write.Label(i, 0, title[i]); //put the title in row1 sheet.addCell(label); } //下列添加的对字体等的设置均调试通过,可作参考用 //添加数字 jxl.write.Number number = new jxl.write.Number(3, 4, 3.14159); //put the number 3.14159 in cell D5 sheet.addCell(number); //添加带有字型Formatting的对象 jxl.write.WritableFont wf = new jxl.write.WritableFont(WritableFont.TIMES,10,WritableFont.BOLD,true); jxl.write.WritableCellFormat wcfF = new jxl.write.WritableCellFormat(wf); jxl.write.Label labelCF = new jxl.write.Label(4,4,"文本",wcfF); sheet.addCell(labelCF); //添加带有字体颜色,带背景颜色 Formatting的对象 jxl.write.WritableFont wfc = new jxl.write.WritableFont(WritableFont.ARIAL,10,WritableFont.BOLD,false,jxl.format.UnderlineStyle.NO_UNDERLINE,jxl.format.Colour.RED); jxl.write.WritableCellFormat
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询