我的页面中有一个html编辑器。我希望将文本存储在word文档中,其格式如粗体,斜体等。我使用此代码在word文档中写入..
object strTextToWrite = txtdocument.Text.Trim();
oWordApplic = new Word.ApplicationClass();
object missing = System.Reflection.Missing.Value;
oDoc = oWordApplic.Documents.Add(ref missing, ref missing, ref missing, ref missing);
oDoc.Activate();
string test = StripTagsCharArray(txtdocument.Text);
string test2 = test.Replace(" ", " ");
oWordApplic.Selection.TypeText(test2);
object path =Server.MapPath("~/Documents/"+txtfrom_name.Text + ".doc");
oDoc.SaveAs(ref path, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing);
oDoc.Close(ref missing, ref missing, ref missing);
oWordApplic.Application.Quit(ref missing, ref missing, ref missing);
分割功能是
public static string StripTagsCharArray(string source)
{
char[] array = new char[source.Length];
int arrayIndex = 0;
bool inside = false;
for (int i = 0; i < source.Length; i++)
{
char let = source[i];
if (let == '<')
{
inside = true;
continue;
}
if (let == '>')
{
inside = false;
continue;
}
if (!inside)
{
array[arrayIndex] = let;
arrayIndex++;
}
}
return new string(array, 0, arrayIndex);
}
现在我得到没有粗体,斜体的纯文本..我需要在我的word文档中使用粗体,斜体,下划线函数,,,请帮帮我
答案 0 :(得分:0)
是否需要旧格式的Word文档?如果 docx (Word 2007/2010格式)适合您,请尝试使用MS Open XML SDK和this open source component将html转换为word。有enough information来了解如何使用这两个组件。而且我会说,这比使用像Word.ApplicationClass
等COM类的Interop dll快得多,也更安全。