首页 > 学院 > 开发设计 > 正文

Jxl鎿嶄綔Excel璁剧疆鑳屾櫙銆佸瓧浣撻鑹层€佸榻愭柟寮忋€佸垪鐨勫搴︼紙浜岋級

2019-11-10 19:05:53
字体:
来源:转载
供稿:网友
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;    /**  * 瀵煎嚭Excel瀹炰緥:  * @author Administrator  *  */  public class ExcelDemo {        /**      * @param args      * @throws IOException       * @throws WriteException       * @throws RowsExceededException       */      public static void main(String[] args) throws IOException, RowsExceededException, WriteException {          //鍒涘缓Excel宸ヤ綔绨?          WritableWorkbook workbook = Workbook.createWorkbook(new File("C:/ExcelDemo.xls"));            //鍒涘缓Excel鐢靛瓙钖?          WritableSheet sheet = workbook.createSheet("绗竴涓猄heet", 0);          //鍒嗗埆缁?,3,4鍒楄缃笉鍚岀殑瀹藉害;          sheet.setColumnView(1, 40);          sheet.setColumnView(1, 30);          sheet.setColumnView(2, 50);          sheet.setColumnView(3, 20);            //缁檚heet鐢靛瓙鐗堜腑鎵€鏈夌殑鍒楄缃粯璁ょ殑鍒楃殑瀹藉害;          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, "绗竴琛岀涓€涓崟鍏?#26684;(娴嬭瘯鏄惁鑷姩鎹㈣!)",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, "绗簩琛岀涓€涓崟鍏?#26684;(娴嬭瘯鏄惁鑷姩鎹㈣!)",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);            //鍐欏叆Excel琛?#26684;涓?          workbook.write();          //鍏抽棴娴?          workbook.close();      }  }

缁撴灉濡備笅锛?/span>


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表