我只是想在VB.net中将字符串转换为xml文件。我正在获取xmlException 'Data at the root level is invalid. Line 1, position 1.' 'Data at the root level is invalid. Line 1, pos ...
提示:本站收集StackOverFlow近2千万问答,支持中英文搜索,鼠标放在语句上弹窗显示对应的参考中文或英文, 本站还提供 中文繁体 英文版本 中英对照 版本,有任何建议请联系yoyou2525@163.com。
我有一个jquery Rich Textbox编辑器( http://jqueryte.com/ ),它允许最终用户填写其内容以生成Word文档报告。
过程如下:
用户填写内容->将Richtext框内容的HTML保存到数据库中。 ->从数据库中提取存储的HTML内容,并将其转换为RTF字符串,以便在Microsoft Word中打开它。
我尝试将HTML转换为RTF(该函数将接受我的HTML字符串并给出等效的RTF字符串),但是它变得太复杂了,无法操作所有HTML标记。 我进行了很多搜索,但找不到该问题的任何解决方案(至少不是免费的解决方案除外)。
任何帮助将不胜感激。
提前致谢。
一种选择是使用MS Office Word Interop(尽管有些人不赞成)...
string html = "<html><head><style>p{margin:0}</style></head><body style=\"font-family:Arial;\">" + value.Replace("<p> </p>", "<p><br></p>") + "</body></html>";
byte[] htmlBytes = Encoding.UTF8.GetBytes(html);
string htmlPath = Path.GetTempFileName() + ".html";
string rtfPath = htmlPath.Replace(".html", ".rtf");
FileStream fs = new FileStream(htmlPath, FileMode.Create, FileAccess.Write);
fs.Write(htmlBytes, 0, htmlBytes.Length);
fs.Close();
Application word = new Application();
Document doc = word.Documents.Open(htmlPath);
doc.SaveAs(rtfPath, WdSaveFormat.wdFormatRTF);
doc.Close();
word.Quit();
fs = new FileStream(rtfPath, FileMode.Open, FileAccess.Read);
byte[] rtfBytes = new byte[fs.Length];
fs.Read(rtfBytes, 0, rtfBytes.Length);
fs.Close();
string rtf = Encoding.ASCII.GetString(rtfBytes);
Thread thread = new Thread(() =>
{
RichTextBox rtb = new RichTextBox();
rtb.Rtf = rtf;
rtf = rtb.Rtf;
});
thread.SetApartmentState(ApartmentState.STA);
thread.Start();
thread.Join();
return rtf;
我使用RichTextBox和Word的原因是Word的RTF文件非常庞大...当将Word的RTF数据输入到RichTextBox中时,它会过滤掉所有不需要的代码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.