import java.io.File;
import java.io.FileOutputStream;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.apache.log4j.Logger;
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.hssf.util.HSSFColor;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
public class ExportData(String[][] s,String outputFile){
// 创建新的Excel
HSSFWorkbook workBook = new HSSFWorkbook();
//创建工作表
HSSFSheet sheet = workBook.createSheet();
//在索引0的位置创建行(最顶端的行)
HSSFRow row = sheet.createRow((short) 0);
HSSFCell cell = null;
//内容行样式
HSSFCellStyle conStyle = workBook.createCellStyle();
try{
for(int i=0;i<s.length ;i++){
row = sheet.createRow(i);
cell = row.createCell((short)j);
cell.setCellStyle(conStyle);
HSSFCellStyle conStyle1 = workbook.createCellStyle();
conStyle1.setFillForegroundColor(HSSFColor.BLUE.index);//可对指定单元格背景变色
conStyle1.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
cell.setCellStyle(conStyle1);
cell.setCellValue(Tools.isNull(s[i][j]));
}
//新建一输出文件流
File oldFile = new File(outputFile);
if (oldFile.exists()) {
oldFile.delete();
}
FileOutputStream fOut = new FileOutputStream(outputFile);
// 把相应的Excel 工作簿存盘
workbook.write(fOut);
fOut.flush();
// 操作结束,关闭文件
fOut.close();
}