UE4 not recognizing "Name" Column in csv

I am working on several CSV files using the same class derived from FTableRowBase, in which I specify a “Name” column containing an FString. However, every time I try to import any of the CSV files using this class I get the same error message “Expected column ‘Name’ not found in input.” The imported result has two “Name” columns, one is empty, and the other has all the name values from the CSV file. What am I doing wrong?

1 Like

It’s because the first column is implicitly the name of the rows. So it’s getting confused by the fact that it’s expecting the first column to not have a header. You can look at the code in UDataTable::GetTablePropertyArray to see how it works specifically.

1 Like

Thanks for the help, that fixed it.

How does the first column not have a header? The original CSV file? The Struct? The struct cannot have a blank field name. Leaving the CSV file blank does nothing.

v4.26

Best approach working for me:

  1. Create struct
  2. Create array using this struct (empty it ok too)
  3. Export array as csv - look how is constructed (header)
  4. Make csv
  5. Import to UE4

And name should be unique for each row if you want all array to be imported.

just additional with examples to Ben’s answer.

It’s means:

  1. UStruct haven’t to contains “name of the rows”;

  2. csv file must contain empty header for “name of the rows”.

  3. below empty headers each row must have name.

csv :

    ,Name,SName,Address1,Address2,ShortAddress,Index
    1,John,Doe,120 jefferson st.,Riverside, NJ,8075
    2,Jack,McGinnis,220 hobo Av.,Phila, PA,9119
    3,"John ""Da Man""",Repici,120 Jefferson St.,Riverside, NJ,8075
    4,Stephen,Tyler,"7452 Terrace ""At the Plaza"" road",SomeTown,SD,91234
    5,,Blankman,,SomeTown, SD,298
    6,"Joan ""the bone"", Anne",Jet,"9th, at Terrace plc",Desert City,CO,123

UStruct :

USTRUCT(BlueprintType)
struct FAddressTableStruct
{
	GENERATED_BODY();

	FAddressTableStruct(){}

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "MQTypes")
	FString Name;
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "MQTypes")
	FString SName;
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "MQTypes")
	FString Address1;
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "MQTypes")
	FString Address2;
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "MQTypes")
	FString ShortAddress;
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "MQTypes")
	FString Index;
};

code :

UDataTable* ULocalDataLoader::ImportAddressTableFromFile(const FString& FileDir)
{
	UDataTable* AddressTable = NewObject<UDataTable>(this, UDataTable::StaticClass(), FName(TEXT("AddressDataTable")));
	AddressTable->RowStruct = FAddressTableStruct::StaticStruct();

	FString CSVPath = FPaths::ProjectContentDir() + FileDir;

	if (FPaths::FileExists(CSVPath))
	{
		FString CSVString;		
		FFileHelper::LoadFileToString(CSVString, *CSVPath);

		TArray<FString> OutProblems = AddressTable->CreateTableFromCSVString(CSVString);
		for (auto Problem : OutProblems) 
		{
			UE_LOG(LogTemp, Warning, TEXT("Problem with Imported CSV : %s"), *Problem);
		}
	} 
	else 
	{
		UE_LOG(LogTemp, Error, TEXT("CSV File %s not found!"), *CSVPath);
	}

	return AddressTable;
}