단어 .doc (단어 97 - 2003)에서 프로그래밍 방식으로 기존 사용자 지정 속성을 업데이트하려고합니다. 처음에는 Aspose로 해결했지만 제한된 라이센스로 인해이 프로젝트에는 사용할 수 없습니다.기존 사용자 지정 속성 업데이트 Word doc
이 코드는 excel Accessing Excel Custom Document Properties programatically 대신에 단어를 약간 수정하여 여기에서 도매로 가져옵니다.
첫 번째 메서드는 사용자 지정 속성이 없으면 추가하고 두 번째 메서드는 사용자 지정 속성을 가져올 수 있습니다. 이미 존재하는 속성을 업데이트하는 방법을 알지 못했습니다. InvokeMember()에서 동사와 관련이있을 수 있지만 많은 문서를 찾을 수 없다고 생각합니다.
public void SetDocumentProperty(string propertyName, string propertyValue)
{
object oDocCustomProps = oWordDoc.CustomDocumentProperties;
Type typeDocCustomProps = oDocCustomProps.GetType();
object[] oArgs = {propertyName,false,
MsoDocProperties.msoPropertyTypeString,
propertyValue};
typeDocCustomProps.InvokeMember("Add",
BindingFlags.Default | BindingFlags.InvokeMethod,
null,
oDocCustomProps,
oArgs);
}
public object GetDocumentProperty(string propertyName, MsoDocProperties type)
{
object returnVal = null;
object oDocCustomProps = oWordDoc.CustomDocumentProperties;
Type typeDocCustomProps = oDocCustomProps.GetType();
object returned = typeDocCustomProps.InvokeMember("Item",
BindingFlags.Default |
BindingFlags.GetProperty, null,
oDocCustomProps, new object[] { propertyName });
Type typeDocAuthorProp = returned.GetType();
returnVal = typeDocAuthorProp.InvokeMember("Value",
BindingFlags.Default |
BindingFlags.GetProperty,
null, returned,
new object[] { }).ToString();
return returnVal;
}
http://docx.codeplex.com/ –
이 라이브러리가 좋아 보인다하지만 난 – Curtis