Bugzilla Bug Xml导出为excel

下面是我做一个程序:用java语言将Bugzilla系统的Bug Xml转化为excel文件。

 

用java处理excel文件的第三方包: pio-3.7-20101029.jar

 

主要代码:

 

读取Xml:

 

package com.tzp.bugzilla;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;



public class ReadXml {

	
	
	public List<Bug> GetBugList(String xmlPath) throws Exception{
		
		DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
		DocumentBuilder builder;
		builder = factory.newDocumentBuilder();
		
		File file=new File(xmlPath);
		
		//boolean b=file.exists(); 
		
		//System.out.println(b); 
		
		Document document = builder.parse(file);
		
		Element e1=document.getDocumentElement();
		
		NodeList nodeList=e1.getChildNodes();
		
		List<Bug> bugList=new ArrayList<Bug>();
		
		for(int i=0;i<nodeList.getLength();i++){
			Node bugNode=nodeList.item(i);
			if("bug".equalsIgnoreCase(bugNode.getNodeName())){
				Element bugEle=(Element)bugNode;
				Bug bug=GetBugInfor(bugEle);
				bugList.add(bug);
			};
		}
				
		return bugList;
	}
	
	public Bug GetBugInfor(Element e){
		
		Bug bug =new Bug();
		
		bug.setBug_ID(e.getElementsByTagName("bug_id").item(0).getTextContent());
		bug.setBug_opened_time(e.getElementsByTagName("creation_ts").item(0).getTextContent());
		bug.setBug_summary(e.getElementsByTagName("short_desc").item(0).getTextContent());
		bug.setBug_changed_time(e.getElementsByTagName("delta_ts").item(0).getTextContent());
		bug.setBug_product(e.getElementsByTagName("product").item(0).getTextContent());
		bug.setBug_comp(e.getElementsByTagName("component").item(0).getTextContent());
		bug.setBug_version(e.getElementsByTagName("version").item(0).getTextContent());
		bug.setBug_hardware(e.getElementsByTagName("rep_platform").item(0).getTextContent());
		bug.setBug_OS(e.getElementsByTagName("op_sys").item(0).getTextContent());
		bug.setBug_status(e.getElementsByTagName("bug_status").item(0).getTextContent());
		bug.setBug_priority(e.getElementsByTagName("priority").item(0).getTextContent());
		bug.setBug_severity(e.getElementsByTagName("bug_severity").item(0).getTextContent());
		bug.setBug_reporter(e.getElementsByTagName("reporter").item(0).getTextContent());		
		bug.setBug_reporter_realname(((Element)e.getElementsByTagName("reporter").item(0)).getAttribute("name"));	
		bug.setBug_assign(e.getElementsByTagName("assigned_to").item(0).getTextContent());
		bug.setBug_assign_realname(((Element)e.getElementsByTagName("assigned_to").item(0)).getAttribute("name"));
		
		//bug.setBug_frequency(e.getElementsByTagName("cf_frequency").item(0).getTextContent());
		
		if(e.getElementsByTagName("cf_language").getLength()==0){
			bug.setBug_language("");
		}else{
			bug.setBug_language(e.getElementsByTagName("cf_language").item(0).getTextContent());
		}
		if(e.getElementsByTagName("cf_frequency").getLength()==0){
			bug.setBug_frequency("");
		}else{
			bug.setBug_frequency(e.getElementsByTagName("cf_frequency").item(0).getTextContent());			
		}
		
		if(e.getElementsByTagName("resolution").getLength()==0){
			bug.setBug_resolution("");
		}else{
			bug.setBug_resolution(e.getElementsByTagName("resolution").item(0).getTextContent());
		}
		
		//读取desc 
		NodeList descList=e.getElementsByTagName("long_desc");
		String comments="";
		String desc="";
		for(int i=0;i<descList.getLength();i++){
			Element descEle=(Element)descList.item(i);
			//将第一个desc设置为Reproduce steps and test results,将其它desc设置为comments
			if(i==0){
				desc=descEle.getElementsByTagName("thetext").item(0).getTextContent(); 
			}else{
				comments=comments +descEle.getElementsByTagName("bug_when").item(0).getTextContent()+" "
				+((Element)descEle.getElementsByTagName("who").item(0)).getAttribute("name")+" : \n"
				+descEle.getElementsByTagName("thetext").item(0).getTextContent()+"\n";
			}
		}	
		bug.setBug_desc(desc);
		bug.setBug_comments(comments);
					
		return bug;
	}
	
