Jump to content

Formatting text from a data cell

Recommended Posts

I was wondering if it is possible to apply different text formatting to a data cell. I received a data file from a client who has a field that has 4 words in each cell. Each word is separated with a few spaces.

Example... "ZZZ 321 AAA 123".

The problem is that I have to apply different formatting to this cell. I need to have ZZZ aligned left, 321 aligned right, AAA aligned left in another column and 123 aligned right also in the other column. To make matters worse.. I need the words in each column underlined. Is this possible without breaking these words into individual fields in the data file.


Another issue will be that I will need to have a black stroked border around these columns that will adjust in size depending on the amount of entrees.


Any help would be much appreciated!!



Link to comment
Share on other sites

There's a table API which helps with this, including the cell alignment. Specifically, you can set the alignment of a cell with the FPTableCell.HAlign property. Take a look at the Frodo Travel tutorial for examples of the the table API.


As for breaking out the individual words, that's what the JavaScript String.split function is for.


Here's something that should get you started:

var text = Field("Your Field Name"); // e.g. "ZZZ 321       AAA   123"
var words = text.split(/\W+/); // split on whitespace

var table = new FPTable;
table.AddColumns(6000, 6000, 6000, 6000); // set column widths here
var row = table.AddRow();
for (var i in words)
   row.Cells[i].SetBorders("Thin", "Black", "Top", "Bottom", "Left", "Right");
   row.Cells[i].HAlign = i % 2 ? "Right" : "Left"; // even-numbered right-aligned
   row.Cells[i].Content = "<u>" + TaggedTextFromRaw(words[i]) + "</u>";
return table.MakeTags();

Note that this only returns a table with a single row. If you want to read from more than one record of data, you'll need to open the data file with ExternalDataFileEx and iterate through all the records in a loop which calls table.AddRow() for each.

Link to comment
Share on other sites


This topic is now archived and is closed to further replies.

  • Create New...