◀ Previous Next ▶ Up ▲


ใช้ vb.net สั่งเปิดไฟล์ excel ที่มีอยู่ไม่ได้ครับ

ผมเขียน code ดังนี้ครับ

Imports Excel
Imports System.Data
Imports System.Data.SqlClient
Imports System.Globalization
Public Class frmExcelTest
   Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

   Public Sub New()

       'This call is required by the Windows Form Designer.

       'Add any initialization after the InitializeComponent() call

   End Sub

   'Form overrides dispose to clean up the component list.
   Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
       If disposing Then
           If Not (components Is Nothing) Then
           End If
       End If
   End Sub

   'Required by the Windows Form Designer
   Private components As System.ComponentModel.IContainer

   'NOTE: The following procedure is required by the Windows Form Designer
   'It can be modified using the Windows Form Designer.  
   'Do not modify it using the code editor.
   Friend WithEvents txtProd_SerialNo As System.Windows.Forms.TextBox
   Friend WithEvents btnPrint As System.Windows.Forms.Button
   <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
       Me.txtProd_SerialNo = New System.Windows.Forms.TextBox
       Me.btnPrint = New System.Windows.Forms.Button
       Me.txtProd_SerialNo.Location = New System.Drawing.Point(48, 32)
       Me.txtProd_SerialNo.MaxLength = 10
       Me.txtProd_SerialNo.Name = "txtProd_SerialNo"
       Me.txtProd_SerialNo.Size = New System.Drawing.Size(136, 20)
       Me.txtProd_SerialNo.TabIndex = 19
       Me.txtProd_SerialNo.Text = ""
       Me.btnPrint.Location = New System.Drawing.Point(192, 32)
       Me.btnPrint.Name = "btnPrint"
       Me.btnPrint.TabIndex = 28
       Me.btnPrint.Text = "พิมพ์"
       Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
       Me.ClientSize = New System.Drawing.Size(292, 118)
       Me.Name = "frmExcelTest"
       Me.Text = "frmExcelTest"

   End Sub

#End Region

   Private Sub btnPrint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrint.Click
       Dim xlsApp As Excel.Application

       Dim xlsBook As Excel.Workbook

       Dim xlsSheet As Excel.Worksheet

       xlsApp = New Excel.Application

       xlsBook = xlsApp.Workbooks.Open("d:\job.xls")

       xlsSheet = xlsBook.ActiveSheet

       xlsApp.Visible = True

   End Sub
End Class


จากคุณ : Wut_The_Gunner -[ 27 ก.ย. 50 - 22:09:17 ]