posts - 5,  comments - 7,  trackbacks - 0
           1package test;
           2
           3import java.io.FileOutputStream;
           4import java.io.IOException;
           5
           6import org.apache.poi.hssf.usermodel.HSSFCell;
           7import org.apache.poi.hssf.usermodel.HSSFCellStyle;
           8import org.apache.poi.hssf.usermodel.HSSFFont;
           9import org.apache.poi.hssf.usermodel.HSSFPrintSetup;
          10import org.apache.poi.hssf.usermodel.HSSFRichTextString;
          11import org.apache.poi.hssf.usermodel.HSSFRow;
          12import org.apache.poi.hssf.usermodel.HSSFSheet;
          13import org.apache.poi.hssf.usermodel.HSSFWorkbook;
          14
          15public class ExcelTest {
          16
          17    public static void main(String[] args) throws IOException {
          18        
          19         // create a new file  
          20         FileOutputStream out = new FileOutputStream("D:/workbook.xls");  
          21         // create a new workbook  
          22         HSSFWorkbook wb = new HSSFWorkbook();  
          23         // create a new sheet  
          24         HSSFSheet sheet = wb.createSheet();  
          25           
          26         //2.model  
          27         HSSFRow row = sheet.createRow(2);  
          28         row.setHeightInPoints(20);  
          29         HSSFCell cell = row.createCell(2);  
          30         HSSFFont cnFont = wb.createFont();  
          31         cnFont.setFontHeightInPoints((short10);  
          32         //font.setFontName("漢儀報宋簡");  
          33         cnFont.setFontName("隸書");  
          34         HSSFCellStyle cnStyle = wb.createCellStyle();  
          35         cnStyle.setFont(cnFont);  
          36         cell.setCellStyle(cnStyle);  
          37         HSSFRichTextString richText = new HSSFRichTextString("中文字體測試");  
          38         cell.setCellValue(richText);  
          39         HSSFCell enCell = row.createCell(3);  
          40         HSSFFont enFont = wb.createFont();  
          41         enFont.setFontHeightInPoints((short10);  
          42         enFont.setFontName("Arial Black");  
          43         HSSFCellStyle enStyle = wb.createCellStyle();  
          44         enStyle.setFont(enFont);  
          45         enCell.setCellStyle(enStyle);  
          46         enCell.setCellValue(new HSSFRichTextString("English font test"));  
          47         sheet.setColumnWidth(24000);  
          48         sheet.setColumnWidth(34000);
          49         
          50         //3.output  
          51         sheet.setDisplayGridlines(false);  
          52         sheet.setPrintGridlines(false);  
          53         HSSFPrintSetup printSetup = sheet.getPrintSetup();  
          54         //A4紙
          55         printSetup.setPaperSize(HSSFPrintSetup.A4_PAPERSIZE);  
          56         wb.write(out);  
          57         out.close(); 
          58    }

          59}

          60
          posted on 2008-11-25 11:47 Vincent-chen 閱讀(2194) 評論(0)  編輯  收藏 所屬分類: POIPrint
          主站蜘蛛池模板: 金山区| 宿迁市| 乾安县| 平昌县| 安陆市| 乌苏市| 清涧县| 嵩明县| 辽宁省| 绥中县| 莲花县| 拉孜县| 法库县| 东丽区| 望江县| 尚志市| 乌拉特前旗| 明星| 平乡县| 合阳县| 马龙县| 东安县| 建瓯市| 朝阳县| 莎车县| 九龙坡区| 伊川县| 门源| 重庆市| 利津县| 论坛| 玉林市| 彭水| 咸宁市| 山西省| 平度市| 万盛区| 永胜县| 福海县| 东丰县| 射阳县|