excelhandle.java

来自「一个用java编写的功能强大的OA系统」· Java 代码 · 共 246 行

JAVA
246
字号
package com.redmoon.oa.address;import jxl.*;import jxl.write.*;import java.io.*;import java.util.Iterator;public class ExcelHandle {    public ExcelHandle() {    }        public static void writeExcel(OutputStream os, String sql) {        try {             WritableWorkbook wwb = Workbook.createWorkbook(os);                        WritableSheet ws = wwb.createSheet("通讯录", 0);            AddressDb adb = new AddressDb();            Iterator ir = adb.list(sql).iterator();            Label labelA = new Label(0, 0, "英文称谓");            Label labelB = new Label(1, 0, "名");            Label labelC = new Label(2, 0, "中间名");            Label labelD = new Label(3, 0, "姓");            Label labelE = new Label(4, 0, "中文称谓");            Label labelF = new Label(5, 0, "单位");            Label labelG = new Label(6, 0, "部门");            Label labelH = new Label(7, 0, "职务");            Label labelI = new Label(8, 0, "商务地址街道");            Label labelJ = new Label(9, 0, "商务地址街道2");            Label labelK = new Label(10, 0, "商务地址街道3");            Label labelL = new Label(11, 0, "商务地址市县");            Label labelM = new Label(12, 0, "商务地址省市自治区");            Label labelN = new Label(13, 0, "商务地址邮政编码");            Label labelO = new Label(14, 0, "商务地址国家地区");            Label labelP = new Label(15, 0, "住宅地址街道");            Label labelQ = new Label(16, 0, "住宅地址街道2");            Label labelR = new Label(17, 0, "住宅地址街道3");            Label labelS = new Label(18, 0, "住宅地址市县");            Label labelT = new Label(19, 0, "住宅地址省市自治区");            Label labelU = new Label(20, 0, "住宅地址邮政编码");            Label labelV = new Label(21, 0, "住宅地址国家地区");            Label labelW = new Label(22, 0, "其他地址街道");            Label labelX = new Label(23, 0, "其他地址街道2");            Label labelY = new Label(24, 0, "其他地址街道3");            Label labelZ = new Label(25, 0, "其他地址市县");            Label labelAA = new Label(26, 0, "其他地址省市自治区");            Label labelAB = new Label(27, 0, "其他地址邮政编码");            Label labelAC = new Label(28, 0, "其他地址国家地区");            Label labelAD = new Label(29, 0, "助理的电话");            Label labelAE = new Label(30, 0, "商务传真");            Label labelAF = new Label(31, 0, "商务电话");            Label labelAG = new Label(32, 0, "商务电话2");            Label labelAH = new Label(33, 0, "回电话");            Label labelAI = new Label(34, 0, "车载电话");            Label labelAJ = new Label(35, 0, "单位主要电话");            Label labelAK = new Label(36, 0, "住宅传真");            Label labelAL = new Label(37, 0, "住宅电话");            Label labelAM = new Label(38, 0, "住宅电话2");            Label labelAN = new Label(39, 0, "ISDN");            Label labelAO = new Label(40, 0, "移动电话");            Label labelAP = new Label(41, 0, "其他传真");            Label labelAQ = new Label(42, 0, "其他电话");            Label labelAR = new Label(43, 0, "寻呼机");            Label labelAS = new Label(44, 0, "主要电话");            Label labelAT = new Label(45, 0, "无绳电话");            Label labelAU = new Label(46, 0, "TTYTDD电话");            Label labelAV = new Label(47, 0, "电报");            Label labelAW = new Label(48, 0, "Internet忙闲");            Label labelAX = new Label(49, 0, "办公地点");            Label labelAY = new Label(50, 0, "地点");            Label labelAZ = new Label(51, 0, "电子邮件地址");            Label labelBA = new Label(52, 0, "电子邮件类型");            Label labelBB = new Label(53, 0, "电子邮件显示名称");            Label labelBC = new Label(54, 0, "电子邮件3显示名");            Label labelBD = new Label(55, 0, "电子邮件3类型");            Label labelBE = new Label(56, 0, "电子邮件3地址");            Label labelBF = new Label(57, 0, "电子邮件2地址");            Label labelBG = new Label(58, 0, "电子邮件2类型");            Label labelBH = new Label(59, 0, "电子邮件2显示名");            Label labelBI = new Label(60, 0, "附注");            Label labelBJ = new Label(61, 0, "工作证号码");            Label labelBK = new Label(62, 0, "关键字");            Label labelBL = new Label(63, 0, "记帐信息");            Label labelBM = new Label(64, 0, "纪念日");            Label labelBN = new Label(65, 0, "经理姓名");            Label labelBO = new Label(66, 0, "类别");            Label labelBP = new Label(67, 0, "里程");            Label labelBQ = new Label(68, 0, "敏感度");            Label labelBR = new Label(69, 0, "目录服务器");            Label labelBS = new Label(70, 0, "配偶");            Label labelBT = new Label(71, 0, "其他地址邮箱");            Label labelBU = new Label(72, 0, "商务地址邮箱");            Label labelBV = new Label(73, 0, "身份证编号");            Label labelBW = new Label(74, 0, "生日");            Label labelBX = new Label(75, 0, "私有");            Label labelBY = new Label(76, 0, "缩写");            Label labelBZ = new Label(77, 0, "网页");            Label labelCA = new Label(78, 0, "性别");            Label labelCB = new Label(79, 0, "业余爱好");            Label labelCC = new Label(80, 0, "引用者");            Label labelCD = new Label(81, 0, "用户1");            Label labelCE = new Label(82, 0, "用户2");            Label labelCF = new Label(83, 0, "用户3");            Label labelCG = new Label(84, 0, "用户4");            Label labelCH = new Label(85, 0, "优先级");            Label labelCI = new Label(86, 0, "语言");            Label labelCJ = new Label(87, 0, "帐户");            Label labelCK = new Label(88, 0, "职业");            Label labelCL = new Label(89, 0, "住宅地址邮箱");            Label labelCM = new Label(90, 0, "助理的姓名");            Label labelCN = new Label(91, 0, "子女");            ws.addCell(labelA);            ws.addCell(labelB);            ws.addCell(labelC);            ws.addCell(labelD);            ws.addCell(labelE);            ws.addCell(labelF);            ws.addCell(labelG);            ws.addCell(labelH);            ws.addCell(labelI);            ws.addCell(labelJ);            ws.addCell(labelK);            ws.addCell(labelL);            ws.addCell(labelM);            ws.addCell(labelN);            ws.addCell(labelO);            ws.addCell(labelP);            ws.addCell(labelQ);            ws.addCell(labelR);            ws.addCell(labelS);            ws.addCell(labelT);            ws.addCell(labelU);            ws.addCell(labelV);            ws.addCell(labelW);            ws.addCell(labelX);            ws.addCell(labelY);            ws.addCell(labelZ);            ws.addCell(labelAA);            ws.addCell(labelAB);            ws.addCell(labelAC);            ws.addCell(labelAD);            ws.addCell(labelAE);            ws.addCell(labelAF);            ws.addCell(labelAG);            ws.addCell(labelAH);            ws.addCell(labelAI);            ws.addCell(labelAJ);            ws.addCell(labelAK);            ws.addCell(labelAL);            ws.addCell(labelAM);            ws.addCell(labelAN);            ws.addCell(labelAO);            ws.addCell(labelAP);            ws.addCell(labelAQ);            ws.addCell(labelAR);            ws.addCell(labelAS);            ws.addCell(labelAT);            ws.addCell(labelAU);            ws.addCell(labelAV);            ws.addCell(labelAW);            ws.addCell(labelAX);            ws.addCell(labelAY);            ws.addCell(labelAZ);            ws.addCell(labelBA);            ws.addCell(labelBB);            ws.addCell(labelBC);            ws.addCell(labelBD);            ws.addCell(labelBE);            ws.addCell(labelBF);            ws.addCell(labelBG);            ws.addCell(labelBH);            ws.addCell(labelBI);            ws.addCell(labelBJ);            ws.addCell(labelBK);            ws.addCell(labelBL);            ws.addCell(labelBM);            ws.addCell(labelBN);            ws.addCell(labelBO);            ws.addCell(labelBP);            ws.addCell(labelBQ);            ws.addCell(labelBR);            ws.addCell(labelBS);            ws.addCell(labelBT);            ws.addCell(labelBU);            ws.addCell(labelBV);            ws.addCell(labelBW);            ws.addCell(labelBX);            ws.addCell(labelBY);            ws.addCell(labelBZ);            ws.addCell(labelCA);            ws.addCell(labelCB);            ws.addCell(labelCC);            ws.addCell(labelCD);            ws.addCell(labelCE);            ws.addCell(labelCF);            ws.addCell(labelCG);            ws.addCell(labelCH);            ws.addCell(labelCI);            ws.addCell(labelCJ);            ws.addCell(labelCK);            ws.addCell(labelCL);            ws.addCell(labelCM);            ws.addCell(labelCN);            String person = "", firstName = "", lastName = "";            int i = 1, j = 1;            while (ir.hasNext()) {                adb = (AddressDb) ir.next();                person = adb.getPerson();                try {                   firstName = person.substring(0,1);                   lastName = person.substring(1);                } catch (Exception e) {                }                Label labelA1 = new Label(1, j, lastName);                Label labelB1 = new Label(3, j, firstName);                Label labelC1 = new Label(5, j, adb.getCompany());                Label labelD1 = new Label(6, j, adb.getDepartment());                Label labelE1 = new Label(7, j, adb.getJob());                Label labelF1 = new Label(30, j, adb.getOperationFax());                Label labelG1 = new Label(31, j, adb.getOperationPhone());                Label labelH1 = new Label(34, j, adb.getBeepPager());                Label labelI1 = new Label(37, j, adb.getTel());                Label labelJ1 = new Label(40, j, adb.getMobile());                Label labelK1 = new Label(51, j, adb.getEmail());                j++;                ws.addCell(labelA1);                ws.addCell(labelB1);                ws.addCell(labelC1);                ws.addCell(labelD1);                ws.addCell(labelE1);                ws.addCell(labelF1);                ws.addCell(labelG1);                ws.addCell(labelH1);                ws.addCell(labelI1);                ws.addCell(labelJ1);                ws.addCell(labelK1);            }            wwb.write();            wwb.close();        } catch (Exception e) {            System.out.println(e.toString());        }    }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?