My winform application doesn't work on others' pc without vs 2010 installed
- by wings
Just like I said, my winform application works properly on computers with VS installed, but on other computers, it will crash due to a FileNotFound Exception. I used
using Application = Microsoft.Office.Interop.Excel.Application;
in my source code to generate a Excel file, and the problem occurs as soon as the Excel-related function is called. But I don't know what it refers to exactly. Do I have to get some .dll included along with the .exe file? And what DLL is that?
Below are part of my codes:
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();
        }