就像我说的,我的 winform 应用程序在安装了 VS 的计算机上正常工作,但在其他计算机上,它会由于FileNotFound Exception
. 我用了
using Application = Microsoft.Office.Interop.Excel.Application;
在我的源代码中生成一个Excel文件,一调用Excel相关函数就出现问题。但我不知道它具体指的是什么。我是否必须将一些.dll
与 .exe 文件一起包含在内?那DLL
是什么?
以下是我的部分代码:
private void FileExport(object objTable)
{
StartWaiting();
string[,] table = null;
try
{
table = (string[,])objTable;
}
catch (Exception ex)
{
ShowStatus(ex.Message, StatusType.Warning);
}
if (table == null)
{
return;
}
Application excelApp = new Application
{
DisplayAlerts = false
};
Workbooks workbooks = excelApp.Workbooks;
Workbook workbook = workbooks.Add(XlWBATemplate.xlWBATWorksheet);
Worksheet worksheet = (Worksheet)workbook.Worksheets[1];
worksheet.Name = "TABLE";
for (int i = 0; i < table.GetLength(0); i++)
{
for (int j = 0; j < table.GetLength(1); j++)
{
worksheet.Cells[i + 1, j + 1] = table[i, j];
}
}
Range range = excelApp.Range["A1", "H1"];
range.Merge();
range.Font.Bold = true;
range.Font.Size = 15;
range.RowHeight = 50;
range.EntireRow.AutoFit();
range = excelApp.Range["A2", "H8"];
range.Font.Size = 11;
range = excelApp.Range["A1", "H8"];
range.NumberFormatLocal = "@";
range.RowHeight = 300;
range.ColumnWidth = 50;
range.HorizontalAlignment = XlHAlign.xlHAlignCenter;
range.VerticalAlignment = XlVAlign.xlVAlignCenter;
range.EntireRow.AutoFit();
range.EntireColumn.AutoFit();
worksheet.UsedRange.Borders.LineStyle = 1;
Invoke(new MainThreadInvokerDelegate(SaveAs), new object[] { worksheet, workbook, excelApp }
);
EndWaiting();
}
`