jxl操作excel樣式設置


  1. WritableFont headFont = new WritableFont(WritableFont.TIMES, 14,WritableFont.BOLD);   
  2. //設置標題,字號14,加粗  
  3.   
  4.     
  5. <P>WritableFont countents = new WritableFont(WritableFont.TIMES,12); // 設置單元格內容,字號12  
  6. WritableCellFormat cell = new WritableCellFormat(contentFont);  
  7.   
  8. cell.setAlignment(jxl.format.Alignment.CENTRE);// 單元格內容水平居中  
  9. cell.setVerticalAlignment(jxl.format.VerticalAlignment.CENTRE);// 單元格內容垂直居中  
  10.   
  11. cell.setBorder(Border.ALL, BorderLineStyle.THIN,jxl.format.Colour.BLACK); // 邊框  
  12. // Border.ALL:上下左右都設置邊框; BorderLineStyle.THIN: 細邊框; jxl.format.Colour.BLACK: 黑顏色   
  13.   
  14. cell.setWrap(true);//是否換行   
  15.    
  16.    
  17.   
  18.   
  19. WritableSheet sheet = book.createSheet("公文檢索", 0); //創建一個新sheet  
  20. sheet.setColumnView(0, 80); //第1列寬  
  21. sheet.setColumnView(1, 80); //第2列寬  
  22.    
  23.   
  24. sheet.setRowView(i+1, 400);//某行的行高,一般用在循環中  
  25.   
  26. //合並單元格  
  27. sheet.mergeCells(3,0,4,0);//(列,行,列,行)  
  28.    
  29.   
  30. //設置頁邊距(0.1d=0.26cm)  
  31. sheet.getSettings().setBottomMargin(0.7d);  
  32. sheet.getSettings().setTopMargin(0.7d);  
  33. sheet.getSettings().setLeftMargin(0.75d);  
  34. sheet.getSettings().setRightMargin(0.75d);  
  35.   
  36.   
  37. //設置打印方向為 橫向,不設置為縱向  
  38.   
  39. sheet.setPageSetup(PageOrientation.LANDSCAPE.LANDSCAPE,PaperSize.A4,0.5d,0.5d);  
  40.    
  41.   
  42. //設置頁碼,3個參數位置分別對應:左邊、中間、右邊  
  43.  sheet.setFooter("", "&P", "");  
  44.   
  45. //設置凍結單元格,下拉時第一列固定  
  46. sheet.getSettings().setVerticalFreeze(1);   
  47.    
  48.   
  49. //設置是否顯示行數列數編號  
  50. sheet.getSettings().setPrintHeaders(true);  

 

注:轉載自https://xqqing79.iteye.com/blog/1454326


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM