无需打开文件即可从EXcel文件调用对象 [英] call object from EXcel file witout opening the file

查看:110
本文介绍了无需打开文件即可从EXcel文件调用对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的代码是

my code is

Dim oApp As New Excel.Application()
        Dim wb As Excel.Workbook
        Dim oldCI As System.Globalization.CultureInfo = System.Threading.Thread.CurrentThread.CurrentCulture
        System.Threading.Thread.CurrentThread.CurrentCulture = New System.Globalization.CultureInfo("en-US")
        wb = oApp.Workbooks.Open("D:\NoriaMail\23120011\LPO Summary per Month_View 3 - All Months.xlsx")
        'oApp.Workbooks.
        System.Threading.Thread.CurrentThread.CurrentCulture = oldCI
        oApp.Visible = False
        Dim cmdText As String
        Dim cmdType
        Dim connStr
        cmdText = wb.Connections.Item(1).OLEDBConnection.CommandText
        cmdType = wb.Connections.Item(1).OLEDBConnection.CommandType
        wb.Connections.Item(1).Delete()
        connStr = "OLEDB;Provider=SQLOLEDB.1;" & _
                        "Password=sa;" & _
                        "Persist Security Info=True;" & _
                        "User ID=sa;" & _
                        "Initial Catalog=Northwind;Data Source=."
        wb.Connections.Add("NORIA", "", connStr, cmdText, 2)
        wb.RefreshAll()
        'wb.Close(False)
        wb = Nothing
        oApp = Nothing
        ' oApp.Quit()
        GC.Collect()
        'wb.Close(True, "D:\NoriaMail\23120011\LPO Summary per Month_View 3 - All Months.xlsx", False)
        'oApp.Visible = False
        WebBrowser1.Navigate("D:\NoriaMail\23120011\LPO Summary per Month_View 3 - All Months.xlsx")
        'oApp.Visible = False
    End Sub


//我有三个问题
1-我要更改
wb = oApp.Workbooks.Open(& quot; D:\ NoriaMail \ 23120011 \ LPO每个月查看_摘要3-所有Months.xlsx")
用另一种方法初始化wb而不打开excel文件
2-如何在保存配置的情况下关闭文件,但又不让excel文件询问我是否要保存更改.
3-从内存中实现wb以及与其相关的所有事物.
请提供任何帮助.


//I have three problems
1-I want to change
wb = oApp.Workbooks.Open("D:\NoriaMail\23120011\LPO Summary per Month_View 3 - All Months.xlsx")
with another method to initialize wb without open the excel file
2-how can I close the file with saving my configuration but without let the excel file to ask me if I want to save my change.
3-realize wb from the memory and all thing connection with it.
please any help

推荐答案

如果我正确理解您的问题,则#2应该非常简单,因为Workbook.Close方法具有可选参数SaveChanges. HTH.

http://msdn.microsoft .com/es-es/library/microsoft.office.tools.excel.workbook.close(v = vs.80).aspx [
If I understand correctly your question, #2 should be pretty straightforward, as the Workbook.Close method has an optional parameter SaveChanges. HTH.

http://msdn.microsoft.com/es-es/library/microsoft.office.tools.excel.workbook.close(v=vs.80).aspx[^]

in youe code you invoke wb.close twice, both are commented... but the second call is made after you set wb to nothing... i don''t know why


这篇关于无需打开文件即可从EXcel文件调用对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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