Hello,everyone. Can a table be exported to Excel?
we define a table in AutoCAD :
Dim TableEnt As New Autodesk.AutoCAD.DatabaseServices.Table()
Then, we can launch Excel :
Imports Microsoft.Office.Interop
Public Sub exportToExcel()
Dim xlApp As Excel.Application
Dim xlWorkBook As Excel.Workbook
Dim xlWorkSheet As Excel.Worksheet
Dim misValue As Object = System.Reflection.Missing.Value
Try
xlApp = New Excel.ApplicationClass
xlWorkBook = xlApp.Workbooks.Add(misValue)
'Fixed:(Microsoft.Office.Interop.Excel.Worksheet)
xlWorkSheet = DirectCast(xlWorkBook.Sheets("sheet1"), Excel.Worksheet)
xlWorkSheet = DirectCast(xlWorkBook.ActiveSheet, Excel.Worksheet)
'changing the name of active sheet
xlWorkSheet.Name = "My Exported DataSet"
xlApp.Visible = True
Catch ex As Exception
MessageBox.Show(ex.StackTrace() + ex.Message())
End Try
End Sub
But how to select a table in AutoCAD, and then expoted the texts to Excel.
Is this possible? I have no idea of this. Is there anyone who has done this before?
By the way, To lanuch Excel, we will need to add a reference to the Microsoft Excel object library.Do it liks this:
Right click on your project and select Add Reference menu. After that go to COM tab and select and add Microsoft Excel 12.0 object library