DICE PACKS BUNDLE
Page 1 of 10 123 ... Last
  1. #1

    CSV Table Importer MK

    Now Available on the Fantasy Grounds Forge: https://forge.fantasygrounds.com/shop/items/34/view

    This extension allows you to import the contents of a Comma Separated Values(CSV) file into a Formatted text control. Importing the CSV into a formatted text control will create it as a formatted 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.

    Usage:
    Usage: Open the window where the text will be imported. In the formatted text field, add a line with "#table#" as the only text on the line. Click the Import CSV button below and select your CSV file.



    If the table is not importing, try closing the record and reopening it, then Importing the CSV again.







    Supported Rulesets: CoreRPG, 5E, 2E, PFRPG, PFRPG2, Savage worlds
    Last edited by mattekure; May 5th, 2022 at 21:34.
    For support with any of my extensions, visit my #mattekure-stuff channel on Rob2e's discord https://discord.gg/rob2e

  2. #2

    Join Date
    Apr 2007
    Location
    Mississippi, USA
    Posts
    1,089
    This extension uses code from my extension with permission from me to use it.

  3. #3

    Join Date
    Apr 2008
    Location
    Virginia Beach
    Posts
    3,096

    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
    That was amazing Bidmaron, thanks. Excellent documentation
    For support with any of my extensions, visit my #mattekure-stuff channel on Rob2e's discord https://discord.gg/rob2e

  5. #5

    Join Date
    Apr 2008
    Location
    Virginia Beach
    Posts
    3,096
    You are very welcome sir

  6. #6

    Join Date
    Jun 2013
    Location
    Isanti, MN
    Posts
    2,922
    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
    For support with any of my extensions, visit my #mattekure-stuff channel on Rob2e's discord https://discord.gg/rob2e

  8. #8

    Join Date
    Jun 2013
    Location
    Isanti, MN
    Posts
    2,922
    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
    -7 UTC
    Posts
    17,236
    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.

    Problems? See; How to Report Issues, Bugs & Problems
    On Licensing & Distributing Community Content
    Community Contributions: Gemstones, 5E Quick Ref Decal, Adventure Module Creation, Dungeon Trinkets, Balance Disturbed, Dungeon Room Descriptions
    Note, I am not a SmiteWorks employee or representative, I'm just a user like you.

  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.
    For support with any of my extensions, visit my #mattekure-stuff channel on Rob2e's discord https://discord.gg/rob2e

Thread Information

Users Browsing this Thread

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

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
STAR TREK 2d20

Log in

Log in