Page 1 of 1

repeat for each line to help Datagrid to HTM

Posted: Thu Mar 27, 2014 7:27 pm
by DavJans
I need to convert two parts of the datagrid to a functioning htm file. The data I get from my datagrid varies in lines, I will show you what I have so far and maybe someone can help me get into the right direction. It will probably be very simple for one of you.

Here is my approach so far

Code: Select all

   local tFileName, tFileContents, tDate
   put short date into tDate
   replace "/" with "-" in tDate
   put "//mfcpdc2/qc/Metals Fab tracker/Reports/" & tDate  & " " & fld "Job" & " Report.htm" into tFileName
   
   put the dgProp[ "columns" ] of group "DataGrid 1" into tColumnTitles
   replace return with Tab in tColumnTitles
   
   put the dgText of group "DataGrid 1" into tData
this gives me:
trackerjob trackercert trackerpcmk trackerpcmkqt trackerzone trackerrev trackerparts trackercopes trackerholes trackerpitches trackerlength trackercamber trackerfitter trackerclean trackerwelder trackerndt trackerloosepcs trackercoating trackerpn trackerfinalqc trackerfinalqcdate
and
6179 MF17902156 9227 1 9 0 N/A N/A 265 N/A 265 N/A 37 265 N/A N/A N/A Bare N/A 265 3/24/14
in tData

The lines in tData will vary from 1 to X so this is where I'm having an issue getting my head arround it. This here is what my html should look like with only the one line.

<table border="1">
<thead><tr><th title="Field #1">trackerjob</th>
<th title="Field #2">trackercert</th>
<th title="Field #3">trackerpcmk</th>
<th title="Field #4">trackerpcmkqt</th>
<th title="Field #5">trackerzone</th>
<th title="Field #6">trackerrev</th>
<th title="Field #7">trackerparts</th>
<th title="Field #8">trackercopes</th>
<th title="Field #9">trackerholes</th>
<th title="Field #10">trackerpitches</th>
<th title="Field #11">trackerlength</th>
<th title="Field #12">trackercamber</th>
<th title="Field #13">trackerfitter</th>
<th title="Field #14">trackerclean</th>
<th title="Field #15">trackerwelder</th>
<th title="Field #16">trackerndt</th>
<th title="Field #17">trackerloosepcs</th>
<th title="Field #18">trackercoating</th>
<th title="Field #19">trackerpn</th>
<th title="Field #20">trackerfinalqc</th>
<th title="Field #21">trackerfinalqcdate</th>
</tr></thead>
<tbody><tr><td align="right">6179</td>
<td>MF17902156</td>
<td align="right">9227</td>
<td>1</td>
<td align="right">9</td>
<td>0</td>
<td>N/A</td>
<td>N/A</td>
<td align="right">265</td>
<td>N/A</td>
<td align="right">265</td>
<td>N/A</td>
<td align="right">37</td>
<td align="right">265</td>
<td>N/A</td>
<td>N/A</td>
<td>N/A</td>
<td>Bare</td>
<td>N/A</td>
<td align="right">265</td>
<td>3/24/14</td>
</tr>
</tbody></table>

Re: repeat for each line to help Datagrid to HTM

Posted: Thu Mar 27, 2014 7:47 pm
by DavJans
Playing with this I also found another Issue I don't know how to get arround.

Code: Select all

put "<th title="Field #" & lNumber & "">" before line x of tColumnTitles
Dosn't work, there are 2 issues I see I cant " " " quote in a quote causing # to comment out the rest of the line

Re: repeat for each line to help Datagrid to HTM

Posted: Thu Mar 27, 2014 7:54 pm
by Simon
Hi DavJans,
Wicked Fun!
So so many ways to do this.

I guess the start is

Code: Select all

repeat for each word tWord in tColumnTitles
And the second one
""&quote&"<th title="&quote&"Field #"&quote&" & lNumber & "&quote&""&quote&">"&quote&""

Simon
Edit; think you have an extra quote in there

Re: repeat for each line to help Datagrid to HTM

Posted: Thu Mar 27, 2014 8:51 pm
by DavJans
Thank you Simon this will get me a little further i'm sure, Ill post again when I run into more trouble.

Re: repeat for each line to help Datagrid to HTM

Posted: Thu Mar 27, 2014 9:07 pm
by Simon
Here this will help you:
infamous_quotes.zip
LC 6.5
(838 Bytes) Downloaded 281 times
Hopefully you'll figure out how to use it.

Simon

Re: repeat for each line to help Datagrid to HTM

Posted: Thu Mar 27, 2014 9:39 pm
by DavJans
Simon,

I didn't see your second post till just now, I have just finished and It works great, here is what I was able to do with your help

Code: Select all

on mouseUp
   local tFileName, tFileContents, tDate, tDataLineTemp, htmlScript
   put short date into tDate
   replace "/" with "-" in tDate
   put "//mfcpdc2/qc/Metals Fab tracker/Reports/" & tDate  & " " & fld "Job" & " Report.htm" into tFileName
   
   put the dgProp[ "columns" ] of group "DataGrid 1" into tColumnTitles

   replace "tracker" with "" in tColumnTitles
   put "<table border=" & quote & "1" & quote & ">" & return & "<thead><tr>" into htmlScript
   put 1 into lNumber
   repeat with x = 1 to the number of lines of tColumnTitles
      put "<th title=" & quote & "Field #" & lNumber & quote &">" before line x of tColumnTitles
      put "</th>" after line x of tColumnTitles
      put lNumber + 1 into lNumber
   end repeat
   put tColumnTitles after htmlScript
   put return & "</tr></thead>" & return & "<tbody>" after htmlScript
   
   put the dgText of group "DataGrid 1" into tData
   repeat with x = 1 to the number of lines of tData
      put line x of tData into tDataLineTemp
      replace Tab with return in tDataLineTemp
      repeat with y = 1 to the number of lines of tDataLineTemp
         put "<td align=" & quote & "left" & quote & ">" before  line y of tDataLineTemp
         put "</td>" after line y of tDataLineTemp
      end repeat
      put "<tr>" before tDataLineTemp
      put return & "</tr>" & return after tDataLineTemp
      put tDataLineTemp after htmlScript
   end repeat
   put htmlScript into fld fff
   put htmlScript into URL ("file:" & tFileName)
end mouseUp
I thank you so much.

One more question if you have the answer.

Is there anyway to have it automatically open my htm file with a browser after It saves it to disc?

Re: repeat for each line to help Datagrid to HTM

Posted: Thu Mar 27, 2014 10:20 pm
by Simon
hmmm,
launch url ("file:" & tFileName)

Simon