检查下面的代码
{
var file = Request.Form.Files;
var path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "dowanloadErpFiles");
var newFileName = $"EeasergyFile_{DateTime.Now.ToPersianDateTime().Replace("/", "_").Replace(":", "_")}.xls";
newFilePath = Path.Combine(path, newFileName);
List<string> FirstColumn_Value = new List<string>();
Stream sr = System.IO.Stream.Null;
HSSFWorkbook hssfwb = null;
HSSFSheet SettingSheet = null;
HSSFSheet RelaySheet = null;
HSSFRow dataRow;
int countRow = 0;
string cel = "";
await Task.Run(() =>
{
if (file.Count > 0)
{
using (sr = file[0].OpenReadStream())
{
hssfwb = new HSSFWorkbook(sr);
sr.Close();
SettingSheet =(HSSFSheet) hssfwb.GetSheet("Settings");
RelaySheet = (HSSFSheet)hssfwb.GetSheet("Relay");
countRow = SettingSheet.PhysicalNumberOfRows;
for (int i = 0; i < countRow; i++)
{
cel = SettingSheet.GetRow(i).Cells[0].StringCellValue;
FirstColumn_Value.Add(cel);
}
foreach (var row in lst)
{
string SQL_Address = row.ADDRESS;
string ParamValue = row.PARAMETER_VALUE;
for (int y = 0; y < FirstColumn_Value.Count; y++)
{
if (SQL_Address == FirstColumn_Value[y])
{
dataRow = (HSSFRow)SettingSheet.GetRow(y);
dataRow.GetCell(2).SetCellValue(ParamValue);
}
}
}
}
using (FileStream fs = new FileStream(newFilePath, FileMode.Create, FileAccess.ReadWrite))
{
hssfwb.Write(fs);
fs.Close();
}
}
});
}