NetOffice
NetOffice copied to clipboard
NetOfficeFw not close Application if call by WebApi
NetOfficeFw 1.9.3 Framework .NET6.0 VS 2022 SO Win 11
I have buid a simple example for test convertion in Pdf file
public static void ConvertExcel2Pdf(string excelPath, string pdfPath)
{
Workbook wkb = null;
NetOffice.ExcelApi.Application app = new NetOffice.ExcelApi.Application(true);
try
{
app.DisplayAlerts = false;
app.Visible = false;
wkb = app.Workbooks.Open(excelPath);
wkb.ExportAsFixedFormat(XlFixedFormatType.xlTypePDF, pdfPath);
}
finally
{
// Cleanup
wkb.Close(false);
wkb.Dispose();
app.Quit();
WaitForComCleanup();
}
}
It work fine and close process if i call this method by Console App, but if i call via WebAPI
[HttpGet()]
[Route("api/GetConvert2Pdf")]
public string GetConvert2Pdf(string fullPathInputFile = @"c:\temp\TemplateExcel.xlsx")
{
try
{
string testFileInput = fullPathInputFile;
string testFileOutput = @"c:\temp\TemplateExcel.pdf";
ConvetDocumentUtility.ConvertExcel2Pdf(testFileInput, testFileOutput);
}
catch (Exception ex)
{
return ex.Message;
}
return "Finish OK!";
}
seem not to able to close to process
there is a workarround?
Thanks