[C++/EXCEL] #DIV/0! 데이터 읽을 때 발생하는 오류 문제
본문 바로가기

응용 프로그램 개발/C++, MFC, Windows

[C++/EXCEL] #DIV/0! 데이터 읽을 때 발생하는 오류 문제

728x90
반응형

MFC Excel Automation 을 활용하여 데이터를 읽어올 때,

 

#DIV/0! 인 데이터를 읽을 때 오류가 발생하며, 프로그램이 종료 되어버렸다.

 

따라서 다음과 같이 try catch 문을 활용하여 데이터를 읽을 때 오류를 잡도록 하였다.

 

이 방식으로 프로그램이 종료되지는 않았지만, 메모리 누수가 발생하였다.

 

따라서 프로그램을 실행하기 전에 직접 파일내에서 #DIV/0!인 데이터를 없애는 방법이 최선인 것 같다...

 

CString HsExcel::GetValue(long col, long row)
{
	SetRange(col, row);

	CString strValue = L"";

	try{
		strValue = (CString)m_range.GetValue2();
	}
	catch (CException* e)
	{
		throw e;
	}

	return strValue;
}

 

 

 

 

( + try catch 참고)

try
{
   CString strText = L"";
   strText = ex.GetValue(2,3);   
}
catch (CException* e)
{
	m_bExecuteRes = FALSE;
	m_bIsEndThread = TRUE;	
	m_strMsg = L"Error ocurred : Converting Data";
	SendMessage(m_parentHwnd, UWM_RUN_MESSAGE_POS, NULL, (LPARAM)&m_strMsg);	
	if (m_bIsEndThread) { ex.Close(); SendMessage(m_parentHwnd, UWM_EXTRACT_SELF_DESTROY, NULL, NULL); return; }
}

 

코드 설명:

GetValue 내부에서 throw e;를 통해 Exception을 위로 던졌기 때문에
Exception 발생 시 위의 catch 문을 타게된다.

728x90
반응형