package ftkj.db;
import java.io.FileOutputStream;
import java.io.IOException;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import ftkj.form.*;
public class IntoExcel {
public void votoexcel(OrderForm of,int quantity1,float amount1,int county1,int school1) throws IOException
{
HSSFWorkbook wb=new HSSFWorkbook();
HSSFSheet sheet=wb.createSheet("lq");
System.out.println(of.getName());
//OrderForm de=(OrderForm)of.;
//HSSFRow row=sheet.createRow((short));
HSSFRow row=sheet.createRow((short)0);
HSSFRow row1=sheet.createRow((short)1);
setEncoding(row.createCell((short)0)).setCellValue(new String("产品编号"));
setEncoding(row.createCell((short)1)).setCellValue("产品名称");
setEncoding(row.createCell((short)2)).setCellValue("载体");
setEncoding(row.createCell((short)3)).setCellValue("单位包装");
setEncoding(row.createCell((short)4)).setCellValue("单价");
setEncoding(row.createCell((short)5)).setCellValue("数量");
setEncoding(row.createCell((short)6)).setCellValue("金额");
setEncoding(row.createCell((short)7)).setCellValue("出版单位");
setEncoding(row.createCell((short)8)).setCellValue("订购县区");
setEncoding(row.createCell((short)9)).setCellValue("订购学校");
setEncoding(row.createCell((short)10)).setCellValue("订购年度");
setEncoding(row1.createCell((short)0)).setCellValue(of.getNumber());
setEncoding(row1.createCell((short)1)).setCellValue(of.getName());
setEncoding(row1.createCell((short)2)).setCellValue(of.getCarrier());
setEncoding(row1.createCell((short)3)).setCellValue(of.getPacking());
setEncoding(row1.createCell((short)4)).setCellValue(of.getPrice());
setEncoding(row1.createCell((short)5)).setCellValue(quantity1);
setEncoding(row1.createCell((short)6)).setCellValue(amount1);
setEncoding(row1.createCell((short)7)).setCellValue(of.getPub());
setEncoding(row1.createCell((short)8)).setCellValue(county1);
setEncoding(row1.createCell((short)9)).setCellValue(school1);
setEncoding(row1.createCell((short)10)).setCellValue(of.getYear());
FileOutputStream fos=new FileOutputStream("c:\\haha.xls");
wb.write(fos);
fos.close();
}
public HSSFCell setEncoding(HSSFCell cell)
{
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
return cell;
}
}
另外需要导入三个包到你的工程中分别是:poi-2.5.1-final-20040804.jar
poi-contrib-2.5.1-final-20040804.jar
poi-scratchpad-2.5.1-final-20040804.jar