zalezou
zotyouri
2018-09-29 01:31

VB.net 处理Excel2010时设置app.Visible = False无效

  • excel
  • qrmarker控件
  • vba
  • vb
  • 二维码

各位大侠

求~~~~~~~~

test1只往excel sheet 单元格A1中写入内容时如果将app.Visible = False的话,excel窗口不会被打开为当前窗口,能正常隐藏在后台。

test2在excel表中追加了二维码QRmarker外部控件,在sheet1中插入一个二维码,通过点击按钮给二维码赋值。**也是同样进行app.Visible = False,但是excel窗口还是会显示出来,不会隐藏,有没有什么办法可以不让其显示。**

备注:
1.QRmarker控件 https://blog.bccn.net/tlliqi/16654
2.QRmarker控件在excel中的使用方法:http://blog.51cto.com/windyli/284574

Imports Microsoft.Office.Interop
Imports Microsoft.Office.Core

test1:

Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
Dim app As Excel.Application
Dim book As Excel.Workbook
Dim sheet As Excel.Worksheet

    '
    Dim filename As String
    filename = "C:\test1.xlsx"
    app = CreateObject("Excel.Application")
    app.Visible = False
    book = app.Workbooks.Open(filename)
    sheet = book.Worksheets("Sheet1")
    sheet.Range("A1").Value = "test1"
    book.Save() '保存
    app.Quit() '終了
    ' 解放
    sheet = Nothing
    book = Nothing
    app = Nothing
    System.GC.Collect()
End Sub

** test2:**
Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
Dim app As Excel.Application
Dim book As Excel.Workbook
Dim sheet As Excel.Worksheet

    Dim filename As String
    filename = "C:\test2.xlsx"
    app = CreateObject("Excel.Application")
    app.Visible = False
    book = app.Workbooks.Open(filename)
    sheet = book.Worksheets("Sheet1")
    sheet.Range("A2").Value = "test2"

    Dim QRString1 As String = "test22222222222222"
    With sheet.QRmaker1
        .ModelNo = 2
        .CellPitch = 5
        .CellUnit = 200
        .QuietZone = 0
        .InputData = QRString1
        .ShapeRange.Width = 50
        .ShapeRange.Height = 50
        .AutoRedraw = 1
        '.AutoRedraw = ArOn
        .Refresh()
    End With
    book.Save() '保存
    app.Quit() '終了
    ' 解放
    sheet = Nothing
    book = Nothing
    app = Nothing
    System.GC.Collect()
End Sub
  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

0条回答