当前位置:软件学习 > Excel >>

java通过jxl生成excel文档

Java代码 
import java.awt.BasicStroke; 
import java.awt.Color; 
import java.awt.Font; 
import java.io.File; 
import java.io.IOException; 
import java.lang.reflect.Field; 
import java.util.ArrayList; 
import java.util.Calendar; 
import java.util.Date; 
import java.sql.SQLException; 
import java.text.DecimalFormat; 
import java.text.NumberFormat; 
import java.text.ParseException; 
import java.text.SimpleDateFormat; 
import java.util.List; 
 
import sun.security.krb5.internal.crypto.c; 
 
import com.sun.java_cup.internal.internal_error; 
 
import jxl.Workbook; 
import jxl.format.Alignment; 
import jxl.format.Colour; 
import jxl.format.UnderlineStyle; 
import jxl.write.Label; 
import jxl.write.Number; 
import jxl.write.NumberFormats; 
import jxl.write.WritableCell; 
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; 
 
public class ExcelReport { 
     
    private static WritableCellFormat wcf_value;//表格数据样式 
    private static WritableCellFormat wcf_value_left; 
    private static WritableCellFormat wcf_key;//表头样式 
    private static WritableCellFormat wcf_name_left;//表名样式 
    private static WritableCellFormat wcf_name_right;//表名样式 
    private static WritableCellFormat wcf_name_center;//表名样式 
    private static WritableCellFormat wcf_title;//页名称样式  
    private static WritableCellFormat wcf_percent_float; 
     
    private static final int MAXCOLS=7;//表名称样式 
     
    static{ 
        try { 
            //WritableFont wf_value = new WritableFont(WritableFont.ARIAL,10,WritableFont.NO_BOLD); 
            WritableFont wf_key = new jxl.write.WritableFont(WritableFont.createFont("微软雅黑"), 10,WritableFont.BOLD); 
            WritableFont wf_value = new jxl.write.WritableFont(WritableFont.createFont("微软雅黑"), 10,WritableFont.NO_BOLD); 
            wcf_value = new WritableCellFormat(wf_value); 
            wcf_value.setAlignment(jxl.format.Alignment.CENTRE); 
            wcf_value.setVerticalAlignment(jxl.format.VerticalAlignment.CENTRE); 
            wcf_value.setBorder(jxl.format.Border.ALL, jxl.format.BorderLineStyle.THIN); 
             
            wcf_value_left = new WritableCellFormat(wf_value); 
            wcf_value_left.setAlignment(jxl.format.Alignment.LEFT); 
            wcf_value_left.setVerticalAlignment(jxl.format.VerticalAlignment.CENTRE); 
            wcf_value_left.setBorder(jxl.format.Border.ALL, jxl.format.BorderLineStyle.THIN); 
            wcf_value_left.setWrap(true); 
             
            //WritableFont wf_key = new WritableFont(WritableFont.ARIAL,10,WritableFont.BOLD); 
            wcf_key = new WritableCellFormat(wf_key); 
            wcf_key.setAlignment(jxl.format.Alignment.CENTRE); 
            wcf_key.setBorder(jxl.format.Border.ALL, jxl.format.BorderLineStyle.THIN); 
             
            wcf_name_left = new WritableCellFormat(wf_key); 
            wcf_name_left.setAlignment(Alignment.LEFT); 
            wcf_name_left.setVerticalAlignment(jxl.format.VerticalAlignment.CENTRE); 
             
            wcf_name_right = new WritableCellFormat(wf_key); 
            wcf_name_right.setAlignment(Alignment.RIGHT); 
             
            wcf_name_center = new WritableCellFormat(wf_key); 
            wcf_name_center.setAlignment(Alignment.CENTRE); 
             
            jxl.write.NumberFormat wf_percent_float = new jxl.write.NumberFormat("0.00");  
            wcf_percent_float= new jxl.write.WritableCellFormat(wf_value,wf_percent_float); 
            wcf_percent_float.setAlignment(jxl.format.Alignment.CENTRE); 
            wcf_percent_float.setVerticalAlignment(jxl.format.VerticalAlignment.CENTRE); 
            wcf_percent_float.setBorder(jxl.format.Border.ALL, jxl.format.BorderLineStyle.THIN); 
             
             
            //WritableFont wf_title = new WritableFont(WritableFont.ARIAL,14,WritableFont.BOLD); 
            WritableFont wf_title = new jxl.write.WritableFont(WritableFont.createFont("微软雅黑"), 14,WritableFont.BOLD); 
            wcf_title = new WritableCellFormat(wf_title); 
            wcf_title.setAlignment(Alignment.CENTRE); 
             
  &

补充:软件开发 , Java ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,