某些数据显示在datagridview(Winform)中。我有一个要求以类似的格式(行,列等)邮寄在datagridview中表示的表。我能做到的最简单的是什么?如何使用列标题将其转换为html表格并保留列宽。C#WinForm的DataGridView数据为html
0
A
回答
1
快速谷歌搜索产生这样:How to send DataGridView contents by email。它包括将DGV转换为HTML表格并邮寄给它。
2
我不知道是否有任何框架级别的转换可以发生。但是,迭代栅格行和单元格,并使用宽度就绪的HTML重新创建它应该是一件非常简单的事情。
注销袖口,请原谅其不完整和任何简单的错误,但我认为你可以在这里得到基本的想法。
StringBuilder sb = new SringBuilder();
sb.AppendLine("<table>");
sb.AppendLine(" <tr>");
foreach(DataGridViewColumn column in grid.Columns)
{
sb.AppendLine(" <td>" + column.HeaderText + "</td>");
}
sb.AppendLine(" </tr>");
foreach(DataGridViewRow row in grid.Rows)
{
sb.AppendLine(" <tr>");
foreach(DataGridViewCell cell in row.Cells)
{
sb.AppendLine(" <td width=\"" + cell.Width + "px\">" + cell.Value + "</td>");
}
sb.AppendLine(" </tr>");
}
sb.AppendLine("</table>");
1
我想,如果你搜索,你会发现这个网站
。如果你不这样做......
Do the following
1. Create a stringbuilder, wrap it with htmlTextWriter
2. Create a htmltable, add a header row,
3. Iterate through the gridheaders and add cells, write the width in attributes, write other stuff like font, fontsize, forecolor, backcolor etc if you want
4. Next iterate through the grid rows, add a row each time to table, add cells to row for each grid cells
5. Call the render method passing the html writer
6. Take the string builder out and you have a html table layout output.
相关问题
- 1. DataGridView Winform c#
- 2. WinForm/C# - 在DataGridView中添加数据
- 3. C#中的DataGridView WinForm
- 4. DatagridView搜索Winform - C#
- 5. Winform C#Datagridview paint header
- 6. c#winform datagridview删除toolstripmenu
- 7. 在Winform C中打印DataGridView#
- 8. DatagridView突出事件 - WINFORM C#
- 9. C#Winform数据库
- 10. datagridview的数据c#
- 11. 的WinForm的DataGridView的
- 12. C#Winform的:内嵌的datagridview编辑
- 13. 保存的DataGridView数据到SQL Server数据库的Winform
- 14. C#Winform DataGridView添加的新行值
- 15. winform c的持久数据#
- 16. Winform DatagridView数字列排序
- 17. C#Winform DataGridView内联添加新行
- 18. DataGridView筛选OnClick事件(C#WinForm)
- 19. Datagridview列标题排序 - Winform C#
- 20. 缺少DataGridview滚动条C#WinForm
- 21. C#WinForm DataGridView过滤器暂停
- 22. 与DatagridView同步WinForm
- 23. Datagridview cell forecolor question(winform)
- 24. Winform datagridview不刷新
- 25. 将数据划分为datagridview C#
- 26. 使用datagridview在c#winform中显示2个表的数据更新
- 27. 如何使用c#winform从datagridview中编辑的单元格中获取数据?
- 28. 从另一个Winform更新winform DataGridView
- 29. 如何将ComboBox添加到绑定到数据表的WINFORM datagridview
- 30. DATAFORMAT为DataGridView的数据源
另请参阅:http://stackoverflow.com/questions/16008477/export-datagridview-to-html-page – 2016-09-10 01:50:35