import java.io.*;
import jxl.*;
import jxl.format.UnderlineStyle;
import jxl.write.*;
public class CreateXLS {
public static void main(String args[]) {
try {
//打开文件
WritableWorkbook book= Workbook.createWorkbook(new File("测试.xls"));
//生成名为“第一页”的工作表,参数0表示这是第一页
WritableSheet sheetOne=book.createSheet("第一页",0);
/**
* 定义单元格样式
*/
WritableFont wf_title = new WritableFont(WritableFont.ARIAL, 11,
WritableFont.NO_BOLD, false, UnderlineStyle.NO_UNDERLINE,
jxl.format.Colour.BLACK); // 定义格式 字体 下划线 斜体 粗体 颜色
WritableFont wf_head = new WritableFont(WritableFont.ARIAL, 11,
WritableFont.NO_BOLD, false, UnderlineStyle.NO_UNDERLINE,
jxl.format.Colour.BLACK); // 定义格式 字体 下划线 斜体 粗体 颜色
WritableFont wf_table = new WritableFont(WritableFont.ARIAL, 11,
WritableFont.NO_BOLD, false, UnderlineStyle.NO_UNDERLINE,
jxl.format.Colour.BLACK); // 定义格式 字体 下划线 斜体 粗体 颜色
WritableCellFormat wcf_title = new WritableCellFormat(wf_title); // 单元格定义
wcf_title.setBackground(jxl.format.Colour.WHITE); // 设置单元格的背景颜色
wcf_title.setAlignment(jxl.format.Alignment.CENTRE); // 设置对齐方式
wcf_title.setBorder(jxl.format.Border.ALL, jxl.format.BorderLineStyle.THIN,jxl.format.Colour.BLACK); //设置边框
WritableCellFormat wcf_title1 = new WritableCellFormat(wf_title); // 单元格定义
wcf_title1.setBackground(jxl.format.Colour.LIGHT_GREEN); // 设置单元格的背景颜色
wcf_title1.setAlignment(jxl.format.Alignment.CENTRE); // 设置对齐方式
wcf_title1.setBorder(jxl.format.Border.ALL, jxl.format.BorderLineStyle.THIN,jxl.format.Colour.BLACK); //设置边框
WritableCellFormat wcf_title2 = new WritableCellFormat(wf_title); // 单元格定义
wcf_title2.setBackground(jxl.format.Colour.YELLOW2); // 设置单元格的背景颜色
wcf_title2.setAlignment(jxl.format.Alignment.CENTRE); // 设置对齐方式
wcf_title2.setBorder(jxl.format.Border.ALL, jxl.format.BorderLineStyle.THIN,jxl.format.Colour.BLACK); //设置边框
WritableCellFormat wcf_head1 = new WritableCellFormat(wf_head);
wcf_head1.setBackground(jxl.format.Colour.LIGHT_GREEN);
wcf_head1.setAlignment(jxl.format.Alignment.CENTRE);
wcf_head1.setBorder(jxl.format.Border.ALL, jxl.format.BorderLineStyle.THIN,jxl.format.Colour.BLACK);
WritableCellFormat wcf_head2 = new WritableCellFormat(wf_head);
wcf_head2.setBackground(jxl.format.Colour.YELLOW2);
wcf_head2.setAlignment(jxl.format.Alignment.CENTRE);
wcf_head2.setBorder(jxl.format.Border.ALL, jxl.format.BorderLineStyle.THIN,jxl.format.Colour.BLACK);
WritableCellFormat wcf_table1 = new WritableCellFormat(wf_table);
wcf_table1.setBackground(jxl.format.Colour.LIGHT_GREEN);
wcf_table1.setAlignment(jxl.format.Alignment.CENTRE);
wcf_table1.setBorder(jxl.format.Border.ALL, jxl.format.BorderLineStyle.THIN,jxl.format.Colour.BLACK);
WritableCellFormat wcf_table2 = new WritableCellFormat(wf_table);
wcf_table2.setBackground(jxl.format.Colour.YELLOW2);
wcf_table2.setAlignment(jxl.format.Alignment.CENTRE);
wcf_table2.setBorder(jxl.format.Border.ALL, jxl.format.BorderLineStyle.THIN,jxl.format.Colour.BLACK);
sheetOne.setColumnView(0, 15); // 设置列的宽度
sheetOne.setColumnView(1, 15); // 设置列的宽度
sheetOne.setColumnView(2, 15); // 设置列的宽度
sheetOne.setColumnView(3, 15); // 设置列的宽度
sheetOne.setColumnView(4, 15); // 设置列的宽度
sheetOne.setColumnView(5, 15); // 设置列的宽度
sheetOne.setColumnView(6, 15); // 设置列的宽度
sheetOne.setColumnView(7, 15); // 设置列的宽度
sheetOne.setColumnView(8, 15); // 设置列的宽度
sheetOne.setColumnView(9, 15); // 设置列的宽度
sheetOne.setColumnView(10, 15); // 设置列的宽度
sheetOne.setColumnView(11, 15); // 设置列的宽度
sheetOne.setColumnView(12, 15); // 设置列的宽度
sheetOne.setColumnView(13, 15); // 设置列的宽度
//在Label对象的构造子中指名单元格位置是第一列第一行(0,0)
//以及单元格内容为test
Label title=new Label(0,0,"统计",wcf_title);
Label titleOne=new Label(0,1,"统计1",wcf_title1);
Label titleTwo=new Label(2,1,"统计2",wcf_title2);
Label column1=new Label(0,2,"姓名",wcf_head1);
Label column2=new Label(1,2,"所选课程",wcf_head1);
Label column3=new Label(2,2,"姓名",wcf_head2);
Label column4=new Label(3,2,"所选课程",wcf_head2);
//或者WritableCell cell = new jxl.write.Number(column, row, value, wcf)
//将定义好的单元格添加到工作表中
sheetOne.addCell(title);
sheetOne.addCell(titleOne);
sheetOne.addCell(titleTwo);
sheetOne.addCell(column1);
sheetOne.addCell(column2);
sheetOne.addCell(column3);
sheetOne.addCell(column4);
//合: 第1列第1行 到 第13列第1行
sheetOne.mergeCells(0, 0, 3, 0);
sheetOne.mergeCells(0, 1, 1, 1);
sheetOne.mergeCells(2, 1, 3, 1);
/*动态数据 */
Label content1=new Label(0,3,"张三",wcf_table1);
Label content2=new Label(0,4,"张三",wcf_table1);
Label content3=new Label(0,5,"张三",wcf_table1);
Label kecheg1=new Label(1,3,"语文",wcf_table1);
Label kecheg2=new Label(1,4,"数学",wcf_table1);
Label kecheg3=new Label(1,5,"英语",wcf_table1);
sheetOne.addCell(content1);
sheetOne.addCell(content2);
sheetOne.addCell(content3);
sheetOne.addCell(kecheg1);
sheetOne.addCell(kecheg2);
sheetOne.addCell(kecheg3);
sheetOne.mergeCells(0, 3, 0, 2+3);
Label content11=new Label(2,3,"李四",wcf_table2);
Label content22=new Label(2,4,"李四",wcf_table2);
Label content33=new Label(2,5,"李四",wcf_table2);
Label kecheg11=new Label(3,3,"语文",wcf_table2);
Label kecheg22=new Label(3,4,"数学",wcf_table2);
Label kecheg33=new Label(3,5,"英语",wcf_table2);
sheetOne.addCell(content11);
sheetOne.addCell(content22);
sheetOne.addCell(content33);
sheetOne.addCell(kecheg11);
sheetOne.addCell(kecheg22);
sheetOne.addCell(kecheg33);
sheetOne.mergeCells(2, 3, 2, 2+3);
//写入数据并关闭文件
book.write();
book.close();
}catch(Exception e){
System.out.println(e);
}
}
}
相关推荐
java利用jxl生成excel文件,代码直接导入就可以跑(修改自己的生成的ecxel地址)
poi jxl 生成EXCEL 报表 POI 用的JAR poi-3.6-20091214.jar jxl 用到的jar jxl-2.6.jar
使用jxl生成excel的通用方法,参数List<?>数据,LinkedHashMap,String>实体类属性名和中文列名的键值对
自己封装的方法,调用 XlHelper.getXl(List<?> voList , Object head , OutputStream ops)方法,直接返回需要的excel,而不需要再去写jxl的方法。第一个参数voList 是excel里的内容,第二个参数head是excel表头。第...
NULL 博文链接:https://heisetoufa.iteye.com/blog/1932093
用jxl生成EXCEL表格,一个非常简单易懂的写法。
jxl模版生成excel,采用类似EL表达式的方式生成模版
JXL生成excel报表,是一种专门用来制作excle的报表工具插件,用来处理导入到处操作
利用JSCH实现文件传输,JXL生成表格,log4使用。拿过来可以直接使用,注意配置文件以及自己的文件传输的类型,文件名等。非模板代码,所以设计隐私部分已删除,还请谅解
jxl是对excel强有力的操纵工具,它具有丰富的API可以满足对excel的各种开发需要。
String template=System.getProperty("user.dir")+"\\src\\template.xls";//模板文件 String book=System.getProperty("user.dir")+"\\src\\book.xls"; Workbook wb=Workbook.getWorkbook(new File(template))...
NULL 博文链接:https://jeasonjack.iteye.com/blog/1186790
例子如下: Object是一个对象实体类,如Studnet.java. List 是一个对象集合,后面的是输出路径. WriteExcel rw=new WriteExcel(); rw.writeExcel(new Object(), List, "f:/a.xls","库存表");...
jxl创建下拉列表,使用Java来操作EXCEL,创建下拉列表
NULL 博文链接:https://greatjone.iteye.com/blog/1160522
NULL 博文链接:https://1017401036.iteye.com/blog/2197461
资源包含:(1)一个txt转为excel Demo(2)将解析出的数据写入excel表格里所需要架包jxl。
java用于生成EXCEL等文件格式的包,直接导入到java工程即可,简单方便,另外还配有jxl api说明文档
jxl对下拉列表的读写操作以及相应的修改功能
。。。