<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def ToHtml(self, columns_order=None, order_by=()):
 """Writes the data table as an HTML table code string. Args: columns_order: Optional. Specifies the order of columns in the output table. Specify a list of all column IDs in the order in which you want the table created. Note that you must list all column IDs in this parameter, if you use it. order_by: Optional. Specifies the name of the column(s) to sort by. Passed as is to _PreparedData. Returns: An HTML table code string. Example result (the result is without the newlines):
 <html><body><table border="1"> <thead><tr><th>a</th><th>b</th><th>c</th></tr></thead> <tbody> <tr><td>1</td><td>"z"</td><td>2</td></tr> <tr><td>"3$"</td><td>"w"</td><td></td></tr> </tbody> </table></body></html> Raises: DataTableException: The data does not match the type. """

    table_template = "<html><body><table border=\"1\">%s</table></body></html>"
    columns_template = "<thead><tr>%s</tr></thead>"
    rows_template = "<tbody>%s</tbody>"
    row_template = "<tr>%s</tr>"
    header_cell_template = "<th>%s</th>"
    cell_template = "<td>%s</td>"

    if columns_order is None:
      columns_order = [col["id"] for col in self.__columns]
    col_dict = dict([(col["id"], col) for col in self.__columns])

    columns_list = []
    for col in columns_order:
      columns_list.append(header_cell_template %
                          html.escape(col_dict[col]["label"]))
    columns_html = columns_template % "".join(columns_list)

    rows_list = []
    # We now go over the data and add each row
    for row, unused_cp in self._PreparedData(order_by):
      cells_list = []
      # We add all the elements of this row by their order
      for col in columns_order:
        # For empty string we want empty quotes ("").
        value = ""
        if col in row and row[col] is not None:
          value = self.CoerceValue(row[col], col_dict[col]["type"])
        if isinstance(value, tuple):
          # We have a formatted value and we're going to use it
          cells_list.append(cell_template % html.escape(self.ToString(value[1])))
        else:
          cells_list.append(cell_template % html.escape(self.ToString(value)))
      rows_list.append(row_template % "".join(cells_list))
    rows_html = rows_template % "".join(rows_list)

    return table_template % (columns_html + rows_html)