注册 登录
编程论坛 VB.NET论坛

VBnet 如何打开excel 文件, 并自己输入excel 的密码。

mrkkk 发布于 2014-03-09 02:10, 2050 次点击
请各位大神帮忙。
想用vbnet 打开excel 的文件, excel 文件有密码。
曾经用vb6.0 打开excel 文件,并自行输入密码。 但是现在新的vbnet 不知道如何操作。
我用了 process start(C:/user/desktop/a.xlsm) 打开了, 不过不知道怎么输入其excel 附属的密码.  
试过了process start( , , , ) 里面的 password栏目, 不过总显示我的密码不符合 security string.
不知道有没有什么方式可以帮忙解决.

急~~~ 希望好心人可以给个方法~~最好附上详细的code(跪求)
我要打开的文件是(C:/user/desktop/a.xlsm),excel 文件的密码是123456
3 回复
#2
mrkkk2014-03-09 14:23
没人呢~~~

没人帮忙么~~~
#3
tlliqi2014-03-09 18:38
没弄过
#4
cnwangb2014-03-22 15:40
首先在  项目-添加引用- 添加上  Microsoft.Office.Interop.Excel

以下代码在VS VB2013 +OFFICE 2010通过:


Imports Microsoft.Office.Interop.Excel
Public Class Form1
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim xlApp As Microsoft.Office.Interop.Excel.Application
        Dim xlBook As Microsoft.Office.Interop.Excel.Workbook
        Dim sfile As String
        sfile = "z:\123.xlsx"

        xlApp = New Microsoft.Office.Interop.Excel.Application
        xlApp.DisplayAlerts = False               'EXCEL运行中不显示对话框,直接运行
        xlBook = xlApp.Workbooks.Open(sfile, Password:=123456)  'excel打开密码为123456
        xlApp.Rows("1:1").RowHeight = 23.25          '设置第一行行高23.25
        xlApp.Cells(2, 1) = "你好,这是一个测试"
        xlApp.Range("A3:F3").Interior.ColorIndex = 37 ' 浅蓝色填充

        xlBook.Save()
        xlBook.Close()
        xlApp.Quit()
        MsgBox("ok!")
    End Sub
End Class
1