当我读取.txt文件时,它会工作并显示,但当我读取.docx文件时,它会读取但以XML格式显示。如何将该XML格式转换为.docx?
代码是:
protected void viewfile(object sender, EventArgs e)
{
string path = (sender as LinkButton).CommandArgument;
if (!string.IsNullOrEmpty(path))
{
string[] readText = File.ReadAllLines(path);
StringBuilder strbuild = new StringBuilder();
foreach (string s in readText)
{
strbuild.Append(s);
strbuild.AppendLine();
}
TextBox1.Text = strbuild.ToString();
}
}
答案 0 :(得分:0)
有一个库来操纵docx,请查看:http://docx.codeplex.com/
答案 1 :(得分:0)
引用此Using DocxToText to Extract Text from DOCX Files。
您可以从.docx
文件中提取文字,例如
DocxToText dtt = new DocxToText(docxFileName);
string text = dtt.ExtractText();