比较excel函数返回false时,如何修改web api返回不匹配的消息



我处理asp.net core 2.2,我面临无法的问题

修改web api以显示消息"Not Matched Compare"当比较excel函数返回假CCD_ 4时。

下面的web api将物理文件返回为zip file

在比较excel的情况下返回真实

但我需要在比较excel函数时返回错误

显示消息"Not matched compare"

那么请怎么做?

我尝试什么

public IActionResult ExportNormalizedRelation()
{
var InputfilePath = System.IO.Path.Combine(GetFilesDownload, "DeliveryGenerationNormalTest_Input.xlsx");
using (var stream = new FileStream(dbPath, FileMode.Create))
{
Request.Form.Files[0].CopyTo(stream);
stream.Flush();
stream.Close();
}
bool areIdentical = ex.CompareExcel(dbPath, InputfilePath, out rowCount, out error);
if (areIdentical == true)
{
pathToCreate = Path.Combine(myValue2,Month,"file" + DateTime.Now.Ticks.ToString());

Directory.CreateDirectory(pathToCreate);
List<inputexcelnormaltest> inputexcellist = new List<inputexcelnormaltest>();
inputexcellist = ex.ImportNormalTest(dbPath);
List<string> tabs = new List<string>();
var outputTemplatePath = System.IO.Path.Combine(GetFilesDownload, "DeliveryGeneration_Output.xlsx");
List<inputexcelnormaltest> inputmodulelist = new List<inputexcelnormaltest>();


foreach (var m in tabs)
{
inputmodulelist.Clear();
inputmodulelist = inputexcellist.Where(x => (x.TabName == m && x.FileName == f)).ToList();
var dtimport = DatatableConversion.ToDataTable(inputmodulelist);
DataTable dtexport = new DataTable();
dtexport = _deliveryService.LoadExcelToDataTableZipData(_connectionString, dtimport);
ex.Export(dtexport, m, exportPath);
}


}
string zipPath = Path.Combine(myValue2,Month,"result" + DateTime.Now.Ticks.ToString() + ".zip");
ZipFile.CreateFromDirectory(pathToCreate, zipPath);
return PhysicalFile(zipPath, "application/zip", Path.GetFileName(zipPath));



}
expected result
if (areIdentical == false)
return "Not Matched Compare"

那么怎么做呢?

我解决了问题

我只添加返回return new JsonResult("Not Matched Excel");

public IActionResult ExportNormalizedRelation()
{
var InputfilePath = System.IO.Path.Combine(GetFilesDownload, "DeliveryGenerationNormalTest_Input.xlsx");
using (var stream = new FileStream(dbPath, FileMode.Create))
{
Request.Form.Files[0].CopyTo(stream);
stream.Flush();
stream.Close();
}
bool areIdentical = ex.CompareExcel(dbPath, InputfilePath, out rowCount, out error);
if (areIdentical == false)
{
return new JsonResult("Not Matched Excel");
}
else

{
pathToCreate = Path.Combine(myValue2,Month,"file" + DateTime.Now.Ticks.ToString());

Directory.CreateDirectory(pathToCreate);
List<inputexcelnormaltest> inputexcellist = new List<inputexcelnormaltest>();
inputexcellist = ex.ImportNormalTest(dbPath);
List<string> tabs = new List<string>();
var outputTemplatePath = System.IO.Path.Combine(GetFilesDownload, "DeliveryGeneration_Output.xlsx");
List<inputexcelnormaltest> inputmodulelist = new List<inputexcelnormaltest>();


foreach (var m in tabs)
{
inputmodulelist.Clear();
inputmodulelist = inputexcellist.Where(x => (x.TabName == m && x.FileName == f)).ToList();
var dtimport = DatatableConversion.ToDataTable(inputmodulelist);
DataTable dtexport = new DataTable();
dtexport = _deliveryService.LoadExcelToDataTableZipData(_connectionString, dtimport);
ex.Export(dtexport, m, exportPath);
}


}
string zipPath = Path.Combine(myValue2,Month,"result" + DateTime.Now.Ticks.ToString() + ".zip");
ZipFile.CreateFromDirectory(pathToCreate, zipPath);
return PhysicalFile(zipPath, "application/zip", Path.GetFileName(zipPath));



}

最新更新