gpt4 book ai didi

vb.net - 用户在 vb.net 的对话框中单击取消后,如何摆脱消息框?

转载 作者:行者123 更新时间:2023-12-05 05:27:40 26 4
gpt4 key购买 nike

我的表单中有一个“另存为”对话框,用于保存 Excel 工作表。当我在对话框中单击取消时,会出现另一个消息框,询问“是否要保存对 Book1 所做的更改?”。我希望摆脱此消息框,因为用户已经决定不通过单击“取消”来保存 Excel...请帮助...谢谢...

         Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim xlApp As Microsoft.Office.Interop.Excel.Application
Dim xlWorkBook As Microsoft.Office.Interop.Excel.Workbook
Dim xlWorkSheet As Microsoft.Office.Interop.Excel.Worksheet
Dim misValue As Object = System.Reflection.Missing.Value

Dim myArray(DataGridView1.Rows.Count - 1, DataGridView1.Columns.Count - 1) As Object

Dim r As Integer
Dim c As Integer

xlApp = New Microsoft.Office.Interop.Excel.ApplicationClass
xlWorkBook = xlApp.Workbooks.Add(misValue)
xlWorkSheet = CType(xlWorkBook.Worksheets.Item("sheet1"), Microsoft.Office.Interop.Excel.Worksheet)
For r = 0 To DataGridView1.Rows.Count - 1
For c = 0 To DataGridView1.Columns.Count - 1
myArray(r, c) = DataGridView1.Rows(r).Cells(c).Value
Next cc
xlWorkSheet.Range("A1").Resize(DataGridView1.Rows.Count, DataGridView1.Columns.Count).Value = myArray
Dim saveFileDialog As New SaveFileDialog()
saveFileDialog.Filter = "Excel files (*.xlsx)|*.xlsx|All files (*.*)|*.*"
saveFileDialog.FilterIndex = 2
saveFileDialog.RestoreDirectory = True

If saveFileDialog.ShowDialog() = DialogResult.OK Then
xlWorkSheet.SaveAs(saveFileDialog.FileName)
MsgBox(" Your file has been saved")

End If


xlWorkBook.Close()
xlApp.Quit()
xlApp = Nothing
xlWorkBook = Nothing
xlWorkSheet = Nothing
End Sub

最佳答案

退出前试试这个:

xlApp.DisplayAlerts = False

或者将False值传递给close方法:

xlWorkBook.Close(False)

关于vb.net - 用户在 vb.net 的对话框中单击取消后,如何摆脱消息框?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17970271/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com