dreimer Posted March 27, 2015 Share Posted March 27, 2015 (edited) var XDF = new ExternalDataFileEx("61786_List_New.csv", "\,"); var firstItemColumn = 11; // Field Number Minus One var myTable = new FPTable; myTable.AddColumns(4800, 10000, 20000, 4800); myTable.AddRow() // This adds the header row below for (var row = firstItemColumn; row <= XDF.fieldCount; row++) { var itemCount = Int(XDF.GetFieldValue(CurrentRecordNumber(), row)); if (itemCount) { var thisRow = myTable.AddRow(); for (var cell = 0; cell < myTable.Columns.length; cell++) { var thisCell = thisRow.Cells[cell]; thisCell.SetBorders("Thin","Black","Top","Bottom","Right","Left"); thisCell.HAlign = "Center"; thisCell.VAlign = "Middle"; thisCell.Margins = { Top:40, Bottom:40 }; } var header = XDF.GetFieldValue(0, row); thisRow.SetContents(header.substr(0,2), header.substr(3,20), header.substr(21), itemCount); } } myTable.Rows[0].Type = "Header"; myTable.Rows[0].Cells[0].Font = "Myriad Pro Black"; myTable.Rows[0].Cells[0].PointSize = 12; myTable.Rows[0].Cells[0].HAlign = "Center"; myTable.Rows[0].Cells[0].Content = "CODE"; myTable.Rows[0].Cells[1].Font = "Myriad Pro Black"; myTable.Rows[0].Cells[1].PointSize = 12; myTable.Rows[0].Cells[1].HAlign = "Center"; myTable.Rows[0].Cells[1].Content = "DESCRIPTION1"; myTable.Rows[0].Cells[2].Font = "Myriad Pro Black"; myTable.Rows[0].Cells[2].PointSize = 12; myTable.Rows[0].Cells[2].HAlign = "Center"; myTable.Rows[0].Cells[2].Content = "DESCRIPTION2"; myTable.Rows[0].Cells[3].Font = "Myriad Pro Black"; myTable.Rows[0].Cells[3].PointSize = 12; myTable.Rows[0].Cells[3].HAlign = "Center"; myTable.Rows[0].Cells[3].Content = "QTY"; return myTable.MakeTags();So I have posted my rule that I have and I want to be able to change this line to split my header data into two columns where the pipe is. thisRow.SetContents(header.substr(0,2), header.substr(3,20), header.substr(21), itemCount); Right now I just tried to split at 20 characters but if I can somehow use the pipe to split it would be great. TIA I attached the data if it helps to see what I am trying. I have also attached the output if I only use three columns. Trying to modify the rule to make four columns and use the pipe to separate the field into the two columns.61786_List_New.zipOutput.pdf Edited March 27, 2015 by dreimer Quote Link to comment Share on other sites More sharing options...
step Posted March 27, 2015 Share Posted March 27, 2015 The impression I get from your data is that columns 1 and 2 (CODE & DESCRIPTION1) are separated by an underscore and columns 2 and 3 (DESCRIPTION1 & DESCRIPTION2) are separated by a pipe character. The way I would do what you're attempting is: 1. Replace the underscore with a pipe character. 2. Split the string using the pipe character as a delimiter. This will give you an array of your three column values. 3. Use the trim function to remove any extra spaces before/after the actual text. 4. Assign the values of that resulting array to the contents of the table. Here's an example: . . . var header = XDF.GetFieldValue(0, row); var [code,desc1,desc2] = header.replace('_','|').split('|').map(function(s){return Trim(s);}); thisRow.SetContents(code, desc1, desc2, itemCount); Quote Link to comment Share on other sites More sharing options...
dreimer Posted March 27, 2015 Author Share Posted March 27, 2015 Exactly what I needed as always! Thank You! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.