	public void PrintBugList(List<Bug> bugList){
		for(Bug bug:bugList){
			System.out.println(bug);
		}
	}
}
写入Excel文件代码:
package com.tzp.bugzilla;
import java.io.FileOutputStream;
import java.util.List;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFFont;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.util.HSSFColor;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.Font;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.util.CellRangeAddress;
public class WriteToExcel {
 private Workbook wb=null;
 private Sheet sh=null;
 private CellStyle defStyle=null;
 private CellStyle defStyle1=null;
 private Font redFont=null;
 private Font blackFont=null;
 
 private int ID=0;
 private int id_Id=0;
 private int product_Id=0;
 private int version_Id=0;
 private int assign_Id=0;
 private int severity_Id=0;
 private int hardware_Id=0;
 private int OS_Id=0;
 private int priority_Id=0;
 private int frequency_Id=0;
 private int language_Id=0;
 private int reopen_version_Id=0;
 private int close_version_Id=0;
 private int summary_Id=0;
 private int desc_Id=0;
 private int comments_Id=0;
 private int opened_time_Id=0;
 private int changed_time_Id=0;
 private int comp_Id=0;
 private int status_Id=0;
 private int assign_realname_Id=0;
 private int reporter_Id=0;
 private int reporter_realname_Id=0;
 private int resolution_id=0;
 
