我的.doc文件受到保护而无法填充,只允许填写doc中的表单。文件包含下拉列表,复选框和文本框。当我尝试从文件下拉列表和复选框中获取文本时,它们会向我发送“???”而不是任何文本。
如何在C#中从这些表单中获取文本。
这是我获取文字的方式:
Microsoft.Office.Interop.Word.Application word = new Microsoft.Office.Interop.Word.Application();
object miss = System.Reflection.Missing.Value;
object path = @"C:\DOC\myDocument.docx";
object readOnly = true;
Microsoft.Office.Interop.Word.Document docs = word.Documents.Open(ref path, ref miss, ref readOnly, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss);
string totaltext = "";
for (int i = 0; i < docs.Paragraphs.Count; i++)
{
totaltext += " \r\n "+ docs.Paragraphs[i+1].Range.Text.ToString();
}
Console.WriteLine(totaltext);
docs.Close();
word.Quit()
答案 0 :(得分:1)
试试这个,看它是否有效:
for (int i = 1; i <= docs.FormFields.Count; i++)
{
totaltext += " \r\n "+ docs.FormFields[i].Result.ToString();
}