从vb.net打开Excel工作簿Interop打开时不带功能区或菜单

时间:2018-01-19 02:58:21

标签: vb.net interop excel-interop

Screen shot

无法判断我的引用是否错误或者是什么,但是当我通过vb.net打开工作簿时,它会打开,没有菜单或条带可见,你甚至无法访问它们。它看起来像某种安全版本的Excel。如何让它正常打开?

这是我的完整块:(相关导入是Microsoft.Office.Interop.Excel

Private Sub ButtonExcel_Click(sender As Object, e As EventArgs) Handles ButtonExcel.Click
    Cursor = Cursors.WaitCursor
    System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.CreateSpecificCulture("en-US")
    Dim oExcel As Excel.Application = Nothing
    Dim oBook As Excel.Workbook = Nothing
    Dim oRosterSheet As Excel.Worksheet = Nothing
    oExcel = New Excel.Application
    oExcel.Visible = True

    oBook = oExcel.Workbooks.Open("C:\****.xlsb", [ReadOnly]:=True)
    oRosterSheet = oBook.Worksheets(1)
    oRosterSheet.Cells.Clear()

    Dim dc As System.Data.DataColumn
    Dim dr As System.Data.DataRow
    Dim colIndex As Integer = 0
    Dim rowIndex As Integer = 0

    For Each dc In RosterTable.Columns
        colIndex += 1
        oRosterSheet.Cells(1, colIndex) = dc.ColumnName
    Next dc

    For Each dr In RosterTable.Rows
        rowIndex = rowIndex + 1
        colIndex = 0
        For Each dc In RosterTable.Columns
            colIndex = colIndex + 1
            oRosterSheet.Cells(rowIndex + 1, colIndex) = dr(dc.ColumnName)
        Next dc
    Next dr

    Dim fileName As String = "C:\****.xlsb"
    oRosterSheet.Columns.AutoFit()
    oBook.SaveAs(Filename:=fileName)

    oExcel.UserControl = True

    ReleaseObject(oRosterSheet)
    ReleaseObject(oBook)
    ReleaseObject(oExcel)
    GC.Collect()

    Cursor = Cursors.Default
End Sub

1 个答案:

答案 0 :(得分:2)

想出来。原来它是在“全屏”模式下打开Excel,但不知何故没有最大化。可能与我在我正在进行远程处理的计算机上编码的事实有关。无论哪种方式,下面的行修正了它:

oExcel.DisplayFullScreen = False