我有一個應用需要在應用程式中打開EXCEL,于是用用SetParent 嵌入Excel表,可EXCEL表沒有辦法編輯,請各路大神支支招
Public Sub Open(fileName As String, editAble As Boolean)
Try
If mParentOfficeEdit.InvokeRequired Then
mParentOfficeEdit.Invoke(New Dele_Open(AddressOf Open), New Object() {fileName, editAble})
Else
mEditAble = editAble
Dim fi As System.IO.FileInfo = New System.IO.FileInfo(fileName)
mCaption = fi.Name + " " + DateTime.Now.Ticks.ToString()
deactivateevents = True
OpenFileName = fileName
'初始化Word程式
InitExcel()
'先關閉檔案
CloseDoc()
mAppHwnd = FindWindow("XLMAIN", mCaption)
If mAppHwnd > 0 Then
SetParent(mAppHwnd, mParentOfficeEdit.Handle.ToInt32())
Try
If mExcelApp Is Nothing Then
Throw New WordInstanceException()
End If
If mExcelApp.Workbooks Is Nothing Then
Throw New DocumentInstanceException()
End If
If Not mExcelApp Is Nothing AndAlso Not mExcelApp.Workbooks Is Nothing Then
mWorkbook = mExcelApp.Workbooks.Open(fileName, 0, False)
mExcelApp.Visible = True
Dim mySheet As Microsoft.Office.Interop.Excel.Worksheet = CType(mWorkbook.Worksheets(1), Microsoft.Office.Interop.Excel.Worksheet)
Dim localrange As Microsoft.Office.Interop.Excel.Range = CType(mySheet.Cells(1, 1), Microsoft.Office.Interop.Excel.Range)
localrange.Activate()
End If
If mWorkbook Is Nothing Then
Throw New ValidDocumentException()
End If
Catch
End Try
'把Word顯示到界面
ShowExcelToUi()
OnResize()
SetExcelActive()
deactivateevents = False
End If
End If
Catch ex As Exception
Close()
DisplaySystemMessage("", ex, SystemMessageEnum.ErrMessage) '處理錯誤
End Try
End Sub
uj5u.com熱心網友回復:
樓主以前記得有現成的操作Excel的組件,可以上網找下看看uj5u.com熱心網友回復:
各位大俠們幫支支招吧uj5u.com熱心網友回復:
你可以用OLE或者直接用第三方組件來操作excel,比如NPOI,spire.xls,aspose等這些都挺好用的,還不依賴office組件。uj5u.com熱心網友回復:
樓上有道理,最開始用ole,之后用npoi,現在用spire,反正各有各的艸蛋吧。轉載請註明出處,本文鏈接:https://www.uj5u.com/net/119035.html
標籤:VB.NET
