POI Excel行高设置
生活随笔
收集整理的這篇文章主要介紹了
POI Excel行高设置
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1.Excel行高單位概述
2. 設置Excel行高
POI中行高單位和Office Excel中行高單位是不一樣的
1. POI中的行高單位是twips(緹)
2. Office Excel行高單位是pt(磅)
3. 1pt = 20twips
4. 1px = 3/4pt
5. 1px = 15twips
3.實例
package hssf_grid;import java.io.BufferedOutputStream; import java.io.File; import java.io.FileOutputStream;import org.apache.poi.hssf.usermodel.HSSFCell; import org.apache.poi.hssf.usermodel.HSSFCellStyle; import org.apache.poi.hssf.usermodel.HSSFRow; import org.apache.poi.hssf.usermodel.HSSFSheet; import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.ss.util.WorkbookUtil;public class RowHeightTest {public static void main(String[] args) throws Exception {File file = new File("C:\\Users\\Administrator\\Desktop\\test.xls");if (file.exists()) {file.delete();}BufferedOutputStream out = null;try {out = new BufferedOutputStream(new FileOutputStream("C:\\Users\\Administrator\\Desktop\\test.xls"));exportExcel(out);} finally {out.close();}}private static void exportExcel(BufferedOutputStream out) throws Exception {HSSFWorkbook workbook = new HSSFWorkbook();// 格式化Sheet名,使其合法String safeSheetName = WorkbookUtil.createSafeSheetName("日歷");HSSFSheet sheet = workbook.createSheet(safeSheetName);sheet.setColumnWidth(0, 100*256);HSSFRow row3 = sheet.createRow(3);row3.createCell(0).setCellValue("行高16px = 12pt = 240twips");// 單位為twips(緹)row3.setHeight((short)(12*20));HSSFRow row5 = sheet.createRow(5);row5.createCell(0).setCellValue("行高32px = 24pt = 480twips");row5.setHeight((short)(24*20));HSSFRow row7 = sheet.createRow(7);row7.createCell(0).setCellValue("行高48px = 36pt = 720twips");// 單位為pt(磅)row7.setHeightInPoints(36);HSSFRow row9 = sheet.createRow(9);row9.createCell(0).setCellValue("行高64px = 48pt = 1440twips");// 單位為pt(磅)row9.setHeightInPoints(48);workbook.write(out);}}總結
以上是生活随笔為你收集整理的POI Excel行高设置的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: GraphX与GraphLab、Preg
- 下一篇: 华硕x450jn拆机_华硕X450C系列