1
聯繫不,我想提取名字,contactno從Word文檔文件,我怎麼能提取PLZ任何一個可以幫助我的代碼EMAILID在這裏Windows應用程序提取名稱電子郵件ID和doc文件
public void Opendoc(object file)
{
Microsoft.Office.Interop.Word.Application wpp = new Microsoft.Office.Interop.Word.Application();
object nobj = System.Reflection.Missing.Value;
Microsoft.Office.Interop.Word.Document doc = wpp.Documents.Open(ref file, ref nobj, ref nobj, ref nobj,
ref nobj, ref nobj, ref nobj, ref nobj, ref nobj, ref nobj,
ref nobj, ref nobj, ref nobj, ref nobj, ref nobj, ref nobj);
int i = 1;
List <string> emailCollection = new List<string>();
foreach (Microsoft.Office.Interop.Word.Paragraph objParagraph in doc.Paragraphs)
try
{
string emailaddress = document.Paragraphs[1].Range.Text;
emailaddress = EmailExtractot(emailaddress).TrimEnd();
if (IsEmail(emailaddress))
{
emailCollection.Add(emailaddress);
}
}
catch (Exception ex) { throw ex; } i++;
} // close document and Quit Word
document.Close(ref nullobj, ref nullobj, ref nullobj);
}
public const string MatchEmailPattern = @"^(([\w-]+\.)+[\w-]+|([a-zA-Z]{1}|[\w-]{2,}))@"
+ @"((([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9])\.([0-1]?
[0-9]{1,2}|25[0-5]|2[0-4][0-9])\."
+ @"([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9])\.([0-1]?
[0-9]{1,2}|25[0-5]|2[0-4][0-9])){1}|"
+ @"([a-zA-Z]+[\w-]+\.)+[a-zA-Z]{2,4})$";
public static bool IsEmail(string email)
{
if (email != null) return Regex.IsMatch(email, MatchEmailPattern);
else return false;
}
private static string EmailExtractot(string orginal)
{
int index = orginal.IndexOf('@',' ');
int beforeEmptySpace = orginal.Substring(0, index).LastIndexOf(' ');
string spiled = orginal.Substring(index, (orginal.Length - index));
int afterEmptySpace = spiled.IndexOf(' ');
string emailAddress = orginal.Substring(beforeEmptySpace + 1, (index - beforeEmptySpace) + afterEmptySpace);
return emailAddress;
}
但這代碼不能正常工作