521716 2015-01-07 02:39 采纳率: 0%
浏览 2152

c#打开excel后在手动打开excel两个excel句柄一样

我又重新编辑了一下

1.打开软件图片说明
2..点文件打开图片说明
3.打开psy++图片说明
图片说明
4.手动打开了一个excel
图片说明
图片说明
5.spy++查看
图片说明
图片说明

这个时候我软件本来是要操作之前打开的report.xlsx, 就变成了操作新建 Microsoft Office Excel 2007 Workbook.xlsx了。。。

下面是打开程序

 public static Excel._Application reportExcel;
        public static Excel._Workbook reportWorkbook;
        public static Excel._Worksheet reportSheet;
                public static void openReportExcel()
        {            
           // string fileName="";//= Application.StartupPath + @"\cfg\出货记录.xlsx";
            if(Form1.companySelect==0)
            {
                reportExcelPath = Application.StartupPath + @"\cfg\rean\report.xlsx";
            }
            else
            {
                reportExcelPath = Application.StartupPath + @"\cfg\benan\report.xlsx";
            }
            reportExcel = new Excel.Application();        
            try
            {
                reportExcel.Visible = true;
                reportWorkbook = (Excel._Workbook)reportExcel.Workbooks.Open(reportExcelPath,
                Missing.Value,
                Missing.Value,
                Missing.Value,
                Missing.Value,
                Missing.Value,
                Missing.Value,
                Missing.Value,
                Missing.Value,
                Missing.Value,
                Missing.Value,
                Missing.Value,
                Missing.Value,
                Missing.Value,
                Missing.Value
                );
                openReportResult = 1;
            }
            catch (Exception err)
            {
                openReportResult = 2;
                MessageBox.Show(Convert.ToString(err));                
            }          
        }

  • 写回答

3条回答 默认 最新

  • threenewbee 2015-01-07 02:46
    关注

    两个窗口句柄肯定不同。不知道“句柄精灵”是什么玩艺,也许它有bug。建议你用spy++去看看。

    评论

报告相同问题?