how to create Delphi 4 structure to map column names in XLS to column names in SQL

后端 未结 1 968
青春惊慌失措
青春惊慌失措 2020-12-22 00:26

I have an EXCEL sheet.it has various form-fields that are named as

 “smrBgm133GallonsGross/ smrBgm167GallonsGross “  

and



        
相关标签:
1条回答
  • 2020-12-22 01:11

    What you want to do is map one string to another. You can use a simple string list for that.

    // Declare the variable somewhere, such as at unit scope or as a field
    // of your form class
    var
      ColumnNameMap: TStrings;
    

    // Somewhere else, such as unit initialization or a class constructor,
    // initialize the data structure with the column-name mappings.    
    ColumnNameMap := TStringList.Create;
    ColumnNameMap.Values['Bgm167 GrosGalns DA'] := 'bgm229/ egm229';
    

    // In yet a third place in your code, use something like this to map
    // the column name in your input to the real column name in your output.
    i := ColumnNameMap.IndexOfName(ColumnName);
    if i >= 0 then
      RealColumnName := ColumnNameMap.Values[ColumnName]
    else
      RealColumnName := ColumnName;
    

    Later versions of Delphi have the generic TDictionary class. Use TDictionary<string, string>. The TStrings solution I outlined above will have problems if any of the column names can have equals signs in them, but you can mitigate that by changing the NameValueSeparator property.

    var
      ColumnNameMap: TDictionary<string, string>;
    

    ColumnNameMap := TDictionary<string, string>.Create;
    ColumnNameMap.Add('Bgm167 GrosGalns DA', 'bgm229/ egm229');
    

    if not ColumnNameMap.TryGetValue(ColumnName, RealColumnName) then
      RealColumnName := ColumnName;
    
    0 讨论(0)
提交回复
热议问题