Hello, i am a licensed user of EsyCode Form Generator where there is the possibility to print a a whole B4XTable. Can someone help me with sample code in order to make a printing of a whole B4XTable also via html without use this tool ? Thank In advances
You might want to post a sample project using a B4XTable...
If you look at the data structure(s) used for the B4XTable, you might see how to proceed...
It involves using a loop (or two) to go over the data and then creating a HTML string...
That HTML string can be loaded in a webview, saved in a html-file , uploaded somewhere...
You could use a StringBuilder class to assemble the HTML string...
...
Private Sub ExportToHtml (tbl As B4XTable) As String
Dim HtmlCSS As String = $"
table {width: 100%;border: 1px solid #cef;text-align: left; }
th { font-weight: bold; background-color: #acf; border-bottom: 1px solid #cef; }
td,th { padding: 4px 5px; }
.odd {background-color: #def; }
.odd td {border-bottom: 1px solid #cef; }
a { text-decoration:none; color: #000;}"$
Dim sb As StringBuilder
sb.Initialize
sb.Append("<html><body>").Append(CRLF)
sb.Append("<style type='text/css'>").Append(HtmlCSS).Append("</style>").Append(CRLF)
sb.Append("<table><thead><tr>").Append(CRLF)
For Each col As B4XTableColumn In tbl.Columns
sb.Append("<th>").Append($"$Xml{col.Title}"$).Append("</th>")
Next
sb.Append("</thead>")
sb.Append("</tr>").Append(CRLF)
Dim rs As ResultSet = tbl.sql1.ExecQuery("SELECT * FROM data")
Dim row As Int
Do While rs.NextRow
If row Mod 2 = 0 Then
sb.Append("<tr>")
Else
sb.Append("<tr class='odd'>")
End If
For i = 0 To rs.ColumnCount - 1
sb.Append("<td>")
sb.Append($"$Xml{rs.GetString2(i)}"$)
sb.Append("</td>")
Next
sb.Append("</tr>").Append(CRLF)
row = row + 1
Loop
rs.Close
sb.Append("</table></body></html>")
Return sb.ToString
End Sub
Private Sub ExportToHtml (tbl As B4XTable) As String
Dim HtmlCSS As String = $"
table {width: 100%;border: 1px solid #cef;text-align: left; }
th { font-weight: bold; background-color: #acf; border-bottom: 1px solid #cef; }
td,th { padding: 4px 5px; }
.odd {background-color: #def; }
.odd td {border-bottom: 1px solid #cef; }
a { text-decoration:none; color: #000;}"$
Dim sb As StringBuilder
sb.Initialize
sb.Append("<html><body>").Append(CRLF)
sb.Append("<style type='text/css'>").Append(HtmlCSS).Append("</style>").Append(CRLF)
sb.Append("<table><thead><tr>").Append(CRLF)
For Each col As B4XTableColumn In tbl.Columns
sb.Append("<th>").Append($"$Xml{col.Title}"$).Append("</th>")
Next
sb.Append("</thead>")
sb.Append("</tr>").Append(CRLF)
Dim rs As ResultSet = tbl.sql1.ExecQuery("SELECT * FROM data")
Dim row As Int
Do While rs.NextRow
If row Mod 2 = 0 Then
sb.Append("<tr>")
Else
sb.Append("<tr class='odd'>")
End If
For i = 0 To rs.ColumnCount - 1
sb.Append("<td>")
sb.Append($"$Xml{rs.GetString2(i)}"$)
sb.Append("</td>")
Next
sb.Append("</tr>").Append(CRLF)
row = row + 1
Loop
rs.Close
sb.Append("</table></body></html>")
Return sb.ToString
End Sub
Private Sub ExportToHtml (tbl As B4XTable) As String
Dim HtmlCSS As String = $"
table {width: 100%;border: 1px solid #cef;text-align: left; }
th { font-weight: bold; background-color: #acf; border-bottom: 1px solid #cef; }
td,th { padding: 4px 5px; }
.odd {background-color: #def; }
.odd td {border-bottom: 1px solid #cef; }
a { text-decoration:none; color: #000;}"$
Dim sb As StringBuilder
sb.Initialize
sb.Append("<html><body>").Append(CRLF)
sb.Append("<style type='text/css'>").Append(HtmlCSS).Append("</style>").Append(CRLF)
sb.Append("<table><thead><tr>").Append(CRLF)
For Each col As B4XTableColumn In tbl.Columns
sb.Append("<th>").Append($"$Xml{col.Title}"$).Append("</th>")
Next
sb.Append("</thead>")
sb.Append("</tr>").Append(CRLF)
Dim rs As ResultSet = tbl.sql1.ExecQuery("SELECT * FROM data")
Dim row As Int
Do While rs.NextRow
If row Mod 2 = 0 Then
sb.Append("<tr>")
Else
sb.Append("<tr class='odd'>")
End If
For i = 0 To rs.ColumnCount - 1
sb.Append("<td>")
sb.Append($"$Xml{rs.GetString2(i)}"$)
sb.Append("</td>")
Next
sb.Append("</tr>").Append(CRLF)
row = row + 1
Loop
rs.Close
sb.Append("</table></body></html>")
Return sb.ToString
End Sub
You need the current DataView, just change erel's example
B4X:
Private Sub ExportToHtml (tbl As B4XTable) As String
Dim HtmlCSS As String = $"
table {width: 100%;border: 1px solid #cef;text-align: left; }
th { font-weight: bold; background-color: #acf; border-bottom: 1px solid #cef; }
td,th { padding: 4px 5px; }
.odd {background-color: #def; }
.odd td {border-bottom: 1px solid #cef; }
a { text-decoration:none; color: #000;}"$
Dim sb As StringBuilder
sb.Initialize
sb.Append("<html><body>").Append(CRLF)
sb.Append("<style type='text/css'>").Append(HtmlCSS).Append("</style>").Append(CRLF)
sb.Append("<table>").Append(CRLF)
'sb.Append("<table><thead><tr>").Append(CRLF)
'For Each col As B4XTableColumn In tbl.Columns
'' sb.Append("<th>").Append($"$Xml{col.Title}"$).Append("</th>")
'Next
'sb.Append("</thead>")
'sb.Append("</tr>").Append(CRLF)
Dim rs As ResultSet = tbl.sql1.ExecQuery("SELECT * FROM data")
Dim row As Int
Do While rs.NextRow
If row Mod 2 = 0 Then
sb.Append("<tr>")
Else
sb.Append("<tr class='odd'>")
End If
For i = 0 To rs.ColumnCount - 1
sb.Append("<td>")
sb.Append($"$Xml{rs.GetString2(i)}"$)
sb.Append("</td>")
Next
sb.Append("</tr>").Append(CRLF)
row = row + 1
Loop
rs.Close
sb.Append("</table></body></html>")
Return sb.ToString
End Sub
You can change the ExportToHtml subroutine like this:
limit the query records:
Dim startrow As Int = tbl.FirstRowIndex
Dim numrows As Int = tbl.RowsPerPage
Log("startrow: " & startrow)
Log("numrows: " & numrows)
Dim rs As ResultSet = tbl.sql1.ExecQuery("SELECT * FROM data limit " & startrow & "," & numrows)
This code will take the records from the first (visible) rowindex and the next number of rows per page.
Try it, it might work...
The code in post #9 will not work for you if you use a search string to filter the data to save your html file. If you want to make it work, one way would be to use string builder to construct a string with the IN operator clause and cycle through the visible rows in the B4XTable. Then, include that string in your select query syntax.
The code in post #9 will not work for you if you use a search string to filter the data to save your html file. If you want to make it work, one way would be to use string builder to construct a string with the IN operator clause and cycle through the visible rows in the B4XTable. Then, include that string in your select query syntax.
Dim o() As Object = B4XTable1.BuildQuery(False) 'True to include the page LIMIT in the query.
Dim rs As ResultSet = B4XTable1.sql1.ExecQuery2(o(0), o(1))
Do While rs.NextRow
Log(rs.GetString(B4XTable1.GetColumn("State").SQLID))
Loop
rs.Close
Dim obj() As Object = tbl.BuildQuery(True)
Dim sql As String = obj(0)
Log(sql)
Dim values As List = obj(1)
Log(values)
Dim rs As ResultSet = tbl.sql1.ExecQuery2(sql,values)
I am very familiar with BuildQuery. I use it a lot. It is nothing but a representation of a parameterized query of the table named data making up the in memory SQLite database. What I really wanted to know is: what do you have showing for obj(0) and obj(1) to solve the OP's question in post #5.
I am very familiar with BuildQuery. I use it a lot. It is nothing but a representation of a parameterized query of the table named data making up the in memory SQLite database. What I really wanted to know is: what do you have showing for obj(0) and obj(1) to solve the OP's question in post #5.
Clarity for the other readers.
The first item in the array is the SQL statement and the second item in the array are the arguments or values for the prepared SQL statement.