我有一个用ASP.NET(C#)编写的非常基本的web应用程序和一个包含文本框和下拉列表的基本Microsoft Word (2007)文档。
在我的web应用程序代码隐藏文件中,我想按名称调用textbox控件和dropdown控件,并从中提取值。
我在网上找到的任何文档都只是简单地读写word文档,但我似乎找不到任何关于访问控件和从控件中提取值的内容。
如有任何帮助,我将不胜感激
这是我目前唯一能处理word文档的代码。它会找到单词doc并打开它:
//File path of the word document that contains the required values
string filePath = @"C:\Users\murphycm\Desktop\PlacesFile.docm";
object fileToOpen = (object)filePath;
//CREATING OBJECTS OF WORD AND DOCUMENT
Microsoft.Office.Interop.Word.Application oWord = new Microsoft.Office.Interop.Word.Application();
Microsoft.Office.Interop.Word.Document oWordDoc = new Microsoft.Office.Interop.Word.Document();
oWordDoc = oWord.Documents.Open(ref fileToOpen);发布于 2017-10-27 21:32:26
public List<string> GetTagsFromNewTemplate(string filePath)
{
var tags = new HashSet<string>();
using (WordprocessingDocument myDocument = WordprocessingDocument.Open(filePath, false))
{
var textbox = myDocument.MainDocumentPart.Document.Descendants<DocumentFormat.OpenXml.Wordprocessing.Tag>().Select(x => x.Val);
textbox.ForEach(x => tags.Add(x));
}
return tags.Distinct().ToList();
} https://stackoverflow.com/questions/18232633
复制相似问题