使用POI生成Excel文档并设置打印样式

http://blog.csdn.net/giianhui/article/details/7935090

package test;

import java.io.FileOutputStream;
import java.io.IOException;

import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFFont;
import org.apache.poi.hssf.usermodel.HSSFPrintSetup;
import org.apache.poi.hssf.usermodel.HSSFRichTextString;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;

public class ExcelTest {

    public static void main(String[] args) throws IOException {
        
         // create a new file  
         FileOutputStream out = new FileOutputStream("D:/workbook.xls");  
         // create a new workbook  
         HSSFWorkbook wb = new HSSFWorkbook();  
         // create a new sheet  
         HSSFSheet sheet = wb.createSheet();  
           
         //2.model  
         HSSFRow row = sheet.createRow(2);  
         row.setHeightInPoints(20);  
         HSSFCell cell = row.createCell(2);  
         HSSFFont cnFont = wb.createFont();  
         cnFont.setFontHeightInPoints((short) 10);  
         //font.setFontName("汉仪报宋简");  
         cnFont.setFontName("隶书");  
         HSSFCellStyle cnStyle = wb.createCellStyle();  
         cnStyle.setFont(cnFont);  
         cell.setCellStyle(cnStyle);  
         HSSFRichTextString richText = new HSSFRichTextString("中文字体测试");  
         cell.setCellValue(richText);  
         HSSFCell enCell = row.createCell(3);  
         HSSFFont enFont = wb.createFont();  
         enFont.setFontHeightInPoints((short) 10);  
         enFont.setFontName("Arial Black");  
         HSSFCellStyle enStyle = wb.createCellStyle();  
         enStyle.setFont(enFont);  
         enCell.setCellStyle(enStyle);  
         enCell.setCellValue(new HSSFRichTextString("English font test"));  
         sheet.setColumnWidth(2, 4000);  
         sheet.setColumnWidth(3, 4000);
         
         //3.output  
         sheet.setDisplayGridlines(false);  
         sheet.setPrintGridlines(false);  
         HSSFPrintSetup printSetup = sheet.getPrintSetup();  
         //A4纸
         printSetup.setPaperSize(HSSFPrintSetup.A4_PAPERSIZE);  
         wb.write(out);  
         out.close(); 
    }
}

 

 

HSSFSheet fromsheet = wb.getSheetAt(0); //模版页
            for(int num=0;num

 

你可能感兴趣的:(Java基础方法,导出excel打印样式问题)