Может ли кто-нибудь помочь мне в этом. Проблема возникла при методе слияния во время выполнения.
Я использовал DLL Microsoft.Office.Interop.Excel.При объединении 2 ячеек. Мы получаем эту проблему.
В консольном приложении это работает хорошо, но когда я вставляю контроллер WebApI, он выдает ошибку.
using Microsoft.Office.Interop.Excel;
using System.Reflection;
using System.Runtime.InteropServices;
public void ExcelSheet()
{
Application excelApp = null;
Workbooks workBooks = null;
Workbook workBook = null;
Sheets sheets = null;
Worksheet workSheet = null;
Range tRange = null;
try
{
// Start Excel and get Application object.
excelApp = new Application();
workBooks = excelApp.Workbooks;
workBook = workBooks.Add();
sheets = workBook.Sheets;
workSheet = sheets.Add();
excelApp.Visible = true;
excelApp.DisplayAlerts = false;
workBook.Author = "Fullaname";
workSheet.Name = "Managers";
workSheet.Cells[1, "A"] = "Portfolio";
workSheet.Cells[1, "B"] = "Manager";
workSheet.Cells[1, "C"] = "Total ;
workSheet.Cells[1, "D"] = "Incidents";
//workSheet.Range["D1:E1"].Merge();
workSheet.get_Range("D1:E1").Merge();
workSheet.Cells[2, "D"] = "HKI";
workSheet.Cells[2, "E"] = "Low";
workSheet.Cells[1, "F"] = "Trend";
workSheet.Range["F1:I1"].Merge();
workSheet.Cells[2, "F"] = " Avg Medium";
workSheet.Cells[2, "G"] = " Avg Low";
workSheet.Cells[2, "H"] = "Medium";
workSheet.Cells[2, "I"] = "Low";
workSheet.get_Range("$A1", "$S1").WrapText = true;
//Wrap and Color
workSheet.get_Range("$A1", "$S1").Interior.ColorIndex = 6;
workSheet.get_Range("$A2", "$S2").WrapText = true;
workSheet.get_Range("$A2", "$S2").Interior.ColorIndex = 6;
workBook.Close();
excelApp.Quit();
}
finally
{
if (tRange != null) Marshal.ReleaseComObject(tRange);
if (workSheet != null) Marshal.ReleaseComObject(workSheet);
if (sheets != null) Marshal.ReleaseComObject(sheets);
if (workBook != null) Marshal.ReleaseComObject(workBook);
if (workBooks != null) Marshal.ReleaseComObject(workBooks);
if (excelApp != null) Marshal.ReleaseComObject(excelApp);
GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();
GC.WaitForPendingFinalizers();
}
}