InDesign SDK  20.5
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
DataUpdaterCSVFileHelper Class Reference

#include <DataUpdaterCSVFileHelper.h>

Public Member Functions

 DataUpdaterCSVFileHelper ()
 
virtual ~DataUpdaterCSVFileHelper ()
 
ErrorCode Load (const IDFile &file)
 

Public Attributes

K2Vector< WideStringfKeys
 
K2Vector< WideStringfFields
 
K2Vector< WideStringfValues
 
WideString fTableName
 
PMString fFileName
 

Detailed Description

From SDK sample; DataUpdaterCSVFileHelper is a helper class for handling CSV files.

A naming convention has been adopted for CSV filenames so you can have several files within the same folder that give values for the same table of data. The naming convention is:

Table[_Qualifier][.csv]

where:

[] - optional 

So Inventory_Apr.csv and Inventory_May.csv, would all specify values from the same table of data "Inventory".

For example consider the file "Inventory_Apr.csv" with contents:


    SKU, Price, Description

    A175, ?0, Electric Drill

    B456, ?, Hammer

    A767, ?, Screwdriver

The first line contains the names of the fields in the file. These are loaded into the fFields member. The first column contains the key for each record and must be unique. These are loaded into the fKeys member. All values, including keys, are loaded into the fValues member.

Note that all the values from the CSV file are cached in this class.

Constructor & Destructor Documentation

DataUpdaterCSVFileHelper::DataUpdaterCSVFileHelper ()

Constructor.

DataUpdaterCSVFileHelper::~DataUpdaterCSVFileHelper ()
virtual

Destructor.

Member Function Documentation

ErrorCode DataUpdaterCSVFileHelper::Load (const IDFilefile)

Load the given CSV file.

Parameters
fileCSV file containing data to be loaded.
Returns
kSuccess on success, kDataUpdaterOpenFileErrorCode if file could not be opened, kDataUpdaterFileFormatErrorCode if file is not a CSV file, other ErrorCode otherwise.

Member Data Documentation

K2Vector<WideString> DataUpdaterCSVFileHelper::fFields

Fields in the first line of the CSV file are loaded here. The first line contains the names of the fields in the file.

PMString DataUpdaterCSVFileHelper::fFileName

The CSV file name.

K2Vector<WideString> DataUpdaterCSVFileHelper::fKeys

The first field per line in the CSV file is loaded here. This field contains the key for the CSV file record and should be unique in the CSV file.

WideString DataUpdaterCSVFileHelper::fTableName

The name of the table the CSV file represents derived from the CSV file naming convention described above.

K2Vector<WideString> DataUpdaterCSVFileHelper::fValues

All fields in the second and subsequent lines of the CSV file are loaded here.