- Private Function GetGridTableHtml(ByVal grid As Grid) As String
- Dim sb As New StringBuilder()
- sb.Append("<table cellspacing=""0"" rules=""all"" border=""1"" style=""height:100%;width:100%;border-collapse:collapse;"">")
- sb.Append("<tr class=""gvHeader"" >")
- For Each column As GridColumn In grid.Columns
- sb.AppendFormat("<td style=""font-size: 12px; background-color: #CCCCCC; line-height: 26px; text-align: center; vertical-align: middle;height:30px"">{0}</td>", column.HeaderText)
- Next
- sb.Append("</tr>")
- For Each row As GridRow In grid.Rows
- Dim rq = row.Values(row.Values.Length - 1)
- If rq = "" Then
- sb.Append("<tr class=""gvRow"">")
- Else
- sb.Append("<tr class=""gvRow"">")
- End If
- For Each value As Object In row.Values
- Dim html As String = value.ToString()
- If html.Contains("box-grid-static-checkbox") Then
- If html.Contains("box-grid-static-checkbox-uncheck") Then
- html = "×"
- Else
- html = "√"
- End If
- End If
- If html.Contains("<img") Then
- Dim prefix As String = Request.Url.AbsoluteUri.Replace(Request.Url.AbsolutePath, "")
- html = html.Replace("src=""", "src=""" & prefix)
- End If
- If rq = "" Then
- sb.AppendFormat("<td style=""font-size: 12px;line-height: 26px; text-align: center; vertical-align: middle;height:26px"">{0}</td>", html)
- Else
- sb.AppendFormat("<td style=""background-color:lightgreen;text-align: center; vertical-align: middle;height:26px;font-size: 12px;"">{0}</td>", html)
- End If
- Next
- sb.Append("</tr>")
- Next
- sb.Append("</table>")
- Return sb.ToString()
- End Function
复制代码 以上代码对导出excel的每行设置了行高,设置了背影色,文字水平居中,并可根据不同的内容更改背景色,我导出的内容最后一列是日期格式的,如果日期不为空则更改背景色.导出后的效果如下图.
|