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

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

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

2019-11-10 18:46:26
字體:
來源:轉載
供稿:網友
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();}}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 珠海市| 维西| 平凉市| 周口市| 清水县| 海淀区| 本溪| 巫山县| 曲水县| 鹰潭市| 万盛区| 城步| 墨玉县| 祁连县| 华容县| 彭州市| 长兴县| 深泽县| 得荣县| 崇义县| 仁怀市| 乾安县| 长白| 怀柔区| 涞源县| 泰和县| 尉氏县| 措美县| 营口市| 柳河县| 德兴市| 子洲县| 时尚| 札达县| 海林市| 运城市| 长丰县| 道真| 霞浦县| 卢氏县| 平果县|