This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision Next revision Both sides next revision | ||
howtos:workwithdata:createsetsfromdatafile [2011/05/06 20:44] shona.weldon |
howtos:workwithdata:createsetsfromdatafile [2011/05/06 21:00] shona.weldon |
||
---|---|---|---|
Line 49: | Line 49: | ||
,Manufacturing Industries,,,," 6,978 ", 0 , 5.9 , 0 , 56.6 ,,,,"7,041", | ,Manufacturing Industries,,,," 6,978 ", 0 , 5.9 , 0 , 56.6 ,,,,"7,041", | ||
</file> | </file> | ||
+ | |||
+ | Here it is as a .csv you can download and open with Excel to see it better and to test the code below | ||
+ | {{:howtos:workwithdata:emtestfile.csv|}} | ||
==== Read from a column ==== | ==== Read from a column ==== | ||
The following code reads the second column as | The following code reads the second column as | ||
+ | |||
+ | <code> | ||
+ | string $importPath, $fileName | ||
+ | buildstring ($importPath, $home, "/testScripts") | ||
+ | |||
+ | buildstring ($fileName, $importPath, "/emtestfile.csv") | ||
+ | localinformant ECemRowTitles[] = create (; object=set, delimiter=",", \ | ||
+ | allowDuplicate=on, \ | ||
+ | elemNamesFromColNum=2, firstLine=9, \ | ||
+ | searchElemName1=",", replaceElemName1="-", \ | ||
+ | searchElemName2="&", replaceElemName2="and", \ | ||
+ | replaceWhiteSpaceInElemName="_" , \ | ||
+ | file=$fileName) | ||
+ | display (ECemRowTitles[]) | ||
+ | export (ECemRowTitles[]; file=$importPath/ECemRowTitles.txt) | ||
+ | </code> | ||
+ | |||
+ | ==== Read from a line/row ==== | ||
+ | The following code reads the second column as | ||
+ | |||
+ | <code> | ||
+ | string $importPath, $fileName | ||
+ | buildstring ($importPath, $home, "/testScripts") | ||
+ | |||
+ | buildstring ($fileName, $importPath, "/emtestfile.csv") | ||
+ | localinformant GHGInvEmType[] = create (; object=set, delimiter=",", \ | ||
+ | allowDuplicate=on, \ | ||
+ | elemNamesFromLineNum=6, firstCol=4, \ | ||
+ | file=$fileName) | ||
+ | |||
+ | display (GHGInvEmType[]) | ||
+ | export (GHGInvEmType[]; file=$importPath/GHGInvEmType.txt) | ||
+ | </code> | ||
+ | |||