excel创建
来源:互联网 发布:2016刷枪软件 编辑:程序博客网 时间:2024/05/20 21:18
package org.accp.getdatainfo.excel;
import jxl.*;
import jxl.format.Alignment;
import jxl.format.Border;
import jxl.format.BorderLineStyle;
import jxl.format.Colour;
import jxl.format.UnderlineStyle;
import jxl.write.*;
import jxl.write.Boolean;
import jxl.write.Number;
import java.io.*;
import java.io.File.*;
import java.util.*;
public class CreateXLS {
public static void main(String[] args) {
//String targetfile = "E:/out.xlsx";// 输出的excel文件名
String worksheet = "List";// 输出的excel文件工作表明
String[] title = { "ID", "NAME", "DESCREIB" };
WritableWorkbook workbook;
try {
// 创建可写入的Excel工作薄,运行时生成的文件在tomcat/bin下
// workbook = Workbook.createWorkbook(new File("out.xlsx")
// );
System.out.println("begin");
//OutputStream os = new FileOutputStream(targetfile);
//workbook = Workbook.createWorkbook(os);
workbook = Workbook.createWorkbook(new File("数据库结构显示图.xls"));
WritableSheet sheet = workbook.createSheet(worksheet, 0);// 添加第一个工作表
//WritableSheet sheet1 = workbook.createSheet(worksheet1, 1);//可添加第二个工作表
/*
* Label label = new Label(0, 2,"A label record");//put a label in
* cell A3 Label(column,row); sheet.addCell(label);
*/
Label label;
for (int i = 0; i < title.length; i++) {
// Label(列好,行号,内容);
label = new Label(i, 0, title[i]);// put the title in row 1
sheet.addCell(label);
}
Number number = new Number(3, 4, 3.14159);// put the number
// 3.14159in cell D5
sheet.addCell(number);
// 添加带有字型Formatting 的对象
WritableFont wf = new WritableFont(WritableFont.TIMES, 10,
WritableFont.BOLD, true);
WritableCellFormat wcfF = new WritableCellFormat(wf);
Label labelCF = new Label(4, 4, "文本", wcfF);
sheet.addCell(labelCF);
// 添加带有字体颜色,带背景颜色Formatting 的对象
WritableFont wfc = new WritableFont(WritableFont.ARIAL, 10,
WritableFont.BOLD, false, UnderlineStyle.NO_UNDERLINE,
Colour.RED);
;
WritableCellFormat wcfFC = new WritableCellFormat(wfc);
wcfFC.setBackground(Colour.BLUE);
Label labelCFC = new Label(1, 5, "带颜色", wcfFC);
sheet.addCell(labelCFC);
// 添加带有formatting 的Number 对象
NumberFormat nf = new NumberFormat("#.##");
WritableCellFormat wcfN = new WritableCellFormat(nf);
Number labelNF = new Number(1, 1, 3.1415926, wcfN);
sheet.addCell(labelNF);
// 添加boolean 的对象
Boolean labelB = new Boolean(0, 3, false);
sheet.addCell(labelB);
// 添加DataTime对象
DateTime labelDT = new DateTime(0, 3, new Date());
sheet.addCell(labelDT);
// 添加带有formatting的DateFormat对象
DateFormat df = new DateFormat("ddMMyyyyhh:mm:ss");
WritableCellFormat wcfDF = new WritableCellFormat(df);
DateTime labelDTF = new DateTime(1, 3, new Date(), wcfDF);
sheet.addCell(labelDTF);
// 合并单元格
// sheet.mergeCells(int col1, int row1, int col2, int row2);
sheet.mergeCells(4, 5, 8, 10);
wfc = new WritableFont(WritableFont.ARIAL, 10, WritableFont.BOLD,
false, UnderlineStyle.NO_UNDERLINE, Colour.GREEN);
WritableCellFormat wchB = new WritableCellFormat(wfc);
wchB.setAlignment(Alignment.CENTRE);
labelCFC = new Label(4, 5, "合并单元格", wchB);
sheet.addCell(labelCFC);
// 设置边框
WritableCellFormat wcsB = new WritableCellFormat();
wcsB.setBorder(Border.ALL, BorderLineStyle.THICK);
labelCFC = new Label(0, 6, "设置边框", wcsB);
sheet.addCell(labelCFC);
workbook.write();
workbook.close();
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("end");
Runtime r = Runtime.getRuntime();
Process p = null;
//Sftring cmd[]={"notepad","exec.java"};
String cmd[]={"C:\\Program Files\\kingsoft\\WPS Office Personal\\office6\\et.exe","数据库结构显示图.xls"};
try {
p = r.exec(cmd);
} catch (Exception e) {
System.out.println("error executing:"+cmd[0]);
}
}
}
- excel创建
- 创建Excel
- 创建Excel
- 创建excel
- C#创建EXCEL
- excel的创建打开
- VC创建EXCEL图表
- EXCEL创建菜单栏项目
- 创建EXCEl文件
- jxl创建excel
- VC创建EXCEL图表
- VC创建Excel报表
- Excel创建下拉列表
- Asp 创建Excel 类
- DWR3 创建下载 Excel
- HSSFWorkbook创建excel
- 创建excel 批注
- 创建excel 文件流
- C# WebClient上传下载时进度条显示
- IMAP命令参考
- '4.294967295E9' in column '7' is outside valid range for the datatype INTEGER.
- There is a chrome web app for that:探测与网站匹配的扩展
- 用汇编的眼光看C++(之嵌入汇编)
- excel创建
- iBatis.Net异步多线程 操作Ibatis报错
- 还用的正表达式
- 《Microsoft SQL Server 2008 MDX Step by Step》学习笔记七:执行聚合(上)
- Spring Security3.1 最新配置实例
- [20111123] 什么是青年危机?
- NSString+NSMutableString+NSValue+NSAraay用法汇总
- Spring的AOP配置
- File System with Actionscript3 on AIR