某些数据显示在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. DatagridView搜索Winform - C#
- 4. 在Winform C中打印DataGridView#
- 5. C#Winform的:内嵌的datagridview编辑
- 6. 保存的DataGridView数据到SQL Server数据库的Winform
- 7. C#Winform DataGridView添加的新行值
- 8. Winform DatagridView数字列排序
- 9. winform c的持久数据#
- 10. C#,Winform,将数据插入本地数据库并在DataGridVIew中查看
- 11. C#Winform DataGridView内联添加新行
- 12. DataGridView筛选OnClick事件(C#WinForm)
- 13. 与DatagridView同步WinForm
- 14. Datagridview cell forecolor question(winform)
- 15. 将数据划分为datagridview C#
- 16. 如何使用c#winform从datagridview中编辑的单元格中获取数据?
- 17. DATAFORMAT为DataGridView的数据源
- 18. 如何将ComboBox添加到绑定到数据表的WINFORM datagridview
- 19. C#:Datagridview不显示数据
- 20. C#/ Winform:输入数据到HTML页面,提交表格
- 21. Winform c中的数据绑定错误#
- 22. DataGridView自定义排序WinForm
- 23. winform - 合并datagridview标题
- 24. 在Winform中编辑DataGridView
- 25. 为什么我不能插入我的数据? C#的winform
- 26. 如何有效地将数据填充到winform DataGridView异步?
- 27. C#的数据表,词典,datagridview的
- 28. C#的winform的datagridview细胞点击TabControl的页
- 29. Datagridview数据源为空
- 30. vb.net datagridview数据集作为数据源
另请参阅:http://stackoverflow.com/questions/16008477/export-datagridview-to-html-page – 2016-09-10 01:50:35