import java.io.FileOutputStream;
import java.util.List;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFDataFormat;
import org.apache.poi.hssf.usermodel.HSSFFont;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import com.sinosoft.utility.ExeSQL;
public class CreateReceiptClassImportTemplate {
public boolean CrtReceiptClassImportTemplate(List list,
String filename,String sheetname,String interfacetype) {
System.out.println("====filename=in=java="+filename);
HSSFWorkbook wb = new HSSFWorkbook(); //建立新HSSFWorkbook对象
HSSFSheet sheet = wb.createSheet();
wb.setSheetName( 0, sheetname, HSSFWorkbook.ENCODING_UTF_16 );
sheet.setDefaultColumnWidth((short) 15);
//样式2 宋体 写正文时用
HSSFFont font2 = wb.createFont();
font2.setColor(HSSFFont.COLOR_NORMAL);
font2.setFontName("宋体");
font2.setFontHeightInPoints((short) 12);
HSSFCellStyle normal = wb.createCellStyle();
normal.setFont(font2);
normal.setAlignment(HSSFCellStyle.ALIGN_LEFT); //水平居中
normal.setVerticalAlignment(HSSFCellStyle.VERTICAL_TOP); //垂直居中
normal.setDataFormat(HSSFDataFormat.getBuiltinFormat("@"));
HSSFRow row;
HSSFCell cell;
HSSFCell csCell;
//行
int i = 0;
row = sheet.createRow((short) i);
cell = row.createCell((short) (0)); //建立新cell
cell.setCellStyle(normal);
cell.setEncoding(HSSFCell.ENCODING_UTF_16); //设置cell编码解决中文高位字节截断
cell.setCellValue(interfacetype); //设置中西文结合字符串
row = sheet.createRow((short) 1);
for (int tmpi=1;tmpi<=list.size();tmpi++)
{
try{
cell = row.createCell((short) (tmpi-1)); //建立新cell
cell.setCellStyle(normal);
cell.setEncoding(HSSFCell.ENCODING_UTF_16); //设置cell编码解决中文高位字节截断
cell.setCellValue((String)list.get(tmpi)); //设置中西文结合字符串
}
catch(Exception e)
{
System.out.println(e);
return false;
}
}
try{
FileOutputStream fileOut = new FileOutputStream(filename);
wb.write(fileOut);
fileOut.close();
System.out.println("====动态模板文件excel文件生成成功:========"+filename);
}catch(Exception e1)
{
return false;
}
return true;
}
}