我这里有一个代码VB.NET
。该代码使程序能够查询MS ACCESS database
并将其保存到Excel File(.xls)
并提示用户是否要打开文件。代码运行良好,但打开文件时出现问题。这些列不会自动适应其内容,这使得文件如此混乱,我还想让用户可以选择打印文件。有什么办法可以解决我的问题吗?如果您有任何澄清,请随时询问。
If (Not Directory.Exists("C:\Sales Monitoring Report")) Then
Directory.CreateDirectory("C:\Sales Monitoring Report")
End If
System.IO.File.Delete("C:\Sales Monitoring Report\Transaction.xls")
Dim createExcelFile = "SELECT ORNumber, UserID, TransactionID, Vatable, Tax, Amount, TransactionDate, Status INTO [Excel 12.0;HDR=YES;DATABASE=C:\Sales Monitoring Report\Transaction.xls].[Sheet1] FROM tbl_transaction"
ExecNonQuery(createExcelFile)
If MessageBox.Show("Do you want to open the file?", "Open File", MessageBoxButtons.YesNo) = Windows.Forms.DialogResult.Yes Then
Dim excelFile As New Excel.Application
Dim excelWorkBook As Excel.Workbook
excelWorkBook = excelFile.Workbooks.Open("C:\Sales Monitoring Report\Transaction.xls")
excelFile.Visible = True
excelWorkBook.Activate()
End If