-3
당신이 날은 오류 메시지 다음 해결하는 데 도움이 될 수 있습니다 : 도움말 C 번호 오류를 필요 : 개체 참조가 개체의 인스턴스로 설정되지 않았습니다
가 나는 부분은 내가 코멘트와 함께 오류가 표시되고"Object reference not set to an instance of an object."
**
아래를 참조하십시오.
private static void _GenerateWord(string fname, string reportStartDate, string reportEndDate)
{
var word = new Microsoft.Office.Interop.Word.Application();
var doc = new Microsoft.Office.Interop.Word.Document();
word.Visible = false;
object missing = Type.Missing;
object fileName = (@LetterTemplateLocation + LetterName);
doc = word.Documents.Open(ref fileName);
doc.Activate();//**Error message here "Object reference not set to an instance of an object."**
string dateWithFormat = DateTime.Now.ToString("MMMM d, yyyy");
//**Error message here "Object reference not set to an instance of an object."**
foreach (Microsoft.Office.Interop.Word.Range tmpRange in doc.StoryRanges)
{
_FindAndReplace("<date>", dateWithFormat, tmpRange, missing);
_FindAndReplace("<filename>", fname, tmpRange, missing);
_FindAndReplace("<startdate>", reportStartDate, tmpRange, missing);
_FindAndReplace("<enddate>", reportEndDate, tmpRange, missing);
}
if (doc != null)
{
doc.Close(ref missing, ref missing, ref missing);
word.Application.Quit(ref missing, ref missing, ref missing);
}
}
감사합니다.
가능한 복제본 [NullReferenceException은 무엇이며 어떻게 수정합니까?] (http://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-and-how-do-i-fix- 그것) –
'doc' get '처럼 보입니다. 'fileName'은 기존의 워드 문서 파일에 대한 경로입니까? –
fileName이 먼저 존재하는지 확인합니다. bool found = File.Exist (fileName) – PhillyNJ