Page 1 of 2 12 Last
  1. #1

    CSV Table Importer MK

    This extension allows you to import the contents of a Comma Separated Values(CSV) file into either:
    1. Formatted text control. Importing the CSV into a formatted text control will create it as a formatted table.
    2. Rollable table. Importing into a blank rollable table entry will generate all of the rows and columns for the rollable table.



    Note: This extension is based on the CSV Table Paster extension by lokiare which is available here: https://www.fantasygrounds.com/forum...Access-release Much thanks to him.


    To use:
    Outside of FG
    1. Open your CSV file in a text editor such as notepad.
    2. Copy the contents of the CSV to the clipboard using CTRL+A, CTRL+C or equivalent.


    Within FG
    1. Click on the dark green hammer and gear icon at the top right of the desktop. This will open the import window.
    2. Open the window that contains the formatted text field you want to import the CSV into. If you are importing a rollable table, just open a blank table entry.
    3. If you are importing into a formatted text field, type "#table#" without quotes on a new line where you want the table to appear. Close the entry, then re-open it.
    4. Click on the "Convert Clipboard" button on the import window


    Demo Video: https://youtu.be/Cmeg7ic2ZaI

    Changes from original version
    • Should work with all CoreRPG and 5e ruleset formatted text fields. Can be easily extended to support other rulesets as well.
    • changed the background of the instruction text to make it more readable.
    • replaced CSV parsing code so that it handles quoted strings properly. To produce a quote character " into an entry, it must be escaped by an additional ".

    So this CSV Screenshot_2.jpg
    Will produce this output Screenshot_3.jpg

    Supported Rulesets: CoreRPG, 5E, 2E, PFRPG, PFRPG2, Savage worlds

    Version notes
    v1.0
    • initial release

    v1.1
    • Added support for the following rulesets 2E, PFRPG, PFRPG2, SavageWorlds

    v1.2
    • Added the ability to skip leading and trailing spaces.

    v1.3
    • Added the option to select other delimiters. Default is comma. Can now select pipe "|", semi-colon or colon as the delimiter

    v1.3a
    • Update for compatibility with Unity.
    Attached Files Attached Files
    Last edited by mattekure; September 15th, 2019 at 15:50.

  2. #2

    Join Date
    Apr 2007
    Location
    Mississippi, USA
    Posts
    490
    This extension uses code from my extension with permission from me to use it.
    For support post in the House of Healing or email [email protected]
    Have a suggestion for a feature? Go here http://fg2app.idea.informer.com/

  3. #3

    Join Date
    Apr 2008
    Location
    Virginia Beach
    Posts
    2,998

    Adding a string option for the CSV Separator

    Here's how you can do it:

    In your onInit routine, place the following code:
    Code:
    	OptionsManager.registerOption2("GENPUNC", false, "option_header_game", "option_label_GENPUNC", "option_entry_stringer", 
    			{ baselabel = "option_val_comma", baseval = ",", default = "," });
    'GENPUNC' or whatever you want to use instead of that will be the reference you later use to get the value of the setting.
    The false parameter tells the option manager it is an option that should be stored in the campaign database (true causes it to be stored in the campaign registry).
    'option_header_game' tells the Options Manager to put the setting into the games settings area (see the strings\strings_utility.xml file for the constants you can use to control where the option appears)
    'option_label_GENPUNC' tells the Options Manager to look for this string resource for the label you want assigned on the options manager. It looks like this:

    Code:
    	<string name="option_label_GENPUNC">Generators: Punctuation to separate items in a series</string>
    'option_entry_stringer' is the windowless you want to use to handle the interaction with the user. There is not currently a built-in routine to handle what you are looking for, but this code below is fully tested and will handle a string option setting that is free-form:

    Code:
    	<windowclass name="option_entry_stringer">
    		<margins control="0,0,0,2" />
    		<script>
    			local sOptionKey = nil;
    			local sDefaultVal = "";
    			local enable_update = true;
    			
    			function setLabel(sLabel)
    				label.setValue(sLabel);
    			end
    			
    			function setReadOnly(bValue)
    				stringer.setReadOnly(bValue);
    			end
    			
    			function initialize(sKey, aCustom)
    				sOptionKey = sKey;
    				
    				if sOptionKey then
    					if aCustom then
    						sDefaultVal = aCustom.baseval or "";
    					end
    
    					enable_update = false;
    					local sValue = OptionsManager.getOption(sOptionKey);
    					stringer.setValue(sValue);
    					enable_update = true;
    				end
    			end
    			
    			function onHover(bOnWindow)
    				if bOnWindow then
    					setFrame("rowshade");
    				else
    					setFrame(nil);
    				end
    			end
    			
    			function onValueChanged()
    				if enable_update and sOptionKey then
    					local sValue = stringer.getValue();
    					OptionsManager.setOption(sOptionKey, sValue);
    				end
    			end
    		</script>
    The last parameter is an array passed to control behavior. Since this is a freeform string, I don't set up a series of labels, but you could conceivably setup a series of "|" (pipe) delimited string resource names of labels to use. (or lablesraw if you don't want resources).
    What I have up there will make the default be a comma, and the 'option_val_comma' is a string resource you set up in your xml file like this:

    Code:
    	<string name="option_val_comma">,</string>
    Where you need to get the current CSV setting, you would do something like this:

    Code:
    local sSeparator=OptionsManager.getOption("GENPUNC");
    If you needed to (not sure why you would need to), you could use the Options Manager to register a callback to your code if the value of your setting changes. (see the Options Manager registerCallback and unregisterCallback routines).

  4. #4

  5. #5

    Join Date
    Apr 2008
    Location
    Virginia Beach
    Posts
    2,998
    You are very welcome sir

  6. #6

    Join Date
    Jun 2013
    Location
    Isanti, MN
    Posts
    2,803
    Bug: If there is whitespace between the comma and a following " then it ignores the quotes.

  7. #7
    Quote Originally Posted by Andraax View Post
    Bug: If there is whitespace between the comma and a following " then it ignores the quotes.
    This isnt actually a bug as this is not following the CSV standard. https://tools.ietf.org/html/rfc4180

    CSV fields are separated by a comma and either begin with a double quote, or not. If a CSV field does not begin with a double quote, it cannot contain quote characters within it. In your example, the field is beginning with a space, and so the entire field should not contain any quote characters. If a CSV field does begin with a double quote, it can contain a quote symbol by escaping it with another double quote. For example. value1,"value2""stillvalue2",value3 where the middle term evaluates to value2"stillvalue2

  8. #8

    Join Date
    Jun 2013
    Location
    Isanti, MN
    Posts
    2,803
    You seem to have skipped the part that says:

    While there are various specifications and implementations for the CSV format (for ex. [4], [5], [6] and [7]), there is no formal specification in existence, which allows for a wide variety of interpretations of CSV files. This section documents the format that seems to be followed by most implementations:
    So, while this documents the most common format, it is not a formal specification.

  9. #9
    LordEntrails's Avatar
    Join Date
    May 2015
    Location
    GMT -7
    Posts
    7,883
    Blog Entries
    9
    Quote Originally Posted by Andraax View Post
    So, while this documents the most common format, it is not a formal specification.
    Well, I guess one way to think of it is if the author of an extension wants it to work one way and its working that way, then it's working correctly.

    Of course someone can always ask for an extension to be coded differently, but that's different than saying it not working correctly.

    Current Projects: Ultimate Undermountain (NYDUM)
    Community Contributions: Gemstones, 5E Quick Ref Decal, Adventure Module Creation, Dungeon Trinkets
    DMsGuild Content: Balance Disturbed (Adventure), Dungeon Room Descriptions
    FG Product Reviews: Virtual Scribe Reviews

  10. #10
    Quote Originally Posted by Andraax View Post
    You seem to have skipped the part that says:



    So, while this documents the most common format, it is not a formal specification.
    I did not in fact skip that part. Yes, it is not a formal specification but attempting to account for every possible implementation and undocumented version of the file format is not really productive. So I wrote to the most common format.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Log in

Log in