如何弹出保存或打开文件VB.Net

时间:2013-04-29 08:42:13

标签: asp.net vb.net excel browser

我的目标是尝试弹出保存或打开已创建文件的选项。

这是我的代码:

 Dim xlApp As Excel.Application
        Dim xlWorkBook As Excel.Workbook
        Dim xlWorkSheet As Excel.Worksheet
        Dim misValue As Object = System.Reflection.Missing.Value

        xlApp = New Excel.ApplicationClass
        xlWorkBook = xlApp.Workbooks.Add(misValue)
        xlWorkSheet = CType(xlWorkBook.Sheets("sheet1"), Excel.Worksheet)
        xlWorkSheet.Cells(1, 1) = "PERIOD"
        xlWorkSheet.Cells(1, 2) = "PARTS_NO_FG"
        xlWorkSheet.Cells(1, 3) = "QTY_ASSY"
        xlWorkSheet.Cells(1, 4) = "COSTING1"

        xlWorkSheet.Cells(2, 1) = "201212"
        xlWorkSheet.Cells(2, 2) = "01125E6041"
        xlWorkSheet.Cells(2, 3) = "5"
        xlWorkSheet.Cells(2, 4) = "0"


        xlWorkSheet.SaveAs("D:\TemplateAssy.xlsx")

        xlWorkBook.Close()
        xlApp.Quit()
        releaseObject(xlApp)
        releaseObject(xlWorkBook)
        releaseObject(xlWorkSheet)

然后当我执行这个程序VB.NET时如何弹出

1 个答案:

答案 0 :(得分:2)

只需启用提醒即可。它应该解决问题

 Application.DisplayAlerts = True

 workbook.SaveAs(filePath)

 Application.DisplayAlerts = True

来源:http://p2p.wrox.com/vb-how/63900-disabling-second-excel-save-prompt.html

来自shasur的回答

编辑:在你的情况下

 xlApp.DisplayAlerts = True

 xlWorkbook.SaveAs(filePath)

 xlApp.DisplayAlerts = True

也试试    xlApp.Visible = True

或许能够指出它没有出现的地点/原因。