如何把WinForm里的richtextbox的内容转成html格式的? 都1天了,怎么没有人理睬啊,分不够吗? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 如果你的机器上面装了Office,那可以利用Word Application Object来打开RTF文件并另存为HTML或者mhtml格式,这样也能完成RTF到HTML的转换: public void SaveRtfAsHtml(RichTextBox richTextBox,string SaveAsFileName) { //保存成一个临时的rtf文件。 string tempFileName=System.IO.Path.GetTempFileName(); this.richTextBox1.SaveFile(tempFileName+".rtf",System.Windows.Forms.RichTextBoxStreamType.RichText); object Nothing=System.Reflection.Missing.Value; object srcFileName=tempFileName+".rtf"; object dstFileName=SaveAsFileName; object format=Word.WdSaveFormat.wdFormatHTML; //打开刚才保存的rtf文件 Word.Application wordApp=new Word.ApplicationClass(); Word.Document wordDoc=wordApp.Documents.Open(ref srcFileName,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing); //将rtf文件save as成html文件 wordDoc.SaveAs(ref dstFileName,ref format,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing); wordDoc.Close(ref Nothing, ref Nothing, ref Nothing); wordApp.Quit(ref Nothing, ref Nothing, ref Nothing); } 上面那个SaveRtfAsHtml函数主要做了这么几件事情: 1)把一个richtextbox里面的内容存成一个临时的rtf文件。 2)用word application object打开这个临时的rtf文件。 3)另存为用户指定路径的一个html文件。 例如,可以这样使用这个函数: SaveRtfAsHtml(this.richTextBox1,@"c:\mydoc.html"); 关于DataGridView的Sort方法存在的问题 这里用多线程可以吗,应如何写? 问个算法的问题 VS与matlab混合编程 远程桌面连接运行服务端? 再问一次 这个问题 扫描断口的程序 一个有关于C# Form操作excel的问题,大虾帮忙看一下 DataGridView 绑定多个数据源 C#全局变量问题 WMI管理的问题 高分求救:如何向缩小成系统托盘的窗口发消息 如何设置datagrid的currentcell?
{
//保存成一个临时的rtf文件。
string tempFileName=System.IO.Path.GetTempFileName();
this.richTextBox1.SaveFile(tempFileName+".rtf",System.Windows.Forms.RichTextBoxStreamType.RichText); object Nothing=System.Reflection.Missing.Value;
object srcFileName=tempFileName+".rtf";
object dstFileName=SaveAsFileName;
object format=Word.WdSaveFormat.wdFormatHTML; //打开刚才保存的rtf文件
Word.Application wordApp=new Word.ApplicationClass();
Word.Document wordDoc=wordApp.Documents.Open(ref srcFileName,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing); //将rtf文件save as成html文件
wordDoc.SaveAs(ref dstFileName,ref format,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing);
wordDoc.Close(ref Nothing, ref Nothing, ref Nothing);
wordApp.Quit(ref Nothing, ref Nothing, ref Nothing);
} 上面那个SaveRtfAsHtml函数主要做了这么几件事情:
1)把一个richtextbox里面的内容存成一个临时的rtf文件。
2)用word application object打开这个临时的rtf文件。
3)另存为用户指定路径的一个html文件。 例如,可以这样使用这个函数:
SaveRtfAsHtml(this.richTextBox1,@"c:\mydoc.html");