2

Currently I need to change the name of a column depending on specific criteria but to do that I'd like to refer to that column by its ExternalName rather than its name.

aColumn = Document.ActiveDataTableReference.Columns["I_id"].Name 

unfortunately this doesn't work.

aColumn = Document.ActiveDataTableReference.Columns["I_id"].ExternalName 
Keng
  • 52,011
  • 32
  • 81
  • 111

1 Answers1

3

you're very close! ExternalName isn't a property of the DataColumn object, which is, I suppose you've figured out, why your approach isn't working.

in fact, ExternalName is an item represented by the DataColumnProperties.DefaultProperties class. you would actually access this as if it were a custom-defined Column Property like so:

col_ext_name = Document.ActiveDataTableReference.Columns["I_id"].Properties["ExternalName"]

print(col_ext_name)

>> index_id
niko
  • 3,946
  • 12
  • 26
  • thanks! is there an easy way to reference the externalname without knowing the column name? in our setup, the column name is dynamic and can change however the external name will be stable? – Keng Oct 12 '15 at 14:02
  • 1
    I don't think there's a way to directly reference a column by `ExternalName`, but you could use something like `for col in Document.ActiveDataTableReference.Columns: if col.Properties["ExternalName"] = "some_name": do_stuff()` – niko Oct 12 '15 at 17:50
  • that's how I was doing it. just thinking I might have missed something. thanks! – Keng Oct 12 '15 at 18:06