生成Excel的通过净做奇怪的事情 [英] Generating Excel through .Net doing odd things

查看:108
本文介绍了生成Excel的通过净做奇怪的事情的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

早上好,
我有一个相当奇怪的事情发生与我通过净创建一个Excel工作表。 我加载了现有工作簿

Good Morning,
I have a rather odd thing happening with an Excel WorkSheet that I am creating through .Net. I load up an existing workbook

Dim _xlApp As New Excel.Application
Dim _xlWorkbook As Excel.WokBook = _xlApp.Workbooks.Open(_templateFileName)

将其设置为填充它(用于调试)之前,可见

set it to be visible before populating it (for debugging purposes)

_xlApp.Visible = True

我接下来要填充现有模板。

I then go on to populate the existing template.

Private Sub GenerateOceanFreightGrid()

        Dim columnCount As Integer = 4 ' _standardColumnCount
        Dim columnInsertPosition As Integer = 5

        If MyBooleanValue() Then
            _xlSheet.Columns(4).Insert()
            _xlSheet.Cells(7, 4) = "My Header Value"
            columnInsertPosition += 1
            columnCount += 1
        End If

当我设置的断点私人小组根。行,并通过线code线的步骤,它会插入声明的每个变量的一个新列,所以在这种情况下,它会插入两列之前,甚至打如果MyBooleanValue()...行(我可以看它实际发生是由于Excel的应用程序是可见的)。但是,如果我不设置断点,只是让直通,这并不在code运行发生。
没有多线程发生或其他任何东西,我怀疑会对code产生任何影响。 我明显的解决办法是不设置断点,我只是想知道是否有人见过出于什么原因出现这种情况? 谢谢

When i set a breakpoint on the "Private Sub Gen.." line, and step through the code line by line, it inserts a new column for each variable declared, so in this case it will insert two columns before it even hits the "If MyBooleanValue()..." line (I can watch it actually happen due to the Excel app being visible). However, if i dont set a breakpoint and just let the code run straight through this doesnt happen.
There is no multi threading happening or anything else that i suspect would have any impact on the code. My obvious work around is to not set the breakpoint, i was just wondering if anyone has seen this happen before and for what reason? Thanks

推荐答案

我怀疑这是由于一些财产,调试器正在评估,以便对大家有帮助 - 但它是一个邪恶的财产添加一列的副作用

I suspect this is due to some property that the debugger is evaluating in order to be helpful - but it's an evil property with the side-effect of adding a column.

我假设你没有任何观察变量,可以这样明确地?

I assume you don't have any Watch variables which could be doing this explicitly?

这篇关于生成Excel的通过净做奇怪的事情的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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