在vb.net中导出到csv [英] export to csv in vb.net

查看:400
本文介绍了在vb.net中导出到csv的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须将div的内容导出到csv文件。我的代码如下:



Dim sb As StringBuilder = New StringBuilder()

 sb.Append ( < table width ='100%'border ='1'class ='data'sinsterssacing ='0' cellpadding ='0'>
sb.Append( < tr>



''''''

'''''

< br $> b $ b'''''

''''''

 sb.Append( < / tr>
sb.Append( < / table>
dvReport.InnerHtml = sb.ToString()



  Dim  stringWrite  As  System.IO.StringWriter = < span class =code-keyword>新 System.IO.StringWriter()
Dim htmlWrite As System.Web.UI.HtmlTextWriter = HtmlTextWriter(stringWrite )

Response.Clear()
Response.AddHeader( content-disposition attachment; filename = ReportFullDump.csv
响应。 Charset =
Response.ContentType = application / CSV

dvReport.RenderControl(htmlWrite)
Response.Write(stringWrite.ToString() )





然而我没有得到所需的输出。输出包含其中的所有html标签。

请使用代码示例建议一些解决方案。

提前谢谢。

解决方案

当你构建div时,为什么要导出div的内容?从数据出现的任何地方导出。当你明显将它们写入输出/ StringBuilder时,为什么你想知道输出中的html标签?并且您已经跳过了代码中您应该编写实际数据的部分。所以最好的答案是:查看CSV文件的外观,并将其写入StringBuilder: http: //en.wikipedia.org/wiki/Comma-separated_values [ ^ ]

I have to export the content of a div to csv file. My code is like below:

Dim sb As StringBuilder = New StringBuilder()

sb.Append("<table width='100%' border='1' class='data' cellspacing='0' cellpadding='0'>")
sb.Append("<tr>")


'''''''
'''''

'''''
''''''

sb.Append("</tr>")
sb.Append("</table>")
dvReport.InnerHtml = sb.ToString()


Dim stringWrite As System.IO.StringWriter = New System.IO.StringWriter()
Dim htmlWrite As System.Web.UI.HtmlTextWriter = New HtmlTextWriter(stringWrite)

Response.Clear()
Response.AddHeader("content-disposition", "attachment;filename=ReportFullDump.csv")
Response.Charset = ""
Response.ContentType = "application/CSV"

dvReport.RenderControl(htmlWrite)
Response.Write(stringWrite.ToString())



However i am not getting the desired output. output contains all the html tags in it.
Please suggest some solution with code examples.
Thanks in advance.

解决方案

Why would you have to export the contents of a div when you're the one building the div? Export from wherever the data comes in the first place. And why are you wondering about html tags in the output when you are obviously writing them yourself into the output/StringBuilder? And you have skipped the part of your code where you are supposedly writing the actual data. So the best answer is: Look up how a CSV file is suppose to look like and write it like that to your StringBuilder: http://en.wikipedia.org/wiki/Comma-separated_values[^]


这篇关于在vb.net中导出到csv的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