- package com.java.demo;
-
- import java.io.File;
- import java.io.IOException;
- 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.format.VerticalAlignment;
- import jxl.write.Label;
- import jxl.write.WritableCellFormat;
- import jxl.write.WritableFont;
- import jxl.write.WritableSheet;
- import jxl.write.WritableWorkbook;
- import jxl.write.WriteException;
- import jxl.write.biff.RowsExceededException;
-
- public class ExcelDemo {
-
-
- public static void main(String[] args) throws IOException, RowsExceededException, WriteException {
-
- WritableWorkbook workbook = Workbook.createWorkbook(new File("C:/ExcelDemo.xls"));
-
-
- WritableSheet sheet = workbook.createSheet("第一个Sheet", 0);
-
- sheet.setColumnView(1, 40);
- sheet.setColumnView(1, 30);
- sheet.setColumnView(2, 50);
- sheet.setColumnView(3, 20);
-
-
- sheet.getSettings().setDefaultColumnWidth(30);
-
-
- WritableFont font1 = new WritableFont(WritableFont.ARIAL,14,WritableFont.BOLD,false,UnderlineStyle.NO_UNDERLINE,Colour.RED);
-
- WritableCellFormat cellFormat1 = new WritableCellFormat(font1);
-
- cellFormat1.setBackground(Colour.BLUE_GREY);
-
- cellFormat1.setBorder(Border.ALL, BorderLineStyle.DASH_DOT);
-
- cellFormat1.setWrap(true);
-
- cellFormat1.setAlignment(Alignment.CENTRE);
-
- cellFormat1.setVerticalAlignment(VerticalAlignment.CENTRE);
-
- Label label1 = new Label(0, 0, "第一行第一个单元格(测试是否自动换行!)",cellFormat1);
- Label label2 = new Label(1, 0, "第一行第二个单元格",cellFormat1);
- Label label3 = new Label(2, 0, "第一行第三个单元格",cellFormat1);
- Label label4 = new Label(3, 0, "第一行第四个单元格",cellFormat1);
-
- sheet.addCell(label1);
- sheet.addCell(label2);
- sheet.addCell(label3);
- sheet.addCell(label4);
-
-
- WritableFont font2 = new WritableFont(WritableFont.ARIAL,14,WritableFont.NO_BOLD,false,UnderlineStyle.NO_UNDERLINE,Colour.BLUE2);
- WritableCellFormat cellFormat2 = new WritableCellFormat(font2);
- cellFormat2.setAlignment(Alignment.CENTRE);
- cellFormat2.setBackground(Colour.PINK);
- cellFormat2.setBorder(Border.ALL, BorderLineStyle.THIN);
- cellFormat2.setWrap(true);
-
-
- Label label11= new Label(0, 1, "第二行第一个单元格(测试是否自动换行!)",cellFormat2);
- Label label22 = new Label(1, 1, "第二行第二个单元格",cellFormat2);
- Label label33 = new Label(2, 1, "第二行第三个单元格",cellFormat2);
- Label label44 = new Label(3, 1, "第二行第四个单元格",cellFormat2);
-
- sheet.addCell(label11);
- sheet.addCell(label22);
- sheet.addCell(label33);
- sheet.addCell(label44);
-
-
- workbook.write();
-
- workbook.close();
- }
- }
posted @
2017-10-11 15:08
夕阳残血
阅读(
156)
评论()
编辑
收藏
举报