Excel 각 필드에 연속되는 값을 빠르게 삽입하기 위한 함수 형태.
CStringArray에 입력할 정보들을 추가하여 넘겨주고 내부 for문을 돌며 정보를 삽입한다.
->하나씩 접근하는 방식에 3배 정도 빨라지게 된다.
CRange range;
range.AttachDispatch(sheet.get_Cells(), true);
...
range.Select();
를 반복하면서 시간이 많이 걸린다.
해당 함수를 활용하여 원하는 정보 List를 빠르게 Excel에 입력하자.
void SetValueListData2(bool *pbRun, int nSheet,
CString strCharCol1, int nStartRow1, CStringArray *pstrNewValueList1);
void CExcelCtrl::SetValueListData2(bool *pbRun, int nSheet,
CString strCharCol1, int nStartRow1, CStringArray *pstrNewValueList1)
{
if (nSheet < 1 || m_app == nullptr ||
pstrNewValueList1 == nullptr)
return;
try
{
int nCnt1 = pstrNewValueList1->GetCount();
if (nCnt1 > 0)
{
// sheet 생성, 연결 (1번 시트)
CWorksheet sheet;
sheet = m_worksheets.get_Item(COleVariant((short)nSheet));
sheet.Activate();
// range 생성, 연결
CRange range;
range.AttachDispatch(sheet.get_Cells(), true);
CString strCellPos;
for (int i = 0; i < nCnt1; i++)
{
if (*pbRun == false)//쓰기 중지.
break;
strCellPos.Format(L"%s%d", strCharCol1, nStartRow1 + i);
range = sheet.get_Range(COleVariant(strCellPos.GetBuffer(strCellPos.GetAllocLength())), m_covOptional);
//Data 쓰기.
range.put_Value2(COleVariant(pstrNewValueList1->GetAt(i)));
}
//------------------------------------------------------
range.ReleaseDispatch();
sheet.ReleaseDispatch();
}
}
catch (CMemoryException* e)
{
CMemoryException* ep = e;
AfxMessageBox(L"CMemoryException Could not clean up workbook.");
}
catch (CFileException* e)
{
CFileException* pe = e;
AfxMessageBox(L"CFileException Could not clean up workbook.");
}
catch (CException* e)
{
CException* pe = e;
AfxMessageBox(L"CException Could not clean up workbook.");
}
}
'작업 > MFC' 카테고리의 다른 글
Visual Studio Release모드 Debugging (0) | 2022.01.10 |
---|---|
비주얼 스튜디오 if문 for문 확장 축소 (문 블록 개요) (0) | 2021.10.28 |
CFileDialog Error (File Click-Mouse R) (1) | 2021.10.14 |
MFC에서 Excel 컨트롤 하기(3) (0) | 2021.06.16 |
MFC OpneMP 간단 사용하기. (1) | 2020.03.10 |