Class CsvSpreadsheet

Index Home MAE > MAE Architecture > MAE Data Types > Class Index > Class CsvSpreadsheet

Summary
Public Methods
CsvSpreadsheet(filename)
inline string getFilename() const
bool setFilename(filename)
inline string getName() const
inline CsvSpreadsheet& setName(newName)
bool load(offsetRow, offsetColumn)
bool load(fh, offsetRow, offsetColumn)
bool save()
bool save(fh)
inline string toString()
string& toString(content)
bool valid() const
CsvSpreadsheet& setColumns(count)
inline int getColumnCount() const
bool columnEmpty(column) const
static string getColumnLabel(column)
static int getColumnPos(column)
static string getCellLabel(row, column)
static string getRangeLabel(row1, column1, row2, column2)
static int getColumnFromLabel(address)
CsvSpreadsheet& setRows(count)
inline int getRowCount() const
bool rowEmpty(row) const
static int getRowFromLabel(address)
static void getRowColumnFromAddress(address, row, column)
static void getRowColumnFromAddressRange(address, row1, column1, row2, column2)
bool setCell(row, column, value)
inline bool setCell(row, column, value)
inline bool setCell(address, value)
bool setCell(row, column, value)
inline bool setCell(row, column, value)
inline bool setCell(address, value)
bool setCell(row, column, value)
inline bool setCell(row, column, value)
inline bool setCell(address, value)
string getCell(row, column) const
inline string getCell(row, column) const
inline string getCell(address) const
float getCellFloat(row, column) const
inline float getCellFloat(row, column) const
inline float getCellFloat(address) const
int getCellInt(row, column) const
inline int getCellInt(row, column) const
inline int getCellInt(address) const
HashArray getRow(row, startColumn, stopColumn) const
HashArray getColumn(column, startRow, stopRow) const
inline HashArray getColumn(column, startRow, stopRow) const
void clear(range)
bool empty(range)
float sum(range)
string findCellWithValue(value, startRow, startColumn, stopRow, stopColumn)
string findCellWithValue(value, startRange, stopRange)
inline int findColumnWithValue(value, row, startColumn, stopColumn)
inline int findRowWithValue(value, startRow, stopRow, column)
StringSet findCellsWithValue(value, startRow, startColumn, stopRow, stopColumn)
StringSet findCellsWithValue(value, startRange, stopRange)
bool insertRow(rowNubmer)
bool insertColumn(column)
inline bool insertColumn(column)
bool deleteRow(rowNumber)
bool deleteColumn(column)
inline bool deleteColumn(column)
static void dumpRow(row, outf)
inline void setSeparator(sep)
inline char getSeparator() const
static HashArray fgetcsv(f, startOffset, separator)
static int fputcsv(f, fields, separator)
Private Properties
Private Methods
static long findQuote(text, fh, lastpos, separator)

#include <CsvSpreadsheet.h >

Summary

A class to read a CSV file and peform spreadsheet manipulations on it.

A cell address is a string comprised of a column followed by a row, e.g. D20.

Columns are alphabetically identified:  A..Z, AA..AZ, BA..BZ, etc. AAA..AAZ, ABA..ABZ, ...

Row are always positive integers.  0 is an invalid row.

A range is a cell address followed by ".." followed by another cell address.

In a range, left-right and up-down order is not required.

Public Methods

CsvSpreadsheet(filename)

string filename

a path in the file system where the CSV file can be found.  The file does not request the .csv extension as long as it is in CSV format.

Default value: ""


Instantiate this class - start by reading first line of CSV db

to get the list of fields.  Note that header case does not matter

for searches, but results are always returned using the header case

from the CSV file, regardless of field case in the query.

Return value: (an instance of this class).

inline string getFilename() const

bool setFilename(filename)

string filename


inline string getName() const

inline CsvSpreadsheet& setName(newName)

string newName


bool load(offsetRow, offsetColumn)

int offsetRow

Default value: 0

int offsetColumn

Default value: 0


bool load(fh, offsetRow, offsetColumn)

FILE* fh

int offsetRow

Default value: 0

int offsetColumn

Default value: 0


bool save()

bool save(fh)

FILE* fh


inline string toString()

string& toString(content)

string& content


bool valid() const

Call after instantiating to ensure this is a valid CSV db.

Return value: true if CSV file found and with the correct format; false if CSV file not found or incorrect format

CsvSpreadsheet& setColumns(count)

int count


inline int getColumnCount() const

bool columnEmpty(column) const

int column


static string getColumnLabel(column)

