Jump to content


Batch Attribute Table Export

- - - - -

  • Please log in to reply
No replies to this topic




  • Validated Member
  • PipPip
  • 12 posts
  • United States

Howdy Folks!

I'm looking to batch export attribute tables to ASCII format, the same CSV format that would be the result from opening an attribute table, using "OPTION" -> "EXPORT" -> "TEST FILE"....

I've found the following, it's very close, but it's going to a .dbf file, i need CSV....

thanks in advance!!!!


Public Sub ExporttoTable()

On Error GoTo EH

Dim pDoc As IMxDocument
Dim pMap As IMap
Set pDoc = ThisDocument
Set pMap = pDoc.FocusMap

' Get the selected layer or table
Dim pTable As ITable
Dim pDispTab As IDisplayTable
Dim pStAloneTab As IStandaloneTable
Dim pSelItem As IUnknown
Set pSelItem = pDoc.SelectedItem
If pSelItem Is Nothing Then
MsgBox "No Feature feature layer or table selected"
Exit Sub
' For a feature layer or standalonetable
ElseIf TypeOf pSelItem Is IFeatureLayer Or TypeOf pSelItem Is IStandaloneTable Then
Set pDispTab = pSelItem
Set pTable = pDispTab.DisplayTable
MsgBox "Selected item is not a table or feature layer"
Exit Sub
End If

' Get the selection on the table/layer
Dim pSelSet As ISelectionSet
Set pSelSet = pDispTab.DisplaySelectionSet
If pSelSet.Count = 0 Then Set pSelSet = Nothing

' Get the Definition query (if there is one)
Dim pTableDef As ITableDefinition
Dim pQFlt As IQueryFilter
Set pQFlt = New QueryFilter
Set pTableDef = pDispTab
If Not pTableDef.DefinitionExpression = "" Then
pQFlt.WhereClause = pTableDef.DefinitionExpression
End If

' Get the dataset name for the input table
Dim pDataSet As IDataset
Dim pDSName As IDatasetName
Set pDataSet = pTable
Set pDSName = pDataSet.FullName

' Get the output dataset name ready. In this
' case we are creating a dbf file in c:\temp
Dim pWkSpFactory As IWorkspaceFactory
Dim pWkSp As IWorkspace
Dim pWkSpDS As IDataset
Dim pWkSpName As IWorkspaceName
Dim pOutDSName As IDatasetName
Set pWkSpFactory = New ShapefileWorkspaceFactory
Set pWkSp = pWkSpFactory.OpenFromFile("c:\temp", 0)
Set pWkSpDS = pWkSp
Set pWkSpName = pWkSpDS.FullName
Set pOutDSName = New TableName
pOutDSName.Name = "pTable"
Set pOutDSName.WorkspaceName = pWkSpName

' Export (Selection is ignored)
Dim pExpOp As IExportOperation
Set pExpOp = New ExportOperation
pExpOp.ExportTable pDSName, pQFlt, pSelSet, pOutDSName, Application.hWnd

' add the table to map
Dim pName As IName
Dim pNewTable
Dim pStTab As IStandaloneTable
Dim pStTabColl As IStandaloneTableCollection
Set pName = pOutDSName
Set pNewTable = pName.Open
Set pStTab = New StandaloneTable
Set pStTab.Table = pNewTable
Set pStTabColl = pMap
pStTabColl.AddStandaloneTable pStTab


Exit Sub

MsgBox Err.Number & " " & Err.Description

End Sub


0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users