Skip to main content

How to export Full Table fields in a txt file

Frustrated by the lack of a standard function to export the definitions of an IDEA file (except for poorly printed and unusable PDFs), here's a script to export the entire table of field definitions from an IDEA file into a text (txt) file.
It only exports the currently open IDEA file.
The txt file is saved in the root directory of your project.
The filename consists of the table name + " - Table_files_full.txt"
The column separator is "|".
The text file contains the following columns:
- NAME
- CODE_TYPE (internal code for type field)
- TYPE
- LENGTH
- DECIMAL
- FORMULA
- DESCRIPTION
All you have to do is open the txt file and copy its contents into Excel.

You are welcome :)

'*******************************************************************************
' Script Name: Export_Structure_table_EN.iss
' Cible : IDEAScript (13 at least)
' Author : Michel Retourné (mretourne@gmail.com)
'*******************************************************************************

Sub Main
Dim fs As Object, a As Object
Dim db As Object, table As Object, field As Object
Dim i As Integer
Dim sProject As String, sOutputName As String
Dim sTableName As String, sTypeLabel As String, sContent As String
Dim sChar As String, sCleanName As String

Set db = Client.CurrentDatabase
If db Is Nothing Then Exit Sub

' 1. Extraction and cleanup names of the table
sTableName = db.Name
If InStr(sTableName, ".") > 0 Then
sTableName = Left(sTableName, InStr(sTableName, ".") - 1)
End If

' Clean up forbident caracters(Windows : / \ : * ? " < > |)
sCleanName = ""
For i = 1 To Len(sTableName)
sChar = Mid(sTableName, i, 1)
Select Case sChar
Case "/", "\", ":", "*", "?", """", "<", ">", "|"
sCleanName = sCleanName & "_"
Case Else
sCleanName = sCleanName & sChar
End Select
Next i

' 2. Path preparation
sProject = Client.WorkingDirectory()
If Right(sProject, 1) <> "\" Then sProject = sProject & "\"
sOutputName = sProject & sCleanName & " - Table_files_full.txt"

' 3. File creation
Set fs = CreateObject("Scripting.FileSystemObject")
Set a = fs.CreateTextFile(sOutputName, True)

Set table = db.TableDef
a.WriteLine "NAME|CODE_TYPE|TYPE|LENGH|DECIMAL|FORMULA|DESCRIPTION"

' 4. Reading loop (Codes 0-13)
For i = 1 To table.Count
Set field = table.GetFieldAt(i)

Select Case field.Type
Case 0 : sTypeLabel = "Character (Virtual)"
Case 1 : sTypeLabel = "Numeric (Virtual)"
Case 2 : sTypeLabel = "Date (Virtual)"
Case 3 : sTypeLabel = "Character"
Case 4 : sTypeLabel = "Numeric"
Case 5 : sTypeLabel = "Date"
Case 6 : sTypeLabel = "Numeric (Editable)"
Case 7 : sTypeLabel = "Character (Editable)"
Case 8 : sTypeLabel = "Date (Editable)"
Case 9 : sTypeLabel = "Multistate (Editable)"
Case 10 : sTypeLabel = "Boolean (Editable)"
Case 11 : sTypeLabel = "Time"
Case 12 : sTypeLabel = "Time (Editable)"
Case 13 : sTypeLabel = "Time (Virtual)"
Case Else : sTypeLabel = "Unknown (" & field.Type & ")"
End Select

' Mask filter
sContent = field.Equation
If field.Type = 3 Or field.Type = 4 Or field.Type = 11 Then
sContent = ""
End If

a.WriteLine field.Name & "|" & _
field.Type & "|" & _
sTypeLabel & "|" & _
field.Length & "|" & _
field.Decimals & "|" & _
sContent & "|" & _
field.Description
Next i

a.Close
Set a = Nothing : Set fs = Nothing : Set field = Nothing
Set table = Nothing : Set db = Nothing

MsgBox "Successful exportation for : " & sCleanName, 64, "Succes"
End Sub