int column


static int getColumnPos(column)

string column


static string getCellLabel(row, column)

int row

int column


row from 1+, column from 1+

static string getRangeLabel(row1, column1, row2, column2)

int row1

int column1

int row2

int column2


static int getColumnFromLabel(address)

string address


CsvSpreadsheet& setRows(count)

int count


inline int getRowCount() const

bool rowEmpty(row) const

int row


static int getRowFromLabel(address)

string address


static void getRowColumnFromAddress(address, row, column)

string address

int& row

int& column


static void getRowColumnFromAddressRange(address, row1, column1, row2, column2)

string address

int& row1

int& column1

int& row2

int& column2


bool setCell(row, column, value)

int row

int column

string value


inline bool setCell(row, column, value)

int row

string column

string value


inline bool setCell(address, value)

string address

string value


bool setCell(row, column, value)

int row

int column

int value


inline bool setCell(row, column, value)

int row

string column

int value


inline bool setCell(address, value)

string address

int value


bool setCell(row, column, value)

int row

int column

float value


inline bool setCell(row, column, value)

int row

string column

float value


inline bool setCell(address, value)

string address

float value


string getCell(row, column) const

int row

int column


row from 1+, column from 1+

inline string getCell(row, column) const

int row

string column


inline string getCell(address) const

string address


float getCellFloat(row, column) const

int row

int column


inline float getCellFloat(row, column) const

int row

string column


inline float getCellFloat(address) const

string address


int getCellInt(row, column) const

int row

int column


inline int getCellInt(row, column) const

int row

string column


inline int getCellInt(address) const

string address


HashArray getRow(row, startColumn, stopColumn) const

int row

int startColumn

Default value: 0

int stopColumn

Default value: 0


HashArray getColumn(column, startRow, stopRow) const

int column

int startRow

Default value: 0

int stopRow

Default value: 0


inline HashArray getColumn(column, startRow, stopRow) const

string column

int startRow

Default value: 0

int stopRow

Default value: 0


void clear(range)

string range


bool empty(range)

string range


float sum(range)

string range


string findCellWithValue(value, startRow, startColumn, stopRow, stopColumn)

string value

int startRow

int startColumn

int stopRow

int stopColumn


string findCellWithValue(value, startRange, stopRange)

string value

string startRange

string stopRange

Default value: ""


inline int findColumnWithValue(value, row, startColumn, stopColumn)

string value

int row

int startColumn

int stopColumn


inline int findRowWithValue(value, startRow, stopRow, column)

string value

int startRow

int stopRow

int column


StringSet findCellsWithValue(value, startRow, startColumn, stopRow, stopColumn)

string value

int startRow

int startColumn

int stopRow

int stopColumn


StringSet findCellsWithValue(value, startRange, stopRange)

string value

string startRange

string stopRange

Default value: ""


bool insertRow(rowNubmer)

int rowNubmer


Add another row to the spreadsheet. The new row will have the row number provided.

@param rowNumber - the new row number to create

Return value: true if successful

bool insertColumn(column)

int column

the new position to create, where A is 1, B is 2, etc.


Add another column to the spreadsheet. The new column will have the column position provided.

Return value: true if successful

inline bool insertColumn(column)

string column

the new column letter to create, e.g. A, B, C, etc.


Add another column to the spreadsheet. The new column will have the column letter provided.

Return value: true if successful

bool deleteRow(rowNumber)

int rowNumber


bool deleteColumn(column)

int column


inline bool deleteColumn(column)

string column


static void dumpRow(row, outf)

const HashArray& row

a db row as returned by findRecord().

FILE* outf

Default value: stdout


Debugging utility - output a single row from the database

Return value: An HTML table for a single row of data.

inline void setSeparator(sep)

char sep


inline char getSeparator() const

static HashArray fgetcsv(f, startOffset, separator)

FILE* f

int startOffset

Default value: 1

char separator

Default value: '


static int fputcsv(f, fields, separator)

FILE* f

const HashArray& fields

char separator

Default value: '


Private Properties

string csvfilename

Filename of loaded spreadsheet

string name

spreadsheet name (optional)

char separator

Delimiter for file I/O. Default: comma

bool ssLoaded

Flag: spreadsheet has been loaded from a file

int columnCount

Size of spreadsheet

int rowCount

Size of spreadsheet

vector <HashArray > data

Contents of spreadsheet


Private Methods

static long findQuote(text, fh, lastpos, separator)

string& text

FILE* fh

int lastpos

char separator


Supports fgetcsv()