 public void writeBug(List<Bug> list,String strPath,SelectInfor sInfor) throws Exception{
  
  //set excel style , width ,titles
  writeTitle(sInfor);
  
  int intNum=2;
  
  for(int i=0;i<list.size();i++){
   
   Bug bug=list.get(i);
   //定义sheet的列默认style:水平居中,垂直居中,画出边框线
   defStyle=wb.createCellStyle();
   defStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
   defStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);
   defStyle.setWrapText(true);//自动换行
   
   defStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN);
   defStyle.setBottomBorderColor(HSSFColor.BLACK.index);
   defStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN);
   defStyle.setLeftBorderColor(HSSFColor.BLACK.index);
   defStyle.setBorderRight(HSSFCellStyle.BORDER_THIN);
   defStyle.setRightBorderColor(HSSFColor.BLACK.index);
   defStyle.setBorderTop(HSSFCellStyle.BORDER_THIN);
   defStyle.setTopBorderColor(HSSFColor.BLACK.index);  
   
   //定义sheet的列默认style:水平靠左,垂直居中,画出边框线
   defStyle1=wb.createCellStyle();
   defStyle1.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
   defStyle1.setAlignment(HSSFCellStyle.ALIGN_LEFT);
   defStyle1.setWrapText(true);//自动换行
   
   defStyle1.setBorderBottom(HSSFCellStyle.BORDER_THIN);
   defStyle1.setBottomBorderColor(HSSFColor.BLACK.index);
   defStyle1.setBorderLeft(HSSFCellStyle.BORDER_THIN);
   defStyle1.setLeftBorderColor(HSSFColor.BLACK.index);
   defStyle1.setBorderRight(HSSFCellStyle.BORDER_THIN);
   defStyle1.setRightBorderColor(HSSFColor.BLACK.index);
   defStyle1.setBorderTop(HSSFCellStyle.BORDER_THIN);
   defStyle1.setTopBorderColor(HSSFColor.BLACK.index);
   
   //判断是否为critical bug 和blocker bug,用红色字体
   if(bug.getBug_severity().equalsIgnoreCase("critical") || bug.getBug_severity().equalsIgnoreCase("blocker")){
    defStyle.setFont(redFont);
    defStyle1.setFont(redFont);
    //System.out.println("*******");
   }else{
    defStyle.setFont(blackFont);
    defStyle1.setFont(blackFont);
    //System.out.println("++++++");
   }
   
   Row row=sh.createRow(intNum);
   if(sInfor.isId()){
    Cell cellId=row.createCell(this.id_Id);
    cellId.setCellValue(bug.getBug_ID());
    cellId.setCellStyle(defStyle);
   }
   if(sInfor.isStatus()){
    Cell cellStatus=row.createCell(this.status_Id);
    cellStatus.setCellValue(bug.getBug_status());
    cellStatus.setCellStyle(defStyle);
   }
   if(sInfor.isResolution()){
    Cell cellStatus=row.createCell(this.resolution_id);
    cellStatus.setCellValue(bug.getBug_resolution());
    cellStatus.setCellStyle(defStyle);
   }
   if(sInfor.isPriority()){
    Cell cellPriority=row.createCell(this.priority_Id);
    cellPriority.setCellValue(bug.getBug_priority());
    cellPriority.setCellStyle(defStyle);
   }
   if(sInfor.isSeverity()){
    Cell cellSeverity=row.createCell(this.severity_Id);
    cellSeverity.setCellValue(bug.getBug_severity());
    cellSeverity.setCellStyle(defStyle);
   }
   if(sInfor.isProduct()){
    Cell cellProduct=row.createCell(this.product_Id);
    cellProduct.setCellValue(bug.getBug_product());
    cellProduct.setCellStyle(defStyle);
   }
   if(sInfor.isOS()){
    Cell cellOS=row.createCell(this.OS_Id);
    cellOS.setCellValue(bug.getBug_OS());
    cellOS.setCellStyle(defStyle);
   }
   if(sInfor.isHardware()){
    Cell cellHardware=row.createCell(this.hardware_Id);
    cellHardware.setCellValue(bug.getBug_hardware());
    cellHardware.setCellStyle(defStyle);
   }
   if(sInfor.isComp()){
    Cell cellComp=row.createCell(this.comp_Id);
    cellComp.setCellValue(bug.getBug_comp());
    cellComp.setCellStyle(defStyle);
   }
   if(sInfor.isSummary()){
    Cell cellSummary=row.createCell(this.summary_Id);
    cellSummary.setCellValue(bug.getBug_summary());
    cellSummary.setCellStyle(defStyle1);
   }
   if(sInfor.isDesc()){
    Cell cellDesc=row.createCell(this.desc_Id);
    cellDesc.setCellValue(bug.getBug_desc());
    cellDesc.setCellStyle(defStyle1);
   }
   if(sInfor.isFrequency()){
    Cell cellFrequency=row.createCell(this.frequency_Id);
    cellFrequency.setCellValue(bug.getBug_frequency());
    cellFrequency.setCellStyle(defStyle);
   }
   if(sInfor.isVersion()){
    Cell cellVersion=row.createCell(this.version_Id);
    cellVersion.setCellValue(bug.getBug_version());
    cellVersion.setCellStyle(defStyle);
   }
   if(sInfor.isLanguage()){
    Cell cellLanguage=row.createCell(this.language_Id);
    cellLanguage.setCellValue(bug.getBug_language());
    cellLanguage.setCellStyle(defStyle);
   }
   if(sInfor.isReporter_realname()){
    Cell cellReporterRealName=row.createCell(this.reporter_realname_Id);
    cellReporterRealName.setCellValue(bug.getBug_reporter_realname());
    cellReporterRealName.setCellStyle(defStyle);
   }
   if(sInfor.isOpened_time()){
    Cell cellOpened=row.createCell(this.opened_time_Id);
    cellOpened.setCellValue(bug.getBug_opened_time());
    cellOpened.setCellStyle(defStyle);
   }
   if(sInfor.isReporter()){
    Cell cellReporter=row.createCell(this.reporter_Id);
    cellReporter.setCellValue(bug.getBug_reporter());
    cellReporter.setCellStyle(defStyle);
   }
   if(sInfor.isAssign_realname()){
    Cell cellAssignRealName=row.createCell(this.assign_realname_Id);
    cellAssignRealName.setCellValue(bug.getBug_assign_realname());
    cellAssignRealName.setCellStyle(defStyle);
   }
   if(sInfor.isAssign()){
    Cell cellAssign=row.createCell(this.assign_Id);
    cellAssign.setCellValue(bug.getBug_assign());
    cellAssign.setCellStyle(defStyle);
   }
   if(sInfor.isChanged_time()){
    Cell cellChanged=row.createCell(this.changed_time_Id);
    cellChanged.setCellValue(bug.getBug_changed_time());
    cellChanged.setCellStyle(defStyle);
   }
   if(sInfor.isComments()){
    Cell cellComments=row.createCell(this.comments_Id);
    cellComments.setCellValue(bug.getBug_comments());
    cellComments.setCellStyle(defStyle1);
   }
   if(sInfor.isReopen_version()){
    Cell cellReopenVersion=row.createCell(this.reopen_version_Id);
    cellReopenVersion.setCellValue(bug.getBug_reopen_version());
    cellReopenVersion.setCellStyle(defStyle);
   }
   if(sInfor.isClose_version()){
    Cell cellClosed=row.createCell(this.close_version_Id);
    cellClosed.setCellValue(bug.getBug_close_version());
    cellClosed.setCellStyle(defStyle);
   }
   
      intNum++;
  }
  
  //output excel file
  OutputExcel(strPath);
 }
 
 
 public void writeTitle(SelectInfor sInfor){
  
  //new excel
  wb=new HSSFWorkbook(); 
  //new sheet
  sh=wb.createSheet();
  //set sheet name
  wb.setSheetName(0, "Bug List");
  
  //定义red font
  redFont=wb.createFont();
  redFont.setColor(HSSFColor.RED.index);
  
  //define black font
  blackFont=wb.createFont();
  blackFont.setColor(HSSFColor.BLACK.index);
  /*
  //定义sheet的列默认style:水平居中,垂直居中,画出边框线
  defStyle=wb.createCellStyle();
  defStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
  defStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);
  defStyle.setWrapText(true);//自动换行
  
  defStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN);
  defStyle.setBottomBorderColor(HSSFColor.BLACK.index);
  defStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN);
  defStyle.setLeftBorderColor(HSSFColor.BLACK.index);
  defStyle.setBorderRight(HSSFCellStyle.BORDER_THIN);
  defStyle.setRightBorderColor(HSSFColor.BLACK.index);
  defStyle.setBorderTop(HSSFCellStyle.BORDER_THIN);
  defStyle.setTopBorderColor(HSSFColor.BLACK.index);  
  
  //定义sheet的列默认style:水平靠左,垂直居中,画出边框线
  defStyle1=wb.createCellStyle();
  defStyle1.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
  defStyle1.setAlignment(HSSFCellStyle.ALIGN_LEFT);
  defStyle1.setWrapText(true);//自动换行
  
  defStyle1.setBorderBottom(HSSFCellStyle.BORDER_THIN);
  defStyle1.setBottomBorderColor(HSSFColor.BLACK.index);
  defStyle1.setBorderLeft(HSSFCellStyle.BORDER_THIN);
  defStyle1.setLeftBorderColor(HSSFColor.BLACK.index);
  defStyle1.setBorderRight(HSSFCellStyle.BORDER_THIN);
  defStyle1.setRightBorderColor(HSSFColor.BLACK.index);
  defStyle1.setBorderTop(HSSFCellStyle.BORDER_THIN);
  defStyle1.setTopBorderColor(HSSFColor.BLACK.index);
  */
  
  //new title row
  Row row0=sh.createRow(0);
  row0.setHeightInPoints(35);
  Cell cellTitle=row0.createCell(0);
  cellTitle.setCellValue("Bug List Report");
  
  //定义title style
  CellStyle titleStyle=wb.createCellStyle();
  titleStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
  titleStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);
  
  titleStyle.setFillForegroundColor(HSSFColor.GREEN.index);
  titleStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
  titleStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN);
  titleStyle.setBottomBorderColor(HSSFColor.BLACK.index);
  titleStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN);
  titleStyle.setLeftBorderColor(HSSFColor.BLACK.index);
  titleStyle.setBorderRight(HSSFCellStyle.BORDER_THIN);
  titleStyle.setRightBorderColor(HSSFColor.BLACK.index);
  titleStyle.setBorderTop(HSSFCellStyle.BORDER_THIN);
  titleStyle.setTopBorderColor(HSSFColor.BLACK.index);  
  
  Font titleFont=wb.createFont();
  titleFont.setFontHeightInPoints((short)16);
  titleFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
  titleStyle.setFont(titleFont);
  //设置Title row 的style
  cellTitle.setCellStyle(titleStyle);
  
  //设第2行的style
  CellStyle rowTitleStyle=wb.createCellStyle();
  rowTitleStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);//垂直居中
  rowTitleStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);//水平居中
  //设置背景颜色为浅橙色
  rowTitleStyle.setFillForegroundColor(HSSFColor.LIGHT_ORANGE.index);
  rowTitleStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
    
  rowTitleStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN);
  rowTitleStyle.setBottomBorderColor(HSSFColor.BLACK.index);
  rowTitleStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN);
  rowTitleStyle.setLeftBorderColor(HSSFColor.BLACK.index);
  rowTitleStyle.setBorderRight(HSSFCellStyle.BORDER_THIN);
  rowTitleStyle.setRightBorderColor(HSSFColor.BLACK.index);
  rowTitleStyle.setBorderTop(HSSFCellStyle.BORDER_THIN);
  rowTitleStyle.setTopBorderColor(HSSFColor.BLACK.index);
  
  Font rowTitleFont=wb.createFont();
  rowTitleFont.setFontHeightInPoints((short)10);  //字体10号
  rowTitleFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);//加粗
  
  rowTitleStyle.setFont(rowTitleFont);
  
  //new second row
  Row row=sh.createRow(1);
  row.setHeightInPoints(25);
  //是否有选择ID
  if(sInfor.isId()){  
   this.id_Id=ID;
   sh.setColumnWidth(this.id_Id, 8*256);
   // new Bug ID cell
   Cell cellId=row.createCell(id_Id);
   cellId.setCellValue("Bug ID");
   cellId.setCellStyle(rowTitleStyle);
   ID++;
  }
  if(sInfor.isStatus()){
   this.status_Id=ID;
   sh.setColumnWidth(this.status_Id, 12*256);
   // new Status cell
   Cell cellStatus=row.createCell(status_Id);
   cellStatus.setCellValue("Status");
   cellStatus.setCellStyle(rowTitleStyle);
   ID++;
  }
  if(sInfor.isResolution()){
   this.resolution_id=ID;
   sh.setColumnWidth(this.resolution_id, 12*256);
   // new Status cell
   Cell cellStatus=row.createCell(resolution_id);
   cellStatus.setCellValue("Resolution");
   cellStatus.setCellStyle(rowTitleStyle);
   ID++;
  }
  if(sInfor.isPriority()){
   this.priority_Id=ID;
   sh.setColumnWidth(this.priority_Id, 10*256);
   // new Priority cell
   Cell cellPriority=row.createCell(priority_Id);
   cellPriority.setCellValue("Priority");
   cellPriority.setCellStyle(rowTitleStyle);
   ID++;
  }
  if(sInfor.isSeverity()){
   this.severity_Id=ID;
   sh.setColumnWidth(this.severity_Id, 10*256);
   // new severity cell
   Cell cellSeverity=row.createCell(severity_Id);
   cellSeverity.setCellValue("Severity");
   cellSeverity.setCellStyle(rowTitleStyle);
   ID++;
  }
  if(sInfor.isProduct()){
   this.product_Id=ID;
   sh.setColumnWidth(this.product_Id, 12*256);
   // new product cell
   Cell cellProduct=row.createCell(product_Id);
   cellProduct.setCellValue("Product");
   cellProduct.setCellStyle(rowTitleStyle);
   ID++;
  }
  if(sInfor.isOS()){
   this.OS_Id=ID;
   sh.setColumnWidth(this.OS_Id, 12*256);
   // new OS cell
   Cell cellOS=row.createCell(OS_Id);
   cellOS.setCellValue("OS");
   cellOS.setCellStyle(rowTitleStyle);
   ID++;
  }
  if(sInfor.isHardware()){
   this.hardware_Id=ID;
   sh.setColumnWidth(this.hardware_Id, 12*256);
   // new Hardware cell
   Cell cellHardware=row.createCell(hardware_Id);
   cellHardware.setCellValue("Hardware");
   cellHardware.setCellStyle(rowTitleStyle);
   ID++;
  }
  if(sInfor.isComp()){
   this.comp_Id=ID;
   sh.setColumnWidth(this.comp_Id, 12*256);
   // new Component cell
   Cell cellComp=row.createCell(comp_Id);
   cellComp.setCellValue("Component");
   cellComp.setCellStyle(rowTitleStyle);
   ID++;
  }
  if(sInfor.isSummary()){
   this.summary_Id=ID;
   sh.setColumnWidth(this.summary_Id, 60*256);
   // new Summary cell
   Cell cellSummary=row.createCell(summary_Id);
   cellSummary.setCellValue("Summary");
   cellSummary.setCellStyle(rowTitleStyle);
   ID++;
  }
  if(sInfor.isDesc()){
   this.desc_Id=ID;
   sh.setColumnWidth(this.desc_Id, 60*256);
   // new Description cell
   Cell cellDesc=row.createCell(desc_Id);
   cellDesc.setCellValue("Detail Description");
   cellDesc.setCellStyle(rowTitleStyle);
   ID++;
  }
  if(sInfor.isFrequency()){
   this.frequency_Id=ID;
   sh.setColumnWidth(this.frequency_Id, 10*256);
   // new Frequency cell
   Cell cellFrequency=row.createCell(frequency_Id);
   cellFrequency.setCellValue("Frequency");
   cellFrequency.setCellStyle(rowTitleStyle);
   ID++;
  }
  if(sInfor.isVersion()){
   this.version_Id=ID;
   sh.setColumnWidth(this.version_Id, 15*256);
   // new severity cell
   Cell cellVersion=row.createCell(version_Id);
   cellVersion.setCellValue("Version");
   cellVersion.setCellStyle(rowTitleStyle);
   ID++;
  }
  if(sInfor.isLanguage()){
   this.language_Id=ID;
   sh.setColumnWidth(this.language_Id, 15*256);
   // new language cell
   Cell cellLanguage=row.createCell(language_Id);
   cellLanguage.setCellValue("language");
   cellLanguage.setCellStyle(rowTitleStyle);
   
   ID++;
  }
  if(sInfor.isReporter_realname()){
   this.reporter_realname_Id=ID;
   sh.setColumnWidth(this.reporter_realname_Id, 20*256);
   // new Reporter real name cell
   Cell cellReporterRealName=row.createCell(reporter_realname_Id);
   cellReporterRealName.setCellValue("Reporter");
   cellReporterRealName.setCellStyle(rowTitleStyle);
   ID++;
  }
  if(sInfor.isOpened_time()){
   this.opened_time_Id=ID;
   sh.setColumnWidth(this.opened_time_Id, 20*256);
   // new Opened time cell
   Cell cellOpened=row.createCell(opened_time_Id);
   cellOpened.setCellValue("Opened");
   cellOpened.setCellStyle(rowTitleStyle);
   ID++;
  }
  if(sInfor.isReporter()){
   this.reporter_Id=ID;
   sh.setColumnWidth(this.reporter_Id, 20*256);
   // new Reporter cell
   Cell cellReporter=row.createCell(reporter_Id);
   cellReporter.setCellValue("Report Email");
   cellReporter.setCellStyle(rowTitleStyle);
   ID++;
  }
  if(sInfor.isAssign_realname()){
   this.assign_realname_Id=ID;
   sh.setColumnWidth(this.assign_realname_Id, 20*256);
   // new assign real name cell
   Cell cellAssignRealName=row.createCell(assign_realname_Id);
   cellAssignRealName.setCellValue("Assign");
   cellAssignRealName.setCellStyle(rowTitleStyle);
   ID++;
  }
  if(sInfor.isAssign()){
   this.assign_Id=ID;
   sh.setColumnWidth(this.assign_Id, 20*256);
   // new assign cell
   Cell cellAssign=row.createCell(assign_Id);
   cellAssign.setCellValue("Assign Email");
   cellAssign.setCellStyle(rowTitleStyle);
   ID++;
  }
  if(sInfor.isChanged_time()){
   this.changed_time_Id=ID;
   sh.setColumnWidth(this.changed_time_Id, 20*256);
   // new severity cell
   Cell cellChanged=row.createCell(changed_time_Id);
   cellChanged.setCellValue("Changed");
   cellChanged.setCellStyle(rowTitleStyle);
   ID++;
  }
  if(sInfor.isComments()){
   this.comments_Id=ID;
   sh.setColumnWidth(this.comments_Id, 60*256);
   // new comments cell
   Cell cellComments=row.createCell(comments_Id);
   cellComments.setCellValue("Comments");
   cellComments.setCellStyle(rowTitleStyle);
   ID++;
  }
  if(sInfor.isReopen_version()){
   this.reopen_version_Id=ID;
   sh.setColumnWidth(this.reopen_version_Id, 20*256);
   // new severity cell
   Cell cellReopened=row.createCell(reopen_version_Id);
   cellReopened.setCellValue("Reopen version");
   cellReopened.setCellStyle(rowTitleStyle);
   ID++;
  }
  if(sInfor.isClose_version()){
   this.close_version_Id=ID;
   sh.setColumnWidth(this.close_version_Id, 20*256);
   // new severity cell
   Cell cellClosed=row.createCell(close_version_Id);
   cellClosed.setCellValue("Close version");
   cellClosed.setCellStyle(rowTitleStyle);
   ID++;
  }
   
  //合并第一行单元格
  sh.addMergedRegion(new CellRangeAddress(0,0,0,ID-1));
  
 }
 
 /**
  * 将workbokk 通过fileOutputStream输入为excel文件
  * @param wb
  */
 public void OutputExcel(String strPath) throws Exception{
  FileOutputStream fileOut =null;  
  try{
   fileOut=new FileOutputStream(strPath);   
   wb.write(fileOut);   
  } finally{
   if(fileOut!=null){    
     fileOut.close();
   }   
  }
 }
}

 

你可能感兴趣的:(Bugzilla Bug Xml导出为excel)