是否可以将html字符串输出到csv.
尝试将数据从cms导出到csv和Excel.每个html都可以包含逗号和任何内容.
EG. <p class="myclass">This is an example, of the string</p>
Run Code Online (Sandbox Code Playgroud)
导入在Excel中被破坏,错误的数据出现在错误的列中,尽管前几行是正确的.
我想实现这种格式
col1,col2,col3
"1","<p class="myclass">This is an example, of the string</p>","and more html here"
Run Code Online (Sandbox Code Playgroud)
我尝试过这种事情 - 我在cms中迭代一个内容项,并输出每个属性作为用引号括起来并用逗号分隔的单独的csv数据值.
foreach (var prop in offer.Properties) //.Where(x=>x.Alias != "Id"))
{
var @propValue = prop.Value.ToString().Replace("\"", "'");
// Append comma except last
sb.Append(prop != offer.Properties.Last()
? "\"" + propValue + "\","
: "\"" + propValue + "\"");
}
sb.Append(Environment.NewLine);
Run Code Online (Sandbox Code Playgroud)
更新: 事实证明,这项任务充满了困难.最初的目标是将一组节点及其属性从Umbraco CMS快速导出到Excel文件.我了解到csv可能不是这种类型数据的正确格式,它基于存储在xml中的数据,包括编码的html片段.
在我们的例子中,实现我们想要的最好方法是将导出的数据输出为Excel理解的html表,并保持编辑器友好格式而不是编码的html片段.
Dan*_*len -1
您可以使用HtmlEncode字符串来去掉引号“。
string data = "<p class=\"myclass\">This is an example, of the string</p>";
Server.HtmlEncode(data);
Run Code Online (Sandbox Code Playgroud)
https://msdn.microsoft.com/en-us/library/w3te6wfz(v=vs.110).aspx
编辑:
"<a href="e;http://www.example.com"e;>link</a>","<b>more html</b>"
| 归档时间: |
|
| 查看次数: |
1684 次 |
| 最近记录: |