import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import jxl.CellType;
import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;
import org.apache.struts2.ServletActionContext;
import com.qian.ey.yst.lucene.SearchLucene;
import com.qian.ey.yst.utils.CheckIP;
import com.qian.ey.yst.utils.ChineseCharToEn;
import com.qian.ey.yst.utils.DateUtils;
import com.qian.ey.yst.utils.FreeMarkerManager;
import com.qian.ey.yst.utils.Sys;
import com.qian.ey.yst.utils.UploadUtils;
import com.qian.ey.yst.ystcustomer.domain.YstCustomer;
import com.qian.ey.yst.ystcustomer.domain.YstCustomerGoods;
import com.qian.ey.yst.ystgoods.dao.IYstGoodsDao;
import com.qian.ey.yst.ystgoods.domain.YstGoods;
import com.qian.framework.userLog.dao.ILogDao;
import com.qian.framework.utils.SeparatePage;
public class YstGoodsAction {
private IYstGoodsDao ystgoodsDao;
private ILogDao logDao;
private int sign;
private String prompt;
private File excel;
public String importantCustomer() throws
BiffException, IOException, InterruptedException{
//获取request对象
HttpServletRequest request =
ServletActionContext.getRequest();
try {
//定义一个list
用于存放excel表格中内容
List list
=new ArrayList();
//判断否和模板是否存在
if(!getExcel().exists()){
//提示信息
prompt="批量导入失败!您选择的文件不存在!";
//跳转页面
return "promptFail"; }
//构建Workbook对象,
只读Workbook对象
//直接从本地文件创建Workbook
//从输入流创建Workbook
InputStream
is= new FileInputStream(getExcel());
jxl.Workbook
rwb = Workbook.getWorkbook(is);
//获取第一张Sheet表
Sheet rs =
rwb.getSheet(0);
//得到所有的行数
int
rows=rs.getRows();
//得到所有的列数
int
columns=rs.getColumns();
//如果Excel中没有填入任何记录
if(rows==1||rows==0||columns!=36){
//提示信息
prompt="批量导入失败!模板为空或无有效数据!";
//跳转页面
return
"promptFail"; }//如果Excel中有记录
else{
//得到第1行的第1列
String
l1=rs.getCell(0, 0).getContents();
//得到第1行的第2列
String
l2=rs.getCell(1, 0).getContents();
//得到第1行的第3列
String
l3=rs.getCell(2, 0).getContents();
//判断文件是否符合模板要求
if(!l1.equals("序号")||!l2.equals("商品名称")||!l3.equals("生产企业")){
//提示信息
prompt="文件不符合模板要求!请选择提供的模板";
//跳转页面
return "promptFail";
}
List
ls=new ArrayList();
//字段属性赋值
for(int
i=1 ;i
YstGoods
goods=new YstGoods();
YstCustomerGoods
customergoods=new YstCustomerGoods();
//得到第i+1行的所有列数
String
goodsname=rs.getCell(1, i).getContents();
String
productinterprise=rs.getCell(2, i).getContents();
String classone=rs.getCell(3, i).getContents();
String classtwo=rs.getCell(4, i).getContents();
String classthree=rs.getCell(5, i).getContents();
String classfour=rs.getCell(6, i).getContents();
String approvalnumber=rs.getCell(7, i).getContents();
String specifications=rs.getCell(8, i).getContents();
String unit=rs.getCell(9, i).getContents();
String commonname=rs.getCell(10, i).getContents();
String englishname=rs.getCell(11, i).getContents();
String pack=rs.getCell(12, i).getContents();
//判断excel表格中第13列是否输入值
int OTCflag=0;
if((rs.=Integer.parseInt(rs.getCell(13, i).getContents());