James, Kirk,Thanks for your detailed replies. Both of them helped a great deal - in fact, I think James completed my *next* project for me! Just think how pleased my boss will be.I'm afraid I wasn't as detailed or descriptive as I needed to be in this post. I'm going to start a new one today, and if either of you would like, I'd love to hear from you.Thanks again for your help.Justin
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim pLayer As IFeatureLayer pLayer = GetLayer("Add your layer name here") If pLayer Is Nothing Then MsgBox("Layer Not Found... Exiting") Exit Sub End If buildTempDataTable(pLayer) End Sub
Private Function GetLayer(ByVal lyrName As String) As IFeatureLayer Dim pDoc As ESRI.ArcGIS.ArcMapUI.IMxDocument Dim pMap As ESRI.ArcGIS.Carto.IMap Dim pLayer As ESRI.ArcGIS.Carto.IFeatureLayer Dim i As Short 'Layer name to find Dim sLayerName As String sLayerName = lyrName pDoc = m_pApp.Document pMap = pDoc.FocusMap For i = 0 To pMap.LayerCount - 1 If pMap.Layer(i).Name = sLayerName Then pLayer = pMap.Layer(i) Exit For End If Next Return pLayer End Function
Private Sub buildTempDataTable(ByVal pLayer As IFeatureLayer) Dim tmpDT As New DataTable("tmpDT") Dim column As DataColumn Dim pTable As ITable = pLayer.FeatureClass Dim pFields As IFields = pTable.Fields Dim pCur As ICursor = pTable.Search(Nothing, False) For c = 0 To pCur.Fields.FieldCount - 1 column = New DataColumn() column.ColumnName = (pFields.Field(c).Name) If pFields.Field(c).Type = esriFieldType.esriFieldTypeString Then column.DataType = System.Type.GetType("System.String") ElseIf pFields.Field(c).Type = esriFieldType.esriFieldTypeInteger Then column.DataType = System.Type.GetType("System.Int32") ElseIf pFields.Field(c).Type = esriFieldType.esriFieldTypeDouble Then column.DataType = System.Type.GetType("System.Double") ElseIf pFields.Field(c).Type = esriFieldType.esriFieldTypeDate Then column.DataType = System.Type.GetType("System.DateTime") End If column.ReadOnly = False tmpDT.Columns.Add(column) Next Dim pRow As IRow = pCur.NextRow Dim newRow As DataRow Do Until pRow Is Nothing newRow = tmpDT.NewRow() newRow.BeginEdit() For cols = 0 To pCur.Fields.FieldCount - 1 newRow(cols) = pRow.Value(pRow.Fields.FindField(pFields.Field(cols).Name)) Next newRow.EndEdit() tmpDT.Rows.Add(newRow) tmpDT.AcceptChanges() pRow = pCur.NextRow Loop PopulateExcelTable(tmpDT) End Sub
Private Sub PopulateExcelTable(ByVal ADO_netDataTable As DataTable) Try Dim xlApp As Excel.Application Dim xlWorkBook As Excel.Workbook Dim xlWorkSheet As Excel.Worksheet xlApp = New Excel.ApplicationClass xlWorkBook = xlApp.Workbooks.Open("c:\test.xls") 'specify your .xls xlWorkSheet = xlWorkBook.Worksheets("sheet1") For i = 0 To ADO_netDataTable.Rows.Count - 2 For j = 0 To ADO_netDataTable.Columns.Count - 1 xlWorkSheet.Cells(i + 1, j + 1) = ADO_netDataTable.Rows(i)(j).ToString Next Next xlWorkSheet.SaveAs("C:\test.xls") 'specify your .xls xlWorkBook.Close() xlApp.Quit() Catch ex As Exception MsgBox(ex.ToString) End Try End Sub
Imports Excel = Microsoft.Office.Interop.Excel Private Sub PopulateExcelTable(ByVal ADO_netDataTable As DataTable) Try Dim xlApp As Excel.Application Dim xlWorkBook As Excel.Workbook Dim xlWorkSheet As Excel.Worksheet xlApp = New Excel.ApplicationClass xlWorkBook = xlApp.Workbooks.Open("c:\test.xls") 'specify your .xls xlWorkSheet = xlWorkBook.Worksheets("sheet1") For i = 0 To ADO_netDataTable.Rows.Count - 2 For j = 0 To ADO_netDataTable.Columns.Count - 1 xlWorkSheet.Cells(i + 1, j + 1) = ADO_netDataTable.Rows(i)(j).ToString Next Next xlWorkSheet.SaveAs("C:\test.xls") 'specify your .xls xlWorkBook.Close() xlApp.Quit() Catch ex As Exception MsgBox(ex.ToString) End Try End Sub
Los miembros registrados pueden publicar, seguir actualizaciones y más. ¿Nuevo aquí? Regístrate gratis.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.