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

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

Jxl操作Excel設置背景、字體顏色、對齊方式、列的寬度(一)

2019-11-10 19:06:08
字體:
來源:轉載
供稿:網友
import java.io.File;import java.io.IOException;import java.net.URL;import jxl.Workbook;import jxl.format.UnderlineStyle;import jxl.write.Label;import jxl.write.WritableCellFormat;import jxl.write.WritableFont;import jxl.write.WritableHyperlink;import jxl.write.WritableImage;import jxl.write.WritableSheet;import jxl.write.WritableWorkbook;import jxl.write.WriteException;import jxl.write.biff.RowsExceededException;public class TestExl {public static void main(String args[]) throws IOException,    RowsExceededException, WriteException {   WritableWorkbook book = Workbook.createWorkbook(new File("f://aa.xls")); // 第一步   /**   * 定義與設置Sheet   */   WritableSheet sheet = book.createSheet("sheet", 0); // 創建Sheet   sheet.setColumnView(0, 30); // 設置列的寬度   sheet.setColumnView(1, 30); // 設置列的寬度   sheet.setColumnView(2, 30); // 設置列的寬度   sheet.setRowView(6, 1000); // 設置行的高度   sheet.setRowView(4, 1000); // 設置行的高度   sheet.setRowView(5, 1000); // 設置行的高度      /**   * 定義單元格樣式   */   WritableFont wf = new WritableFont(WritableFont.ARIAL, 15,     WritableFont.BOLD, false, UnderlineStyle.NO_UNDERLINE,     jxl.format.Colour.CORAL); // 定義格式 字體 下劃線 斜體 粗體 顏色   WritableCellFormat wcf = new WritableCellFormat(wf); // 單元格定義   wcf.setBackground(jxl.format.Colour.BLACK); // 設置單元格的背景顏色   wcf.setAlignment(jxl.format.Alignment.CENTRE); // 設置對齊方式   /**   * 使用樣式的單元格   */   sheet.addCell(new Label(0, 0, "郵箱asasasasa", wcf)); // 普通的帶有定義格式的單元格   sheet.addCell(new Label(1, 0, "動作asasasasa", wcf));   sheet.addCell(new Label(2, 0, "時間asasasasa", wcf));   sheet.addCell(new Label(0, 1, "qhcgx@sina.com"));   sheet.addCell(new Label(1, 1, "action"));   sheet.addCell(new Label(2, 1, "time"));   /**   * Excel合并單元格   */   sheet.addCell(new Label(4, 0, "合并單元格", wcf)); // 合并單元格   sheet.addCell(new Label(4, 1, "測試1"));   sheet.addCell(new Label(5, 1, "測試2"));   sheet.addCell(new Label(6, 1, "測試3"));   sheet.mergeCells(4, 0, 6, 0); // 合并單元格   /**   * excel圖片   */   sheet.addCell(new Label(0, 3, "展示圖片 jxl只支持png格式的", wcf)); // 展示圖片標題   sheet.mergeCells(0, 3, 3, 3); // 合并圖片標題單元格   File file = new File("f://1.png"); // 獲得圖片   WritableImage image = new WritableImage(0, 4, 3, 3, file); // 設置圖片顯示位置                  // 4,4代表圖片的高和寬占4個單元格   sheet.addImage(image); // 加載圖片   /**   * excel鏈接   */   sheet.addCell(new Label(0, 8, "excel鏈接測試", wcf)); // 鏈接標題   sheet.mergeCells(0, 8, 2, 8);   WritableHyperlink link = new WritableHyperlink(0, 9, new URL(     "http://www.google.com"));   link.setDescription("鏈接使用 鏈接到Google");   sheet.mergeCells(0, 9, 1, 9);   sheet.addHyperlink(link);   book.write();   book.close();}}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 沙湾县| 色达县| 康保县| 贡嘎县| 商都县| 三明市| 申扎县| 贺兰县| 铅山县| 秦安县| 宜阳县| 福海县| 那曲县| 定远县| 东方市| 万宁市| 武清区| 宁阳县| 河池市| 梁平县| 达州市| 金乡县| 青岛市| 新建县| 板桥市| 古丈县| 顺义区| 耒阳市| 康马县| 贵定县| 镇沅| 湘乡市| 枞阳县| 霞浦县| 许昌县| 淮北市| 呼图壁县| 内黄县| 美姑县| 惠水县| 年辖:市辖区|