国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

java生成excel

2019-11-14 15:28:22
字體:
來源:轉載
供稿:網友
package test.poi;import java.io.File;import java.io.FileOutputStream;import java.io.OutputStream;import java.util.ArrayList;import java.util.List;import java.util.Map;import jxl.Workbook;import jxl.format.Alignment;import jxl.format.Border;import jxl.format.BorderLineStyle;import jxl.format.Colour;import jxl.format.UnderlineStyle;import jxl.write.Label;import jxl.write.WritableCellFormat;import jxl.write.WritableFont;import jxl.write.WritableSheet;import jxl.write.WritableWorkbook;public class createExcel {    public static void main(String[] args) {        createExcel();    }    public static void createExcel() {        try {            File file = new File("f://text.xls");            OutputStream os = new FileOutputStream(file);            WritableWorkbook wwb = Workbook.createWorkbook(os);            WritableSheet ws = wwb.createSheet("sheet1", 0);            //根據月份獲取對象集            List<Map<String,String>> list=new ArrayList<Map<String,String>>();            //設置單元格格式            WritableFont wf = new WritableFont(WritableFont.ARIAL, 11,WritableFont.BOLD, false, UnderlineStyle.NO_UNDERLINE,Colour.WHITE);            WritableCellFormat cellFormat = new WritableCellFormat(wf);            cellFormat.setBorder(Border.ALL, BorderLineStyle.THIN,Colour.BLUE_GREY);            cellFormat.setAlignment(Alignment.CENTRE);            cellFormat.setBackground(Colour.BLUE);            //第一行            Label label = new Label(0, 0, "序號");            label.setCellFormat(cellFormat);            ws.addCell(label);            label = new Label(1, 0, "姓名 ");            label.setCellFormat(cellFormat);            ws.addCell(label);            //合并單元格            ws.mergeCells(2, 0, 3, 0);            label = new Label(2, 0, "合并單元格");            label.setCellFormat(cellFormat);            ws.addCell(label);                                //第二行            label = new Label(0, 1, "1");            ws.addCell(label);            label = new Label(1, 1, "姓名");            ws.addCell(label);            label = new Label(2, 1, "合并1");            ws.addCell(label);            label = new Label(3, 1, "合并2");            ws.addCell(label);            //第三行            label = new Label(0, 2, "2");            ws.addCell(label);            label = new Label(1, 2, "姓名");            ws.addCell(label);            label = new Label(2, 2, "合并1");            ws.addCell(label);            label = new Label(3, 2, "合并2");            ws.addCell(label);            //添加數據            wwb.write();            wwb.close();            System.out.);        } catch (Exception e) {            System.out.println("生成信息表(Excel格式)時出錯:");            e.printStackTrace();        }    }}

操作excel需用到jxl.jar這個jar包。


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 高雄县| 怀远县| 灵武市| 彰化县| 哈巴河县| 马山县| 固阳县| 长寿区| 达尔| 凤城市| 合山市| 封开县| 邻水| 白河县| 凤冈县| 五大连池市| 合肥市| 扎鲁特旗| 航空| 榆社县| 丰都县| 昌黎县| 封开县| 田林县| 同心县| 新竹县| 长丰县| 苏尼特右旗| 洛隆县| 三原县| 丁青县| 庆元县| 安多县| 仙居县| 酒泉市| 始兴县| 明光市| 孟州市| 洛川县| 开江县| 象州县|