使用命令参数调试 VSTO [英] Debugging VSTO with a Command Argument

查看:46
本文介绍了使用命令参数调试 VSTO的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个 Excel 插件,当人们通过打开工作簿启动 Excel 时,我看到了一些错误.如果他们启动 Excel,然后打开一个工作簿,一切都很好,但否则就会出现问题.

I am developing an Excel Add-In, and I'm seeing some bugs that are coming up when people start Excel by opening a Workbook. If they start Excel and then open a Workbook, everything is fine, but otherwise there are issues.

问题是,我不知道如何调试它,因为我无法使用 Excel 命令参数启动调试器(据我所知).

The problem is, I don't know how to debug this, as I can't start the debugger with an Excel command argument (as far as I know).

我会根据要求添加一些细节:

I'll add some detail as requested:

在 ThisAddIn.cs 中,我有 2 个给我带来问题的代码块.

Inside the ThisAddIn.cs, I have 2 blocks of code that are giving me problems.

private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
    try
    {
        if (isStarted) return;

        var xl = this.Application;
        xl.WorkbookOpen += WorkbookOpened;
        xl.SheetActivate += Workbook_SheetActivate;

        var workbook = Application.ActiveWorkbook;

        WorkbookOpened(workbook);

        isStarted = true;
    }
    catch (Exception ex)
    {
        logger.LogIt($"Error 01 - {ex.Message}");
    }
}

和:

private void WorkbookOpened(Excel.Workbook workbook)
{
    try
    {
        if (!isStarted)
        {
            var xl = this.Application;
            xl.WorkbookOpen += WorkbookOpened;
            xl.SheetActivate += Workbook_SheetActivate;

            isStarted = true;
        }

        int key = Application.Hwnd;

        dynamic srVers = null;

        if (workbook.CustomDocumentProperties.Count == 0) return;

        var srType = workbook.CustomDocumentProperties("InternalDocType");

        try
        {
            srVers = workbook.CustomDocumentProperties("Version");
        }
        catch (Exception)
        {
            srVers = null;
        }

        if (srType.Value != "OurType") return;

        Globals.Ribbons.prRibbon.WorkbookOpened(workbook);
    }
    catch (Exception ex)
    {
        logger.LogIt($"Error 06 - {ex.Message}");
    }
}

当有人启动 Excel 并打开工作簿时,没有错误.但是,如果有人通过打开工作簿(在文件资源管理器中双击,或右键单击 Excel 并选择工作簿)来打开 Excel,我会收到错误 06 然后是错误 01,两者都带有未将对象引用设置为对象的实例."

When someone starts Excel and opens the workbook, there are no errors. However, if someone opens Excel by opening the workbook (double-click in File Explorer, or right click Excel and choosing the workbook) I get the Error 06 then Error 01, both with "Object reference not set to an instance of an object."

有什么建议吗?

推荐答案

@ESDictor,可以在visual studio中直接将excel文件的路径作为命令行参数传递.

@ESDictor, you can directly pass the path of the excel file as command line argument in visual studio.

这篇关于使用命令参数调试 VSTO的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