업데이트 : 이것은 Silverlight 4 베타의 확인 된 버그입니다. http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=523052Silverlight 4의 ComAutomationFactory를 사용하여 Word 문서 필드를 반복합니다.
저는이 문제를 완전히 해결 된 WPF 응용 프로그램으로 바꾸고 일반 구형 Microsoft.Office.Interop.Word를 사용하여이 문제를 해결했습니다. 하지만 ComAutomationFactory의 동적 값을 사용하여이 작업을 수행하는 방법에 대해서는 여전히 관심이 많습니다.
더 많은 C# 4.0 질문 일지 모르지만 신뢰할 수있는 SL4 앱의 ComAutomationFactory 클래스를 활용하여 Word 문서를로드하고 텍스트를 변경하고 인쇄하십시오. 일반 윈도우 응용 프로그램을 사용
, 그것은 꽤 쉽게 :
Object oMissing = System.Reflection.Missing.Value;
Object oTrue = true;
Object oFalse = false;
Application oWord = new Application();
Document oWordDoc = new Document();
oWord.Visible = false;
object oTemplatePath = "C:\\Users\\jwest\\Desktop\\DocumentTemplate.dotx";
oWordDoc = oWord.Documents.Add(ref oTemplatePath, ref oMissing, ref oMissing, ref oMissing);
foreach (Field myMergeField in oWordDoc.Fields)
그러나, SL4 당신이 동적 키워드를 사용해야합니다.
Object oMissing = System.Reflection.Missing.Value;
Object oTrue = true;
Object oFalse = false;
dynamic oWord = ComAutomationFactory.CreateObject("Word.Application");
oWord.Visible = false;
object oTemplatePath = "C:\\Users\\jwest\\Desktop\\DocumentTemplate.dotx";
dynamic oWordDoc = oWord.Documents.Add(ref oTemplatePath, ref oMissing, ref oMissing, ref oMissing);
dynamic fields = oWordDoc.Fields;
foreach (var myMergeField in fields)
하는 경우에는 내가 암시를 IEnumerable ComAutomationMetaObjectProvider을 변환 할 수 없다는 런타임 오류를 얻을 : 내 필드를 반복하려고 할 때까지 잘 작동합니다. 내가하는 일과 상관없이 내 Word com 객체와 관련된 모든 속성은 ComAutomationMetaObjectProvider 유형이며 반복 할 수 없습니다.
회원으로부터 String 필드를 가져와야한다고 언급했습니다. HRESULT : 이것은 흥미로운 예외가 발생
for (int i = 0; i < oWordDoc.Fields.Count; i++)
{
String field = oWordDoc.Fields.Item[i].Result.Text;
}
0x800A16E6 봤는 절대적으로 아무것도를 제공하지 않습니다.
나는 당신의 질문에 대한 답을 모르는 ... 비록 콘솔 응용 프로그램에서 잘 작동하지만 그냥 C# 4, 당신은 shouldn 지적하고 싶었 'ref oMissing' 매개 변수가 필요합니다. – CoderDennis