如题,对1000条数据进行计算,有点复杂,经常活出现这个乱码问题,但是有时也不会出现,下面的导入的点击事件,hpf.SaveAs(tempFileName); 是先保存文件在服务器的一个文件下,如果乱码,该文件下就没有新增的excel,所以我觉得是前面的问题 ,但是不知道是什么原因
protected void btnImport_Click(object sender, EventArgs e)
{
string errorMsg = string.Empty;
if (ValidateExcelFile(ref errorMsg))
{
using (ImportExcelHelper importHelper = new ImportExcelHelper())
{
importHelper.InitConfig(Type);
HttpPostedFile hpf = fileUploader.PostedFile;
tempFileName = MapPath("/path_temp/" + Guid.NewGuid().ToString("N") + ".xls");
hpf.SaveAs(tempFileName);
//判断是否有重付信息
bool repetition = true;
if (Type == "RentImport")
{
repetition = RentRepetition();
}
if (Type == "MeterImport")
{
repetition = MeterCostRepetition();
}
if (Type == "TowerRentImport")
{
ATowerInventoryImport();
ScriptHelper.AlertAndCloseDialog(this, "导入成功", "true");
return;
}
if (Type == "CZImport")//场租表验证
{
CZVerification();
return;
}
if (Type == "ZDImport")//账单表验证
{
QZVerification();
return;
}
if (Type == "QZImport")//起租表验证
{
Rent();
return;
}
if (repetition == false)
{
return;
}
if (importHelper.GetWorksheetFromStream(fileUploader.FileContent))
{
importHelper.Import();
ScriptHelper.AlertAndCloseDialog(this, "导入成功", "true");
}
else
{
importResult.Text = string.Join("<br />", importHelper.ErrorInfo.ToArray());
}
}
}
else
{
ScriptHelper.Alert(this, errorMsg);
}
}
1 bool repetition = true; 2 if (Type == "RentImport") 3 { 4 repetition = RentRepetition(); 5 } 6 if (Type == "MeterImport") 7 { 8 repetition = MeterCostRepetition(); 9 } 10 if (Type == "TowerRentImport") 11 { 12 ATowerInventoryImport(); 13 ScriptHelper.AlertAndCloseDialog(this, "导入成功", "true"); 14 return; 15 } 16 if (Type == "CZImport")//场租表验证 17 { 18 CZVerification(); 19 return; 20 } 21 if (Type == "ZDImport")//账单表验证 22 { 23 QZVerification(); 24 return; 25 } 26 if (Type == "QZImport")//起租表验证 27 { 28 Rent(); 29 return; 30 }
这种代码需要重构,违背了对拓展开放,对修改封闭的原则。
乱码无法就是含有特殊字符或者编码方式有冲突,你不要觉得哪里对或者错,进去debug眼见为实,不要告诉我你不会debug,靠冥想和猜?
这个问题解决来了,自己写了个随笔记录下来了,我贴这里,如果有朋友也遇到就可以帮助到了,http://www.cnblogs.com/yyy116008/p/7883533.html