#include "pch.h"
|
#include "ExcelAutomation.h"
|
|
#define SHOW_EXCLE TRUE
|
|
COleVariant covTrue( (short)TRUE );
|
COleVariant covFalse( (short)FALSE );
|
COleVariant l_ValOptional( (long)DISP_E_PARAMNOTFOUND, VT_ERROR );
|
|
//////////////////////////////////////////////////////////////////////
|
// Construction/Destruction
|
//////////////////////////////////////////////////////////////////////
|
|
/*********************************************************************
|
// ¿¢¼¿ ¿ÀÅä¸ÞÀ̼ÇÀ» ÀÌ¿ëÇÏ¿© Ŭ·¡½º ¸¸µé±â..
|
Class Wizard -> Automation -> Add Class ->Form a Type Libary -> Excel9.old ¼±ÅÃ
|
|
Confirm Classes ¸ñ·Ï¿¡¼ ¸ðµç Ŭ·¡½º¸¦ ¼±ÅÃ
|
|
// ±âº»ÀûÀ¸·Î ¼±¾ðµÇ¾î ÀÖÁö¸¸ ¾øÀ¸¸é »õ·Î ¼±¾ðÇÑ´Ù.
|
#include <afxdisp.h> // MFC Automation classes
|
|
// ¿¢¼¿ ¿ÀÅä¸ÞÀÌ¼Ç »ç¿ëÇϱâ
|
// ÇÁ·Î±×·¥ ½ÃÀÛÇÏ´Â °÷¿¡ ¹Ýµå½Ã ¾Æ·¡ ·çƾÀ» Ãß°¡ÇØ ÁÖ¾î¾ß ÇÑ´Ù.
|
if (!AfxOleInit())
|
{
|
AfxMessageBox("Could not initialize COM dll");
|
return FALSE;
|
}
|
|
//////////////////////////////////////////////////////////////////////
|
// ÆÄÀÏ ÀúÀå Format Çü½Ä..
|
//////////////////////////////////////////////////////////////////////
|
|
typedef enum {
|
xlAddIn = 18, xlCSV = 6, xlCSVMac = 22, xlCSVMSDOS = 24,
|
xlCSVWindows = 23, xlDBF2 = 7, xlDBF3 = 8, xlDBF4 = 11,
|
xlDIF = 9, xlExcel2 = 16, xlExcel2FarEast = 27, xlExcel3 = 29,
|
xlExcel4 = 33, xlExcel5 = 39, xlExcel7 = 39, xlExcel9795 = 43,
|
xlExcel4Workbook = 35, xlIntlAddIn = 26, xlIntlMacro = 25,
|
xlWorkbookNormal = -4143, xlSYLK = 2, xlTemplate = 17,
|
xlCurrentPlatformText = -4158, xlTextMac = 19, xlTextMSDOS = 21,
|
xlTextPrinter = 36, xlTextWindows = 20, xlWJ2WD1 = 14,
|
xlWK1 = 5, xlWK1ALL = 31, xlWK1FMT = 30, xlWK3 = 15,
|
xlWK4 = 38, xlWK3FM3 = 32, xlWKS = 4, xlWorks2FarEast = 28, xlWQ1 = 34,
|
xlWJ3 = 40, xlWJ3FJ3 = 41, xlUnicodeText = 42, xlHtml = 44
|
} XlFileFormat;
|
|
|
¿¢¼¿¿¡¼ ¾²ÀÌ´Â xl·Î ½ÃÀ۵Ǵ º¯¼ö°ª ¾Ë¾Æº¸´Â ¹æ¹ý
|
¿¢¼¿ ¸ÞÅ©·Î¿¡¼ ¸¶¿ì½º¿À¸¥ÂÊ Å¬¸¯ÇÏ¿© Á¤ÀÇ ¸¦ º¸¸é µÈ´Ù.
|
**********************************************************************/
|
|
CExcelAutomation::CExcelAutomation()
|
{
|
///m_bIsAppEnable = CreateDispatch();
|
m_bIsAppEnable = false;
|
m_bIsOpen = false;
|
m_bIsSelect = false;
|
m_Filename = _T("");
|
m_szStartSel = _T("");
|
m_szEndSel = _T("");
|
|
m_nActiveSheetIndex = DEFAULT_SHEET_NO;
|
}
|
|
CExcelAutomation::~CExcelAutomation()
|
{
|
Close();
|
Release();
|
m_bIsOpen = false;
|
}
|
|
BOOL CExcelAutomation::CreateDispatch()
|
{
|
::CoInitialize(NULL);
|
if(!m_kApp.CreateDispatch(_T("Excel.Application")))
|
{
|
AfxMessageBox(_T("Couldn't start Excel and get Application object."));
|
return FALSE;
|
}
|
|
m_kApp.put_DisplayAlerts( FALSE ); // Don't display alerts
|
|
LPDISPATCH l_lpDisp = m_kApp.get_Workbooks();
|
m_kBooks.AttachDispatch(l_lpDisp);
|
|
///m_kApp.put_Visible(SHOW_EXCLE);
|
|
return true;
|
}
|
|
void CExcelAutomation::Init( CString strPathName /*= _T("")*/, DWORD dwSheetIndex /*= 1*/ )
|
{
|
CLSID clsExcelApp;
|
|
if(m_kApp.m_lpDispatch == NULL)
|
{
|
::CoInitialize(NULL);
|
if (!m_kApp.CreateDispatch(_T("Excel.Application")))
|
{
|
AfxMessageBox(_T("Couldn't start Excel and get Application object."));
|
return;
|
}
|
}
|
|
m_kApp.put_DisplayAlerts( FALSE ); // Don't display alerts
|
|
m_kBooks = m_kApp.get_Workbooks();
|
|
if( !strPathName.IsEmpty() )
|
{
|
m_kBook = m_kBooks.Open( strPathName, // Existed File Open
|
l_ValOptional, l_ValOptional, l_ValOptional, l_ValOptional,
|
l_ValOptional, l_ValOptional, l_ValOptional, l_ValOptional,
|
l_ValOptional, l_ValOptional, l_ValOptional, l_ValOptional,
|
l_ValOptional, l_ValOptional );
|
}
|
else
|
{
|
m_kBook = m_kBooks.Add(l_ValOptional); // New File Open
|
}
|
|
m_nActiveSheetIndex = dwSheetIndex;
|
|
m_kSheets = m_kBook.get_Worksheets();
|
m_kSheet = m_kSheets.get_Item(COleVariant((long)m_nActiveSheetIndex));
|
m_kSheet.Activate();
|
|
m_bIsOpen = TRUE;
|
m_bIsAppEnable = true;
|
m_Filename = strPathName;
|
}
|
|
void CExcelAutomation::Release()
|
{
|
m_kApp.Quit();
|
|
m_kApp.m_bAutoRelease = TRUE;
|
m_kApp.ReleaseDispatch();
|
m_kApp.DetachDispatch();
|
|
::CoUninitialize();
|
}
|
|
BOOL CExcelAutomation::CreateExcelFile()
|
{
|
LPDISPATCH l_lpDisp;
|
|
// Make New Document
|
m_kBook.SaveCopyAs(l_ValOptional);
|
|
l_lpDisp = m_kBooks.Add(l_ValOptional);
|
if( !l_lpDisp )
|
return FALSE;
|
|
m_kBook.AttachDispatch(l_lpDisp);
|
if( !l_lpDisp )
|
return FALSE;
|
|
l_lpDisp = m_kBook.get_Sheets();
|
m_kSheets.AttachDispatch(l_lpDisp);
|
|
m_bIsOpen = TRUE;
|
|
return TRUE;
|
}
|
|
BOOL CExcelAutomation::Open( const CString strFilename )
|
{
|
|
#if 1
|
LPDISPATCH l_lpDisp;
|
|
// ¿¢¼¿ ÆÄÀÏÀÌ ¿·Á ÀÖ´ÂÁö¸¦ °Ë»çÇÑ´Ù. 1°³ÀÇ ¿¢¼¿ ÆÄÀϸ¸ ÀÛ¾÷ °¡´ÉÇÏ´Ù.
|
if( GetOpenFile() )
|
return FALSE;
|
/*
|
Open(LPCTSTR Filename, const VARIANT& UpdateLinks, const VARIANT& ReadOnly,
|
const VARIANT& Format, const VARIANT& Password, const VARIANT& WriteResPassword,
|
const VARIANT& IgnoreReadOnlyRecommended, const VARIANT& Origin, const VARIANT& Delimiter,
|
const VARIANT& Editable, const VARIANT& Notify, const VARIANT& Converter, const VARIANT& AddToMru)
|
*/
|
l_lpDisp = m_kBooks.Open( strFilename, l_ValOptional, l_ValOptional,
|
l_ValOptional, l_ValOptional, l_ValOptional, l_ValOptional,
|
l_ValOptional, l_ValOptional, l_ValOptional, l_ValOptional,
|
l_ValOptional, l_ValOptional, l_ValOptional, l_ValOptional );
|
if( !l_lpDisp )
|
return FALSE;
|
|
m_kBook.AttachDispatch(l_lpDisp);
|
if( !l_lpDisp )
|
return FALSE;
|
|
DWORD dwSheetCnt = GetSheetCount();
|
|
|
l_lpDisp = m_kBook.get_Worksheets();
|
m_kSheets.AttachDispatch(l_lpDisp);
|
|
|
l_lpDisp = m_kBook.get_Sheets();
|
m_kSheets.AttachDispatch(l_lpDisp);
|
|
m_bIsOpen = TRUE;
|
m_Filename = strFilename;
|
#endif
|
return TRUE;
|
}
|
|
|
BOOL CExcelAutomation::Save(BOOL bIsOverWrite)
|
{
|
if(GetOpenFile() == false || m_Filename.IsEmpty() == TRUE) return FALSE;
|
/*
|
if(access(m_Filename, 0) != -1)
|
{
|
if(bIsOverWrite == true) ::DeleteFile(m_Filename);
|
else return FALSE;
|
}
|
*/
|
|
m_kBook.SaveAs( COleVariant(m_Filename), // VARIANT& Filename
|
COleVariant((long)-4143), // VARIANT& FileFormat
|
l_ValOptional, // VARIANT& Password
|
l_ValOptional, // VARIANT& WriteResPassword
|
covFalse, // VARIANT& ReadOnlyRecommended
|
covFalse, // VARIANT& CreateBackup
|
(long)2, // long AccessMode
|
COleVariant((long)1), // VARIANT& ConflictResolution
|
covFalse, // VARIANT& AddToMru
|
covFalse, // VARIANT& TextCodepage
|
covFalse, // VARIANT& TextVisualLayout
|
covFalse ); // VARIANT& Local
|
|
return TRUE;
|
}
|
|
BOOL CExcelAutomation::SaveAs(BOOL bIsOverWrite, const CString strFilename)
|
{
|
/*
|
if(access(strFilename, 0) != -1)
|
{
|
if(bIsOverWrite == true) ::DeleteFile(strFilename);
|
else return FALSE;
|
}
|
*/
|
m_kBook.SaveAs( COleVariant(strFilename), // VARIANT& Filename
|
COleVariant((long)-4143), // VARIANT& FileFormat
|
l_ValOptional, // VARIANT& Password
|
l_ValOptional, // VARIANT& WriteResPassword
|
covFalse, // VARIANT& ReadOnlyRecommended
|
covFalse, // VARIANT& CreateBackup
|
(long)0, // long AccessMode
|
COleVariant((long)1), // VARIANT& ConflictResolution
|
covFalse, // VARIANT& AddToMru
|
covFalse, // VARIANT& TextCodepage
|
covFalse, // VARIANT& TextVisualLayout
|
covFalse ); // VARIANT& Local
|
|
return TRUE;
|
}
|
|
void CExcelAutomation::Close()
|
{
|
if( m_bIsOpen == FALSE )
|
return;
|
|
if( SHOW_EXCLE == FALSE || m_kApp.get_Visible() == TRUE)
|
m_kBook.Close( covFalse, l_ValOptional, l_ValOptional );
|
|
m_bIsOpen = FALSE;
|
m_Filename.Empty();
|
}
|
|
//-------------------------------------------------------------------------------------------------
|
// Workbook(s)
|
BOOL CExcelAutomation::ChangeActiveWorkbook( CString strPathName )
|
{
|
CString strName = _T("");
|
long lBook = 0;
|
|
for( lBook=1; lBook<=GetBookCount(); lBook++)
|
{
|
m_kBook = m_kBooks.get_Item(COleVariant(lBook));
|
strName = m_kBook.get_FullName();
|
|
if( strPathName == strName )
|
break;
|
}
|
|
if( lBook > GetBookCount() )
|
return FALSE;
|
|
m_kBook = m_kBooks.get_Item(COleVariant(lBook));
|
m_kSheets = m_kBook.get_Worksheets();
|
SetCurrentSheetIndex( DEFAULT_SHEET_NO );
|
m_kSheet = m_kSheets.get_Item(COleVariant((short)m_nActiveSheetIndex));
|
m_kSheet.Activate();
|
|
return TRUE;
|
}
|
|
//iBook´Â 1ºÎÅÍ ½ÃÀÛ
|
BOOL CExcelAutomation::ChangeActiveWorkbook( long lBook )
|
{
|
if( lBook < 1 || GetBookCount() < lBook )
|
return FALSE;
|
|
m_kBook = m_kBooks.get_Item(COleVariant(lBook));
|
m_kSheets = m_kBook.get_Worksheets();
|
SetCurrentSheetIndex( DEFAULT_SHEET_NO );
|
m_kSheet = m_kSheets.get_Item(COleVariant((short)m_nActiveSheetIndex));
|
m_kSheet.Activate();
|
|
return TRUE;
|
}
|
|
long CExcelAutomation::GetBookCount()
|
{
|
if( !GetOpenFile() )
|
return FALSE;
|
|
return m_kBooks.get_Count();
|
}
|
|
|
//-------------------------------------------------------------------------------------------------
|
// Worksheet(s)
|
|
long CExcelAutomation::GetSheetCount()
|
{
|
if( !GetOpenFile() )
|
return FALSE;
|
|
return m_kSheets.get_Count();
|
}
|
|
BOOL CExcelAutomation::AddSheet(DWORD dwSheetIndex, CString strSheetName, BOOL bBeforeOrAfter/* = TRUE*/) // FALSE : Before, TRUE : After
|
{
|
CString strOriginSheetName = _T("");
|
BOOL bSameNameExist = FALSE;
|
DWORD dwSheetCnt = GetSheetCount();
|
|
if( dwSheetCnt == 0 )
|
return FALSE;
|
|
LPDISPATCH l_lpDisp;
|
l_lpDisp = m_kSheets.get_Item(COleVariant((short) dwSheetIndex));//±âÁØ ½ÃÆ®(ù ½ÃÆ®¶ó¸é iSheet == 1)
|
m_kSheet.AttachDispatch(l_lpDisp);
|
|
COleVariant vBeforeOrAfter;
|
vBeforeOrAfter.vt = VT_DISPATCH;
|
vBeforeOrAfter.pdispVal = m_kSheet.m_lpDispatch;
|
vBeforeOrAfter.pdispVal->AddRef();
|
|
if( bBeforeOrAfter )
|
{
|
m_kSheets.Add(l_ValOptional, vBeforeOrAfter, l_ValOptional, l_ValOptional);
|
|
for( int i=1; i<dwSheetCnt+1; i++ )
|
{
|
strOriginSheetName = GetSheetName( i );
|
|
if( strSheetName.Compare(strOriginSheetName) == 0 )
|
{
|
bSameNameExist = TRUE;
|
break;
|
}
|
}
|
|
if( bSameNameExist )
|
strSheetName = GetSheetName( dwSheetIndex+1 );;
|
|
SetSheetName(dwSheetIndex+1, strSheetName);
|
SetActiveSheet(dwSheetIndex+1);
|
}
|
else
|
{
|
m_kSheets.Add(vBeforeOrAfter, l_ValOptional, l_ValOptional, l_ValOptional);
|
SetSheetName(dwSheetIndex, strSheetName);
|
SetActiveSheet(dwSheetIndex);
|
}
|
|
// SetSheetName(dwSheetIndex, strSheetName);
|
// SetActiveSheet(dwSheetIndex);
|
|
return TRUE;
|
}
|
|
BOOL CExcelAutomation::DeleteSheet( CString strSheetName )
|
{
|
if( !SetActiveSheet(strSheetName) )
|
return FALSE;
|
|
m_kSheet.Delete();
|
return TRUE;
|
}
|
|
BOOL CExcelAutomation::DeleteSheet( DWORD dwSheetIndex )
|
{
|
if( !SetActiveSheet(dwSheetIndex) )
|
return FALSE;
|
|
m_kSheet.Delete();
|
return TRUE;
|
}
|
|
BOOL CExcelAutomation::DeleteAllSheet()
|
{
|
DWORD dwSheetCount = GetSheetCount();
|
|
for( int i=1; i<dwSheetCount+1; i++ )
|
DeleteSheet(i);
|
|
return TRUE;
|
}
|
|
BOOL CExcelAutomation::SetSheetName( DWORD dwSheetIndex, CString strName )
|
{
|
if( dwSheetIndex < 1 || GetSheetCount() < dwSheetIndex )
|
return FALSE;
|
|
LPDISPATCH l_lpDisp = m_kSheets.get_Item(COleVariant((short)(dwSheetIndex)));
|
m_kSheet.AttachDispatch(l_lpDisp);
|
|
m_kSheet.put_Name( strName );
|
|
return TRUE;
|
}
|
|
CString CExcelAutomation::GetSheetName( DWORD dwSheetIndex )
|
{
|
if( dwSheetIndex < 1 || GetSheetCount() < dwSheetIndex )
|
return _T("");
|
|
DWORD dwOldSheet;
|
dwOldSheet = m_nActiveSheetIndex;
|
|
LPDISPATCH l_lpDisp = m_kSheets.get_Item(COleVariant((short)(dwSheetIndex)));
|
m_kSheet.AttachDispatch(l_lpDisp);
|
|
return m_kSheet.get_Name();
|
}
|
|
BOOL CExcelAutomation::ChangeSheetName( DWORD dwSheetIndex, CString strSheetName )
|
{
|
if( dwSheetIndex < 1 || GetSheetCount() < dwSheetIndex )
|
return FALSE;
|
|
DWORD dwOldSheet;
|
dwOldSheet = m_nActiveSheetIndex;
|
|
///SetActiveSheet(dwSheetIndex);
|
SetSheetName(dwSheetIndex, strSheetName);
|
SetActiveSheet(dwOldSheet);
|
|
return TRUE;
|
}
|
|
BOOL CExcelAutomation::SetActiveSheet( DWORD dwSheetIndex )
|
{
|
if( dwSheetIndex < 1 || GetSheetCount() < dwSheetIndex )
|
return FALSE;
|
|
LPDISPATCH l_lpDisp = m_kSheets.get_Item(COleVariant((short)(dwSheetIndex)));
|
m_kSheet.AttachDispatch(l_lpDisp);
|
m_kSheet.Activate();
|
|
m_nActiveSheetIndex = dwSheetIndex;
|
|
return TRUE;
|
}
|
|
BOOL CExcelAutomation::SetActiveSheet( CString strSheetName )
|
{
|
CString strName = _T("");
|
long lSheet = 0;
|
|
for( lSheet=1; lSheet<=m_kSheets.get_Count(); lSheet++ )
|
{
|
strName = GetSheetName(lSheet);
|
if( strSheetName == strName )
|
break;
|
}
|
|
if( lSheet > m_kSheets.get_Count() )
|
return FALSE;
|
|
m_nActiveSheetIndex = lSheet;
|
m_kSheet = m_kSheets.get_Item(COleVariant((short)m_nActiveSheetIndex));
|
m_kSheet.Activate();
|
|
return TRUE;
|
}
|
|
|
// All Sheets Copy & Paste
|
// FALSE : Before, TRUE : After
|
BOOL CExcelAutomation::CopySheets( CString strPathNameSrc, CString strPathNameDest, CString strSheetNameDest, BOOL bBeforeOrAfter/* = TRUE*/ )
|
{
|
if( !ChangeActiveWorkbook(strPathNameSrc) )
|
return FALSE;
|
|
CWorkbook workbook;
|
|
CString strPathNameDestTemp = _T("");
|
long lBook = 0;
|
|
for( lBook=1; lBook<=m_kBooks.get_Count(); lBook++ )
|
{
|
workbook = m_kBooks.get_Item(COleVariant(lBook));
|
strPathNameDestTemp = workbook.get_FullName();
|
if( strPathNameDest == strPathNameDestTemp )
|
break;
|
}
|
|
if(lBook > m_kBooks.get_Count() )
|
return FALSE;
|
|
//º¹»çµÉ worksheet À§Ä¡ ¼±ÅÃ
|
CWorksheets worksheets = workbook.get_Worksheets();
|
CWorksheet worksheet;
|
CString strSheetNameDestTemp = _T("");
|
long lSheet = 0;
|
|
for( lSheet=1; lSheet<=worksheets.get_Count(); lSheet++ )
|
{
|
worksheet = worksheets.get_Item(COleVariant(lSheet)); // sheets are indexed starting from 1
|
strSheetNameDestTemp = worksheet.get_Name();
|
|
if( strSheetNameDest == strSheetNameDestTemp )
|
break;
|
}
|
|
if( lSheet > worksheets.get_Count() )
|
return FALSE;
|
|
//worksheets º¹»ç
|
VARIANT v = {0};
|
v.vt = VT_DISPATCH;
|
v.pdispVal = worksheet.m_lpDispatch;
|
|
if( bBeforeOrAfter )
|
m_kSheets.Copy( l_ValOptional, v );
|
else
|
m_kSheets.Copy( v, l_ValOptional );
|
|
VariantClear(&v);
|
|
return TRUE;
|
}
|
BOOL CExcelAutomation::CopySheets( CString strPathNameSrc, CString strPathNameDest, long lSheetDest, BOOL bBeforeOrAfter/* = TRUE*/ )
|
{
|
if( !ChangeActiveWorkbook(strPathNameSrc) )
|
return FALSE;
|
|
CWorkbook workbook;
|
|
CString strPathNameDestTemp = _T("");
|
long lBook = 0;
|
|
for( lBook=1; lBook<=m_kBooks.get_Count(); lBook++ )
|
{
|
workbook = m_kBooks.get_Item(COleVariant(lBook));
|
strPathNameDestTemp = workbook.get_FullName();
|
if( strPathNameDest == strPathNameDestTemp )
|
break;
|
}
|
|
if(lBook > m_kBooks.get_Count() )
|
return FALSE;
|
|
//º¹»çµÉ worksheet À§Ä¡ ¼±ÅÃ
|
CWorksheets worksheets = workbook.get_Worksheets();
|
CWorksheet worksheet = worksheets.get_Item(COleVariant(lSheetDest)); // sheets are indexed starting from 1
|
|
//worksheets º¹»ç
|
VARIANT v = {0};
|
v.vt = VT_DISPATCH;
|
v.pdispVal = worksheet.m_lpDispatch;
|
|
if( bBeforeOrAfter )
|
m_kSheets.Copy( l_ValOptional, v );
|
else
|
m_kSheets.Copy( v, l_ValOptional );
|
|
VariantClear(&v);
|
|
return TRUE;
|
}
|
BOOL CExcelAutomation::CopySheet( CString strPathNameSrc, CString strSheetNameSrc, CString strPathNameDest, CString strSheetNameDest, BOOL bBeforeOrAfter/* = TRUE*/ )
|
{
|
// Original workbook, worksheet Activate
|
if( !ChangeActiveWorkbook(strPathNameSrc) )
|
return FALSE;
|
|
if( !SetActiveSheet(strSheetNameSrc) )
|
return FALSE;
|
|
// Select workbook for copy
|
CWorkbook workbook;
|
CString strPathNameDestTemp = _T("");
|
long lBook = 0;
|
|
for( lBook=1; lBook<=m_kBooks.get_Count(); lBook++ )
|
{
|
workbook = m_kBooks.get_Item(COleVariant(lBook));
|
strPathNameDestTemp = workbook.get_FullName();
|
|
if( strPathNameDest == strPathNameDestTemp )
|
break;
|
}
|
|
if( lBook > m_kBooks.get_Count() )
|
return FALSE;
|
|
//º¹»çµÉ worksheet À§Ä¡ ¼±ÅÃ
|
CWorksheets worksheets = workbook.get_Worksheets();
|
CWorksheet worksheet;
|
CString strSheetNameDestTemp = _T("");
|
long lSheet = 0;
|
|
for( lSheet = 1; lSheet <= worksheets.get_Count(); lSheet++)
|
{
|
worksheet = worksheets.get_Item(COleVariant(lSheet)); // sheets are indexed starting from 1
|
strSheetNameDestTemp = worksheet.get_Name();
|
|
if( strSheetNameDest == strSheetNameDestTemp )
|
break;
|
}
|
|
if(lSheet > worksheets.get_Count())
|
return FALSE;
|
|
//worksheet copy
|
VARIANT v = {0};
|
v.vt = VT_DISPATCH;
|
v.pdispVal = worksheet.m_lpDispatch;
|
|
if( bBeforeOrAfter )
|
m_kSheet.Copy( l_ValOptional, v );
|
else
|
m_kSheet.Copy( v, l_ValOptional );
|
|
VariantClear(&v);
|
|
return TRUE;
|
}
|
BOOL CExcelAutomation::CopySheet( CString strPathNameSrc, long lSheetSrc, CString strPathNameDest, long lSheetDest, BOOL bBeforeOrAfter/* = TRUE*/ )
|
{
|
if( !ChangeActiveWorkbook(strPathNameSrc) )
|
return FALSE;
|
|
if( !SetActiveSheet(lSheetSrc) )
|
return FALSE;
|
|
CWorkbook workbook;
|
CString strPathNameDestTemp = _T("");
|
long lBook = 0;
|
|
for( lBook=1; lBook<=m_kBooks.get_Count(); lBook++ )
|
{
|
workbook = m_kBooks.get_Item(COleVariant(lBook));
|
strPathNameDestTemp = workbook.get_FullName();
|
|
if( strPathNameDest == strPathNameDestTemp )
|
break;
|
}
|
|
if( lBook > m_kBooks.get_Count() )
|
return FALSE;
|
|
CWorksheets worksheets = workbook.get_Worksheets();
|
CWorksheet worksheet = worksheets.get_Item(COleVariant(lSheetDest)); // sheets are indexed starting from 1
|
|
VARIANT v = {0};
|
v.vt = VT_DISPATCH;
|
v.pdispVal = worksheet.m_lpDispatch;
|
|
if( bBeforeOrAfter )
|
m_kSheet.Copy( l_ValOptional, v );
|
else
|
m_kSheet.Copy( v, l_ValOptional );
|
|
VariantClear(&v);
|
|
return TRUE;
|
}
|
|
void CExcelAutomation::SetVisible( BOOL bSet/*=TRUE*/ )
|
{
|
if( m_kApp )
|
m_kApp.put_Visible(bSet);
|
}
|
|
long CExcelAutomation::GetMaxRows(int nSheetIndex)
|
{
|
if( !GetOpenFile() )
|
return FALSE;
|
|
if( nSheetIndex < 1 || GetSheetCount() < nSheetIndex )
|
return -1;
|
|
LPDISPATCH l_lpDisp;
|
l_lpDisp = m_kSheets.get_Item(COleVariant((short)nSheetIndex));
|
m_kSheet.AttachDispatch(l_lpDisp);
|
|
CRange range = m_kSheet.get_UsedRange();
|
CRange rowRange = range.get_Rows();
|
|
return rowRange.get_Count();
|
}
|
|
long CExcelAutomation::GetMaxCols(int nSheetIndex)
|
{
|
if( nSheetIndex < 1 || GetSheetCount() < nSheetIndex )
|
return -1;
|
|
if( !GetOpenFile() )
|
return FALSE;
|
|
if( nSheetIndex < 1 || GetSheetCount() < nSheetIndex )
|
return -1;
|
|
LPDISPATCH l_lpDisp;
|
l_lpDisp = m_kSheets.get_Item(COleVariant((short)nSheetIndex));
|
m_kSheet.AttachDispatch(l_lpDisp);
|
|
CRange range = m_kSheet.get_UsedRange();
|
CRange colRange = range.get_Columns();
|
|
return colRange.get_Count();
|
}
|
|
BOOL CExcelAutomation::Select(int nSheetIndex, const CString strStartSel, const CString strEndSel)
|
{
|
if( !GetOpenFile() )
|
return FALSE;
|
|
if( nSheetIndex < 1 || GetSheetCount() < nSheetIndex )
|
return FALSE;
|
|
LPDISPATCH l_lpDisp;
|
l_lpDisp = m_kSheets.get_Item(COleVariant((short)nSheetIndex));
|
m_kSheet.AttachDispatch(l_lpDisp);
|
|
l_lpDisp = m_kSheet.get_Range(COleVariant(strStartSel), COleVariant(strEndSel));
|
m_kRange.AttachDispatch(l_lpDisp);
|
|
m_kRange.Select();
|
|
m_bIsSelect = TRUE;
|
m_szStartSel = strStartSel;
|
m_szEndSel = strEndSel;
|
|
return TRUE;
|
}
|
|
void CExcelAutomation::UnSelect()
|
{
|
m_bIsSelect = FALSE;
|
m_szStartSel = _T("");
|
m_szEndSel = _T("");
|
}
|
|
CString CExcelAutomation::GetData(int nSheetIndex, const CString strSel)
|
{
|
if( Select(nSheetIndex, strSel, strSel) == FALSE )
|
return _T("");
|
|
VARIANT l_kVar;
|
|
l_kVar = m_kRange.get_Value2();
|
|
VariantChangeType( &l_kVar, &l_kVar, 0, VT_BSTR );
|
|
return CString(l_kVar.bstrVal);
|
}
|
|
void CExcelAutomation::SetData(const CString strFillData)
|
{
|
if( !GetSelect() )
|
return;
|
|
m_kRange.put_Value2(COleVariant(strFillData));
|
}
|
|
void CExcelAutomation::SetData(int nSheetIndex, const CString strSel, const CString strFillData)
|
{
|
if( Select(nSheetIndex, strSel, strSel) == FALSE )
|
return;
|
|
m_kRange.put_Value2(COleVariant(strFillData));
|
}
|
|
void CExcelAutomation::SetData(int nSheetIndex, const CString strStartSel, const CString strEndSel, const CString strFillData)
|
{
|
if( Select(nSheetIndex, strStartSel, strEndSel) == FALSE )
|
return;
|
|
m_kRange.put_Value2(COleVariant(strFillData));
|
}
|
|
void CExcelAutomation::SetData(int nSheetIndex, const CString strSel, const CString strFillData, int nFormat)
|
{
|
if( Select(nSheetIndex, strSel, strSel) == FALSE )
|
return;
|
|
SetDataFormat(nFormat);
|
|
m_kRange.put_Value2(COleVariant(strFillData));
|
}
|
|
void CExcelAutomation::SetData(int nSheetIndex, const CString strStartSel, const CString strEndSel, const CString strFillData, int nFormat)
|
{
|
if( Select(nSheetIndex, strStartSel, strEndSel) == FALSE )
|
return;
|
|
SetDataFormat(nFormat);
|
|
m_kRange.put_Value2(COleVariant(strFillData));
|
}
|
|
void CExcelAutomation::SetMergeColorData(int nSheetIndex, const CString strStartSel, const CString strEndSel, const CString strFillData,
|
COLORREF cBGColor/* = NULL*/, BOOL bMerge/* = TRUE*/)
|
{
|
if( Select(nSheetIndex, strStartSel, strEndSel) == FALSE )
|
return;
|
|
if( cBGColor != NULL )
|
SetColor( cBGColor );
|
|
if( bMerge )
|
SetMerge();
|
|
SetDataFormat(2);
|
|
m_kRange.put_Value2(COleVariant(strFillData));
|
}
|
|
void CExcelAutomation::SetFormula(int nSheetIndex, const CString strSel, const CString strFillData)
|
{
|
if( Select(nSheetIndex, strSel, strSel) == FALSE )
|
return;
|
|
m_kRange.put_Formula(COleVariant(strFillData));
|
}
|
|
void CExcelAutomation::SetFormula(int nSheetIndex, const CString strStartSel, const CString strEndSel, const CString strFillData)
|
{
|
if( Select(nSheetIndex, strStartSel, strEndSel) == FALSE )
|
return;
|
|
m_kRange.put_Formula(COleVariant(strFillData));
|
}
|
|
void CExcelAutomation::SetDataFormat(int nFormat)
|
{
|
if( !GetSelect() )
|
return;
|
|
switch( nFormat )
|
{
|
case 0:
|
m_kRange.put_NumberFormatLocal(COleVariant(_T("G/Ç¥ÁØ"))); // Ç¥ÁØ
|
break;
|
case 1:
|
m_kRange.put_NumberFormatLocal(COleVariant(_T("0_ "))); // ¼ýÀÚ
|
break;
|
case 2:
|
m_kRange.put_NumberFormatLocal(COleVariant(_T("@"))); // ¹®ÀÚ
|
break;
|
}
|
}
|
|
void CExcelAutomation::SetAlign(int nHAlign, int nVAlign, BOOL bIsOrientation)
|
{
|
if( !GetSelect() )
|
return;
|
|
// Horizontal
|
switch( nHAlign )
|
{
|
case 0:
|
nHAlign = -4131; // xlLeft
|
break;
|
case 1:
|
nHAlign = -4108; // xlVAlignCenter
|
break;
|
case 2:
|
nHAlign = -4152; // xlRight
|
break;
|
}
|
|
// Vertical
|
switch( nVAlign )
|
{
|
case 0:
|
nVAlign = -4160; // xlTop = -4108 (&HFFFFEFC0) À§ÂÊ
|
break;
|
case 1:
|
nVAlign = -4108; // xlCenter = -4108 (&HFFFFEFF4) °¡¿îµ¥
|
break;
|
case 2:
|
nVAlign = -4107; // xlBottom = -4107 (&HFFFFEFF5) ¾Æ·§ÂÊ
|
break;
|
case 3:
|
nVAlign = -4130; // xlJustify = -4130 (&HFFFFEFDE) ¾çÂʸÂÃã
|
break;
|
case 4:
|
nVAlign = -4117; // xlDistributed = -4117 (&HFFFFEFEB) ±ÕµîºÐÇÒ
|
break;
|
}
|
|
m_kRange.put_HorizontalAlignment(COleVariant((short)nHAlign));
|
m_kRange.put_VerticalAlignment(COleVariant((short)nVAlign));
|
|
if( bIsOrientation )
|
m_kRange.put_Orientation(COleVariant((short)-4166)); // xlVertical = -4166
|
}
|
|
void CExcelAutomation::SetHorizontalAlign( int nHAlign )
|
{
|
if( !GetSelect() )
|
return;
|
|
// Horizontal
|
switch( nHAlign )
|
{
|
case 0:
|
nHAlign = -4131; // xlLeft
|
break;
|
case 1:
|
nHAlign = -4108; // xlVAlignCenter
|
break;
|
case 2:
|
nHAlign = -4152; // xlRight
|
break;
|
}
|
|
m_kRange.put_HorizontalAlignment(COleVariant((short)nHAlign));
|
}
|
|
void CExcelAutomation::SetVerticalAlign( int nVAlign )
|
{
|
if( !GetSelect() )
|
return;
|
|
// Vertical
|
switch( nVAlign )
|
{
|
case 0:
|
nVAlign = -4160; // xlTop = -4108 (&HFFFFEFC0) À§ÂÊ
|
break;
|
case 1:
|
nVAlign = -4108; // xlCenter = -4108 (&HFFFFEFF4) °¡¿îµ¥
|
break;
|
case 2:
|
nVAlign = -4107; // xlBottom = -4107 (&HFFFFEFF5) ¾Æ·§ÂÊ
|
break;
|
case 3:
|
nVAlign = -4130; // xlJustify = -4130 (&HFFFFEFDE) ¾çÂʸÂÃã
|
break;
|
case 4:
|
nVAlign = -4117; // xlDistributed = -4117 (&HFFFFEFEB) ±ÕµîºÐÇÒ
|
break;
|
}
|
|
m_kRange.put_VerticalAlignment(COleVariant((short)nVAlign));
|
}
|
|
void CExcelAutomation::SetAlignment(CString strCellAddrsrt, CString strCellAddr2end, short iHorizontal, short iVertical)
|
{
|
m_kRange = m_kSheet.get_Range(COleVariant(strCellAddrsrt),COleVariant(strCellAddr2end));
|
|
m_kRange.put_HorizontalAlignment(COleVariant((short) iHorizontal)); //Center:-4108, left:1, right:-4152
|
m_kRange.put_VerticalAlignment(COleVariant((short) iVertical)); //Center:-4108, left:1, right:-4152
|
}
|
|
void CExcelAutomation::SetFont(short nSize, const CString Fontname, BOOL bIsItalic, BOOL bIsUnderLine, BOOL bIsBold, COLORREF color/*=NULL*/)
|
{
|
if( !GetSelect() )
|
return;
|
|
CFont0 font;
|
|
// Font
|
font = m_kRange.get_Font();
|
font.put_Size(COleVariant(nSize));
|
font.put_Name(COleVariant(Fontname));
|
font.put_Italic(bIsItalic == TRUE ? covTrue : covFalse);
|
font.put_Underline(bIsUnderLine == TRUE ? COleVariant((long)2) : COleVariant((long)-4142));
|
font.put_Bold(bIsBold == TRUE ? covTrue:covFalse);
|
if( color != NULL )
|
font.put_Color(COleVariant((double)color));
|
}
|
|
void CExcelAutomation::SetFont(CString strCellAddrsrt, CString strCellAddr2end, BOOL bBold, short iSize, CString strFontName, COLORREF color)
|
{
|
m_kRange = m_kSheet.get_Range(COleVariant(strCellAddrsrt),COleVariant(strCellAddr2end));
|
|
CFont0 font;
|
font = m_kRange.get_Font();
|
|
font.put_Bold(COleVariant((short) bBold));
|
font.put_Size(COleVariant((short) iSize));
|
//font.SetFontStyle(COleVariant("BOLD"));
|
font.put_Name(COleVariant(strFontName));
|
font.put_Color(COleVariant((double)color));
|
}
|
|
void CExcelAutomation::SetLine(short nLineStyle, short nWeight)
|
{
|
if( !GetSelect() )
|
return;
|
|
CBorders borders;
|
|
// Horizontal
|
switch( nLineStyle )
|
{
|
case 0:
|
nLineStyle = 1; // xlContinuous
|
break;
|
case 1:
|
nLineStyle = -4115; // xlDash
|
break;
|
case 2:
|
nLineStyle = 4; // xlDashDot
|
break;
|
case 3:
|
nLineStyle = 5; // xlDashDotDot
|
break;
|
case 4:
|
nLineStyle = -4118; // xlDot
|
break;
|
case 5:
|
nLineStyle = -4119; // xlDouble
|
break;
|
case 6:
|
nLineStyle = -4142; // xlLineStyleNone
|
break;
|
case 7:
|
nLineStyle = 13; // xlSlantDashDot
|
break;
|
}
|
|
// Vertical
|
switch( nWeight )
|
{
|
case 0:
|
nWeight = -4138; // xlMedium
|
break;
|
case 1:
|
nWeight = 1; // xlHairline
|
break;
|
case 2:
|
nWeight = 4; // xlThick
|
break;
|
case 3:
|
nWeight = 2; // xlThin
|
break;
|
}
|
|
borders = m_kRange.get_Borders();
|
borders.put_LineStyle(COleVariant((short)nLineStyle));
|
borders.put_Weight(COleVariant((short)nWeight));
|
}
|
|
|
void CExcelAutomation::SetColor(int nRed, int nGreen, int nBlue)
|
{
|
if( !GetSelect() )
|
return;
|
|
COLORREF color;
|
Cnterior interior;
|
|
color = RGB(nRed, nGreen, nBlue);
|
|
interior = m_kRange.get_Interior();
|
interior.put_Color(COleVariant((double)color));
|
}
|
|
void CExcelAutomation::SetColor( COLORREF crColor )
|
{
|
if( !GetSelect() )
|
return;
|
|
COLORREF color;
|
Cnterior interior;
|
|
color = crColor;
|
|
interior = m_kRange.get_Interior();
|
interior.put_Color(COleVariant((double)color));
|
}
|
|
void CExcelAutomation::SetMerge()
|
{
|
if( !GetSelect() )
|
return;
|
|
m_kRange.put_MergeCells(covTrue);
|
UnSelect();
|
}
|
|
void CExcelAutomation::SetAutoFit()
|
{
|
if( !GetSelect() )
|
return;
|
|
m_kRange = m_kRange.get_EntireColumn();
|
m_kRange.AutoFit();
|
UnSelect();
|
}
|
|
|
void CExcelAutomation::AutoFitColumns( CString strCellAddrsrt, CString strCellAddr2end )
|
{
|
CRange range;
|
m_kRange = m_kSheet.get_Range(COleVariant(strCellAddrsrt), COleVariant(strCellAddr2end));
|
range = m_kRange.get_EntireColumn();
|
range.AutoFit();
|
}
|
|
void CExcelAutomation::SetColumnWidth( CString strCellAddr, long lWidth )
|
{
|
CRange range;
|
m_kRange = m_kSheet.get_Range(COleVariant(strCellAddr), COleVariant(strCellAddr));
|
range = m_kRange.get_EntireColumn();
|
range.put_ColumnWidth(COleVariant((double)lWidth));
|
}
|
|
|
void CExcelAutomation::SetForeColor( CString strCellAddrsrt, CString strCellAddr2end, COLORREF color )
|
{
|
/*
|
m_kRange = m_kSheet.get_Range(COleVariant(strCellAddrsrt),COleVariant(strCellAddr2end));
|
|
Cnterior interior;
|
interior = m_kRange.get_Interior();
|
interior.put_PatternColor(COleVariant((double)color));
|
*/
|
}
|
|
|
void CExcelAutomation::SetBackColor( CString strCellAddrsrt, CString strCellAddr2end, COLORREF color )
|
{
|
m_kRange = m_kSheet.get_Range(COleVariant(strCellAddrsrt),COleVariant(strCellAddr2end));
|
|
Cnterior interior;
|
interior = m_kRange.get_Interior();
|
interior.put_Color(COleVariant((double)color));
|
}
|
|
//Å׵θ® Àüü(Borders)
|
void CExcelAutomation::DrawBorders( CString strCellAddrsrt, CString strCellAddr2end, short iLineStyle, short iWeight )
|
{
|
m_kRange = m_kSheet.get_Range(COleVariant(strCellAddrsrt),COleVariant(strCellAddr2end));
|
|
CBorders borders;
|
borders = m_kRange.get_Borders();
|
borders.put_LineStyle(COleVariant(iLineStyle));//xlDouble = -4119
|
borders.put_Weight(COleVariant(iWeight));//xlThin = 2 //xlThick = 4
|
}
|
|
//Å׵θ® ÀϺÎ(Border)
|
void CExcelAutomation::DrawBorder(CString strCellAddrsrt, CString strCellAddr2end, short iLineStyle, short iWeight, long lBordersIndex)
|
{
|
/*<BordersIndex>
|
xlDiagonalDown 5
|
xlDiagonalUp 6,
|
xlEdgeBottom 9,
|
xlEdgeLeft 7,
|
xlEdgeRight 10,
|
xlEdgeTop 8,
|
xlInsideHorizontal 12
|
xlInsideVertical 11*/
|
m_kRange = m_kSheet.get_Range(COleVariant(strCellAddrsrt), COleVariant(strCellAddr2end));
|
CBorders borders = m_kRange.get_Borders();
|
CBorder border = borders.get_Item(lBordersIndex);
|
border.put_LineStyle(COleVariant(iLineStyle));//xlDouble = -4119
|
border.put_Weight(COleVariant(iWeight));//xlThin = 2 //xlThick = 4
|
}
|
|
void CExcelAutomation::SetHyperlink(CString strCellAddr, CString strCellLink, CString strScreenTip, CString strDisp)
|
{
|
CHyperlinks hyperlinks;
|
m_kRange = m_kSheet.get_Range(COleVariant(strCellAddr),COleVariant(strCellAddr));
|
m_kRange.Select();
|
hyperlinks = m_kRange.get_Hyperlinks();
|
// ³»ºÎ ÆÄÀÏ¿¡ ´ëÇÑ ÇÏÀÌÆÛ¸µ´Â SubAddress ÀÎÀÚ¸¦ »ç¿ë
|
// ½ºÅ©¸°ÆÁÀº 247¹ÙÀÌÆ®±îÁö¸¸ Çã¿ë
|
|
if( strScreenTip.GetLength() > MAX_LENGTH_SCREENTIP )
|
strScreenTip = strScreenTip.Left(MAX_LENGTH_SCREENTIP);
|
|
hyperlinks.Add( m_kRange, _T(""), COleVariant(strCellLink), COleVariant(strScreenTip), COleVariant(strDisp) );
|
|
// À¥ ÁÖ¼Ò µî¿¡ ´ëÇÑ ÇÏÀÌÆÛ¸µ´Â Address ÀÎÀÚ »ç¿ë
|
// hyperlinks.Add(LPDISPATCH Anchor, LPCTSTR Address, const VARIANT& SubAddress, const VARIANT& ScreenTip, const VARIANT& TextToDisplay);
|
}
|
|
void CExcelAutomation::MoveToCell( CString strSheetName, CString strCellAddr )
|
{
|
if(!SetActiveSheet(strSheetName))
|
return;
|
|
m_kRange = m_kSheet.get_Range(COleVariant(strCellAddr),COleVariant(strCellAddr));
|
m_kRange.Select();
|
}
|
|
void CExcelAutomation::MoveToCell( long lSheet, CString strCellAddr )
|
{
|
if(!SetActiveSheet(lSheet))
|
return;
|
|
m_kRange = m_kSheet.get_Range(COleVariant(strCellAddr),COleVariant(strCellAddr));
|
m_kRange.Select();
|
}
|
|
void CExcelAutomation::SetFormula( CString strCellAddrsrt, CString strCellAddr2end, CString strValue )
|
{
|
/* //¿¹½Ã
|
//C2:C6 ¼¿¿¡ (=A2 & " " & B2) ¼ö½Ä ¼³Á¤
|
m_range = m_worksheet.GetRange(COleVariant(strCellAddrsrt),COleVariant(strCellAddr2end));
|
m_range.SetFormula(COleVariant("=A2 & \" \" & B2"));
|
|
//Fill D2:D6 with a formula(=RAND()*100000) and apply a number format.
|
m_range = m_worksheet.GetRange(COleVariant("D2"), COleVariant("D6"));
|
m_range.SetFormula(COleVariant("=RAND()*100000"));
|
m_range.SetNumberFormat(COleVariant("$0.00"));
|
*/
|
//¼¿ÀÌ =·Î ½ÃÀÛÇØ¾ß ÇÑ´Ù.
|
//if(pastrRow[i]->GetAt(0).Find('=') == 0)
|
m_kRange = m_kSheet.get_Range(COleVariant(strCellAddrsrt),COleVariant(strCellAddr2end));
|
m_kRange.put_Formula(COleVariant(strValue));
|
}
|
|
long CExcelAutomation::GetNumRows()
|
{
|
m_kRange = m_kSheet.get_UsedRange();
|
CRange range = m_kRange.get_EntireRow();
|
return range.get_Count();
|
}
|
|
long CExcelAutomation::GetNumCols()
|
{
|
m_kRange = m_kSheet.get_UsedRange();
|
CRange range = m_kRange.get_EntireColumn();
|
return range.get_Count();
|
}
|
|
// (Range) Copy & Paste
|
BOOL CExcelAutomation::CopyRange( CString strPathNameSrc, long lSheetSrc, CString strCellAddrsrtSrc, CString strCellAddr2endSrc,
|
CString strPathNameDest, long lSheetDest, CString strCellAddrDest )
|
{
|
if(!ChangeActiveWorkbook(strPathNameSrc))
|
return FALSE;
|
|
if(!SetActiveSheet(lSheetSrc))
|
return FALSE;
|
|
// Copy to Clipboard
|
m_kRange = m_kSheet.get_Range(COleVariant(strCellAddrsrtSrc),COleVariant(strCellAddr2endSrc));
|
m_kRange.Copy( l_ValOptional );
|
|
// Select workbook for paste
|
CWorkbook workbook;
|
CString strPathNameDestTemp = _T("");
|
long lBook = 0;
|
|
for( lBook=1; lBook<=m_kBooks.get_Count(); lBook++ )
|
{
|
workbook = m_kBooks.get_Item(COleVariant(lBook));
|
strPathNameDestTemp = workbook.get_FullName();
|
|
if( strPathNameDest == strPathNameDestTemp )
|
break;
|
}
|
|
if( lBook > m_kBooks.get_Count() )
|
return FALSE;
|
|
// Select worksheet for Paste
|
CWorksheets worksheets = workbook.get_Worksheets();
|
CWorksheet worksheet = worksheets.get_Item(COleVariant(lSheetDest)); // sheets are indexed starting from 1
|
|
// ¹üÀ§¼³Á¤ÀÌ ¾øÀ¸¸é A1¼¿¿¡ ºÙ¿©³Ö±â
|
if( strCellAddrDest.IsEmpty() )
|
{
|
worksheet.Paste( l_ValOptional, l_ValOptional );
|
}
|
//¹üÀ§¼³Á¤ÀÌ ÀÖÀ¸¸é ÇØ´ç ¼¿¿¡ ºÙ¿©³Ö±â
|
else
|
{
|
CRange range = worksheet.get_Range(COleVariant(strCellAddrDest),COleVariant(strCellAddrDest));
|
/* PasteSpecial ÇÔ¼ö ù ÀÎÀÚ
|
xlPasteAll(±âº»°ª),xlPasteAllExceptBorders,xlPasteColumnWidths,xlPasteComments,xlPasteFormats,xlPasteFormulas,
|
xlPasteFormulasAndNumberFormats,xlPasteValidation,xlPasteValues,xlPasteValuesAndNumberFormats */
|
/* PasteSpecial ÇÔ¼ö µÑ° ÀÎÀÚ
|
xlPasteSpecialOperationAdd,xlPasteSpecialOperationDivide,xlPasteSpecialOperationMultiply,
|
xlPasteSpecialOperationNone(±âº»°ª),xlPasteSpecialOperationSubtract */
|
|
//³Ý° ÀÎÀÚ¸¦ TRUE·Î ¼³Á¤Çϸé Ç࿹ٲÞÀε¥, covTrue¸¦ ¹èÁ¤ÇÏ¸é ¿À·ù ¹ß»ý
|
range.PasteSpecial(xlPasteAll, xlPasteSpecialOperationNone, l_ValOptional, l_ValOptional);
|
}
|
|
return TRUE;
|
}
|
|
void CExcelAutomation::DeleteRange( CString strCellAddrsrt, CString strCellAddr2end, short iDeleteShiftDirection )
|
{
|
m_kRange = m_kSheet.get_Range(COleVariant(strCellAddrsrt),COleVariant(strCellAddr2end));
|
m_kRange.Delete(COleVariant((short) xlShiftUp));//xlShiftToLeft
|
}
|
|
void CExcelAutomation::SetRowHeight(const CString strStartSel, const CString strEndSel, short sHeight)
|
{
|
m_kRange = m_kSheet.get_Range(COleVariant(strStartSel),COleVariant(strEndSel));
|
m_kRange.put_RowHeight(COleVariant((short) sHeight));
|
}
|
|
float CExcelAutomation::GetRangeWidth(const CString strStartSel, const CString strEndSel)
|
{
|
m_kRange = m_kSheet.get_Range(COleVariant(strStartSel),COleVariant(strEndSel));
|
return m_kRange.get_Width().dblVal;
|
}
|
|
float CExcelAutomation::GetRangeHeight(const CString strStartSel, const CString strEndSel)
|
{
|
m_kRange = m_kSheet.get_Range(COleVariant(strStartSel),COleVariant(strEndSel));
|
return m_kRange.get_Height().dblVal;
|
}
|
|
BOOL CExcelAutomation::SetActiveSheetCell( DWORD dwSheetIndex, const CString strStartSel, const CString strEndSel )
|
{
|
if( dwSheetIndex < 1 || GetSheetCount() < dwSheetIndex )
|
return FALSE;
|
|
LPDISPATCH l_lpDisp = m_kSheets.get_Item(COleVariant((short)(dwSheetIndex)));
|
m_kSheet.AttachDispatch(l_lpDisp);
|
m_kSheet.Activate();
|
|
m_kSheet.get_Cells();
|
|
|
|
|
return TRUE;
|
}
|
|
void CExcelAutomation::GetCurrentRangeTopPosition(const CString strStartSel, const CString strEndSel)
|
{
|
m_kRange = m_kSheet.get_Range(COleVariant(strStartSel),COleVariant(strEndSel));
|
m_kRange.get_Top();
|
}
|
|
void CExcelAutomation::AutoFilter( CString strCellAddrsrt, CString strCellAddr2end )
|
{
|
m_kRange = m_kSheet.get_Range(COleVariant(strCellAddrsrt),COleVariant(strCellAddr2end));
|
m_kRange.AutoFilter( covTrue, l_ValOptional, (long) xlOr, l_ValOptional, covTrue );
|
}
|
|
void CExcelAutomation::AddComment( CString strSheetName, CString strCellAddr, CString strComment, float fWidth, float fHeight )
|
{
|
/* Sub Macro1()
|
ActiveCell.FormulaR1C1 = "a"
|
Range("A2").Select
|
ActiveCell.FormulaR1C1 = "b"
|
Range("A1").Select
|
Range("A1").AddComment
|
Range("A1").Comment.Visible = False
|
Range("A1").Comment.Text Text:="ÃÖ:" & Chr(10) & ""
|
Selection.ShapeRange.ScaleWidth 1.75, msoFalse, msoScaleFromTopLeft
|
Selection.ShapeRange.ScaleHeight 2.89, msoFalse, msoScaleFromTopLeft
|
Range("A1").Comment.Shape.Select True
|
Range("A1").Comment.Text Text:="ÃÖ:" & Chr(10) & ""
|
Selection.ShapeRange.ScaleHeight 1.16, msoFalse, msoScaleFromTopLeft
|
Selection.ShapeRange.ScaleWidth 1.25, msoFalse, msoScaleFromTopLeft
|
Range("A1").Comment.Shape.Select True
|
Range("A1").Comment.Text Text:="ÃÖ:" & Chr(10) & "abc" & Chr(10) & "" & Chr(10) & """Áñ°Üã±â""" & Chr(10) & "" & Chr(10) & "'Áñ°Üã±â'" & Chr(10) & ""
|
Range("A1").Select
|
End Sub
|
*/
|
SetActiveSheet(strSheetName);
|
m_kRange = m_kSheet.get_Range(COleVariant(strCellAddr), COleVariant(strCellAddr));
|
CComment comment1 = m_kRange.AddComment(COleVariant(strComment));
|
CString strComment1 = comment1.Text(COleVariant(_T("")), l_ValOptional, covTrue);
|
comment1.put_Visible(FALSE);
|
CShape shape1 = comment1.get_Shape();
|
shape1.put_Height(fHeight);
|
shape1.put_Width(fWidth);
|
|
CTextFrame textFrame1 = shape1.get_TextFrame();
|
CCharacters chars = textFrame1.Characters(covTrue, COleVariant((long)strComment1.GetLength()));
|
CFont0 font1 = chars.get_Font();
|
font1.put_Bold(covFalse);
|
font1.put_Size(COleVariant((short) 10));
|
font1.put_Name(COleVariant(_T("¸¼Àº °íµñ")));
|
}
|
|
void CExcelAutomation::SetConditionalFormat( CString strCellAddrsrt, CString strCellAddr2end, long lType, CString strFormula, COLORREF color )
|
{
|
// Á¶°ÇºÎ ¼½ÄÀº ÀÌ °æ¿ì ¸»°íµµ ´Ù¾çÇÏ°Ô Á¸ÀçÇϹǷΠÀÌ ÇÔ¼ö¸¸À¸·Î ÀüºÎ Ä¿¹öÇÒ ¼ö´Â ¾øÀ½
|
// µÎ°í º¸ÀÚ...
|
/*
|
Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Select
|
Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
|
"=MOD(SUBTOTAL(3,$A$3:$A3),2)=0"
|
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
|
With Selection.FormatConditions(1).Interior
|
.PatternColorIndex = xlAutomatic
|
.Color = 65535
|
.TintAndShade = 0
|
End With
|
Selection.FormatConditions(1).StopIfTrue = True
|
*/
|
m_kRange = m_kSheet.get_Range(COleVariant(strCellAddrsrt),COleVariant(strCellAddr2end));
|
CFormatConditions formatCons = m_kRange.get_FormatConditions();
|
CFormatCondition formatCon = formatCons.Add( lType,
|
l_ValOptional,
|
COleVariant(strFormula),
|
l_ValOptional,
|
l_ValOptional,
|
l_ValOptional,
|
l_ValOptional,
|
l_ValOptional );
|
formatCon.SetFirstPriority();
|
|
Cnterior inte = formatCon.get_Interior();
|
inte.put_PatternColorIndex(COleVariant((long)xlAutomatic));
|
inte.put_Color(COleVariant((double)color));
|
inte.put_PatternTintAndShade(COleVariant((long)0));
|
|
formatCon.put_StopIfTrue(TRUE);
|
}
|
|
|
void CExcelAutomation::Insert( CString strCellAddrsrt, CString strCellAddr2end, short iShiftDirection, short iCopyOrigin )
|
{
|
m_kRange = m_kSheet.get_Range(COleVariant(strCellAddrsrt),COleVariant(strCellAddr2end));
|
m_kRange.Select();
|
m_kRange.Insert(COleVariant((short)iShiftDirection), COleVariant((short)iCopyOrigin));
|
}
|
|
void CExcelAutomation::AutoFill( CString strCellAddrsrt1, CString strCellAddrsrt2, CString strCellAddr2end )
|
{
|
m_kRange = m_kSheet.get_Range(COleVariant(strCellAddrsrt1),COleVariant(strCellAddrsrt2));
|
m_kRange.Select();
|
CRange range = m_kSheet.get_Range(COleVariant(strCellAddrsrt1),COleVariant(strCellAddr2end));
|
m_kRange.AutoFill(range, xlFillDefault);
|
}
|
|
void CExcelAutomation::ClearContents( CString strCellAddrsrt, CString strCellAddr2end )
|
{
|
m_kRange = m_kSheet.get_Range(COleVariant(strCellAddrsrt),COleVariant(strCellAddr2end));
|
m_kRange.Select();
|
m_kRange.ClearContents();
|
}
|
|
char* CExcelAutomation::GetSheetCellPosition(int nCellIndex)
|
{
|
int nQuotient,nRemainder;
|
|
nQuotient = nCellIndex / 26;
|
nRemainder = nCellIndex % 26;
|
if(nQuotient == 0)
|
{
|
temp_buff[0] = nRemainder + 65;
|
temp_buff[1] = NULL;
|
return temp_buff;
|
}
|
else
|
{
|
if(26 < nQuotient) return NULL;
|
temp_buff[0] = nQuotient + 64;
|
temp_buff[1] = nRemainder + 65;
|
temp_buff[2] = NULL;
|
return temp_buff;
|
}
|
}
|
|
/// ¼³¸í : [ ÆäÀÌÁöÀÇ ¸Ó¸´¸» ²¿¸´¸»À» ¼³Á¤ÇÑ´Ù. ]
|
/// [ Data Format : Data ¹®±¸¿¡ ġȯµÇ´Â º¯¼ö &N : Àüü ÆäÀÌÁö ¹øÈ£ , &P : ÇöÁ¦ ÆäÀÌÁö¹øÈ£ , &D : ³¯Â¥ , &T ½Ã°£
|
void CExcelAutomation::SetPageHeaderFooter(BOOL bIsHeader,int nAlign, int nFontSize, const CString strFont, CString strData)
|
{
|
CString szFormat;
|
CPageSetup pagesetup;
|
|
|
pagesetup = m_kSheet.get_PageSetup();
|
|
///if(strlen(strData) != 0)
|
if(strData.GetLength() != 0)
|
{
|
///strData.Left(1)
|
if( isdigit(strData.GetAt(0)) )
|
szFormat.Format(_T("&\"%s\"&%d %s"), strFont, nFontSize, strData);
|
else
|
szFormat.Format(_T("&\"%s\"&%d %s"), strFont, nFontSize, strData);
|
}
|
|
switch( nAlign )
|
{
|
case 0:
|
if( bIsHeader )
|
pagesetup.put_LeftHeader(szFormat);
|
else
|
pagesetup.put_LeftFooter(szFormat);
|
break;
|
case 1:
|
if( bIsHeader )
|
pagesetup.put_CenterHeader(szFormat);
|
else
|
pagesetup.put_CenterFooter(szFormat);
|
break;
|
case 2:
|
if( bIsHeader)
|
pagesetup.put_RightHeader(szFormat);
|
else
|
pagesetup.put_RightFooter(szFormat);
|
break;
|
}
|
}
|
|
/// ¼³¸í : [ ÆäÀÌÁöÀÇ Á¤·Ä/Ãâ·Â ¹æÇâ/È®´ë¸¦ ¼³Á¤ÇÑ´Ù. ]
|
/// [ (Ãâ·Â¹æÇâ - 1 : ¼¼·Î, 2 : °¡·Î)(È®´ë : % ´ÜÀ§À̸ç 0 À̸é ÀÚµ¿¸ÂÃãÀÌ´Ù.)
|
void CExcelAutomation::SetPageControl(BOOL bCenterHorizontally, BOOL bCenterVertically, int nOutDirection, int nZoom)
|
{
|
CPageSetup pagesetup;
|
|
pagesetup = m_kSheet.get_PageSetup();
|
|
pagesetup.put_CenterHorizontally(bCenterHorizontally);
|
pagesetup.put_CenterVertically(bCenterVertically);
|
pagesetup.put_Orientation(nOutDirection);
|
pagesetup.put_Zoom(COleVariant((short)nZoom));
|
}
|
|
void CExcelAutomation::SetPageMargin(float Left, float Right, float Top, float Bottom, float Header, float Footer)
|
{
|
CPageSetup pagesetup;
|
|
pagesetup = m_kSheet.get_PageSetup();
|
|
pagesetup.put_LeftMargin(m_kApp.InchesToPoints(Left));
|
pagesetup.put_RightMargin(m_kApp.InchesToPoints(Right));
|
|
pagesetup.put_TopMargin(m_kApp.InchesToPoints(Top));
|
pagesetup.put_BottomMargin(m_kApp.InchesToPoints(Bottom));
|
|
pagesetup.put_HeaderMargin(m_kApp.InchesToPoints(Header));
|
pagesetup.put_FooterMargin(m_kApp.InchesToPoints(Footer));
|
}
|
|
void CExcelAutomation::FreezePanes(BOOL bIsValue)
|
{
|
if(!GetSelect()) return;
|
|
CWindow0 Win;
|
|
Win = m_kApp.get_ActiveWindow();
|
Win.put_FreezePanes(bIsValue);
|
}
|
|
//Ʋ°íÁ¤
|
//¸Þ´º¿¡¼ â->»õ âÀ» ¼±ÅÃÇϸé ÇϳªÀÇ workbookÀ» ¿©·¯ °³ÀÇ window°¡ Ç¥½ÃÇÏ°Ô ÇÒ ¼ö ÀÖ´Ù.
|
//¿©±â¿¡¼´Â ±»ÀÌ ¿©·¯ °³ÀÇ window·Î Ç¥½ÃµÈ »óȲÀ» °¡Á¤ÇÏÁö ¾ÊÀ¸¹Ç·Î 1¹ø window¸¦ Ʋ°íÁ¤ÇÑ´Ù.
|
void CExcelAutomation::SetFreezePanes( CString strSheetName, CString strCellAddr, BOOL bFreezePanes )
|
{
|
CWindows windows = m_kBook.get_Windows();
|
CWindow0 window = windows.get_Item(COleVariant((long)1));
|
|
SetActiveSheet( strSheetName );
|
m_kRange = m_kSheet.get_Range(COleVariant(strCellAddr), COleVariant(strCellAddr));
|
|
m_kRange.Select(); // Select¸¦ ÇÏÁö ¾ÊÀ¸¸é ¾û¶×ÇÑ ¼¿¿¡ Ʋ°íÁ¤ÀÌ µÈ´Ù.
|
window.put_FreezePanes(bFreezePanes);
|
}
|
|
void CExcelAutomation::SetFreezePanes( long nSheetIndex, CString strCellAddr, BOOL bFreezePanes )
|
{
|
CWindows windows = m_kBook.get_Windows();
|
CWindow0 window = windows.get_Item(COleVariant((long)1));
|
|
SetActiveSheet( nSheetIndex );
|
m_kRange = m_kSheet.get_Range(COleVariant(strCellAddr), COleVariant(strCellAddr));
|
|
m_kRange.Select(); // Select¸¦ ÇÏÁö ¾ÊÀ¸¸é ¾û¶×ÇÑ ¼¿¿¡ Ʋ°íÁ¤ÀÌ µÈ´Ù.
|
window.put_FreezePanes(bFreezePanes);
|
}
|
|
/*
|
.PrintHeadings = False
|
.PrintGridlines = False
|
.PrintComments = xlPrintNoComments
|
.PrintQuality = 600
|
|
.CenterHorizontally = True
|
.CenterVertically = False
|
|
.Orientation = xlPortrait
|
.Draft = False
|
.PaperSize = xlPaperA4
|
.FirstPageNumber = xlAutomatic
|
.Order = xlDownThenOver
|
.BlackAndWhite = False
|
|
.FitToPagesWide = 1 // ¿ëÁö ³Êºñ
|
.FitToPagesTall = 1 // ¿ëÁö ³ôÀÌ
|
.PrintErrors = xlPrintErrorsDisplayed
|
*/
|
|
void CExcelAutomation::PrintOut(int nSheetIndex, const CString strStartSel, const CString strEndSel, int nStartPage, int nEndPage, int nCopies, const CString strFileName)
|
{
|
Select( nSheetIndex, strStartSel, strEndSel );
|
|
m_kRange._PrintOut( COleVariant((short)nStartPage), // VARIANT& From
|
COleVariant((short)nEndPage), // VARIANT& To
|
COleVariant((short)nCopies), // VARIANT& Copies
|
covFalse, // VARIANT& Preview
|
l_ValOptional, // VARIANT& ActivePrinter
|
covFalse, // VARIANT& PrintToFile
|
covTrue, // VARIANT& Collate
|
COleVariant(m_Filename) ); // VARIANT& PrToFileName
|
}
|
|
/*
|
row,col ±¸Çϱâ
|
|
CRange range = sheet.get_UsedRange();
|
CRange rowRange = range.get_Rows();
|
CRange colRange = range.get_Columns();
|
|
|
long rowCount = rowRange.get_Count()
|
|
long colCount = colRange.get_Count()
|
|
Data_Row = m_kSheets.Cell(1A).End(xlDown).Row
|
*/
|
|
void CExcelAutomation::AddMemo(int nSheetIndex, const CString strSel, const CString strFillData)
|
{
|
if( !Select(nSheetIndex, strSel, strSel) )
|
return;
|
|
m_kRange.AddComment(COleVariant(strFillData));
|
}
|
|
void CExcelAutomation::AddTextBox( int nSheetIndex,
|
const CString strStartSel,
|
const CString strEndSel,
|
float nLeft,
|
float nTop,
|
float nWidth,
|
float nHeight,
|
short nSize,
|
BOOL bIsBold,
|
const CString strFillData )
|
{
|
int nDataResultTitle = strFillData.GetLength();
|
|
CShapes kShapes = m_kSheet.get_Shapes();
|
CShape kShape = kShapes.AddTextbox( nSheetIndex, nLeft, nTop, nWidth, nHeight );
|
|
CTextFrame kTextFrame = kShape.get_TextFrame();
|
|
CCharacters kCharacters = kTextFrame.Characters( COleVariant((long)0), COleVariant((long)nDataResultTitle) );
|
|
CFont0 font = kCharacters.get_Font();
|
|
font.put_Size(COleVariant(nSize));
|
font.put_Bold(bIsBold == TRUE ? covTrue:covFalse);
|
|
kCharacters.put_Text(strFillData);
|
}
|
|
void CExcelAutomation::InsertPicture( CString strPicture )
|
{
|
|
/*
|
Sub InsertPic()
|
Dim myPict As Picture
|
With ActiveSheet.Range("A1")
|
Set myPict = .Parent.Pictures.Insert("C:\ExportFile\calendar.gif")
|
myPict.Top = .Top
|
myPict.Left = .Left
|
myPict.Placement = xlMoveAndSize
|
End With
|
End Sub */
|
|
/*
|
CShapes shapes = m_kSheet.get_Shapes();
|
shapes.AddPicture(strPicture, FALSE, TRUE, 0, 0, 200, 200);
|
*/
|
// Delete Previous Pic
|
CPictures pics = m_kSheet.Pictures(l_ValOptional);
|
pics.Cut();
|
|
// Set Border
|
CPicture pic = pics.Insert(strPicture, l_ValOptional);
|
CBorder border = pic.get_Border();
|
border.put_Weight(COleVariant((const short)xlThin));
|
|
//¼¿ ³ôÀÌ ±¸Çϱâ
|
//VARIANT v = m_range.GetHeight();
|
//double d = v.dblVal;
|
//±×¸²ÀÇ ³ÐÀÌ/³ôÀÌ(Çȼ¿ ´ÜÀ§)
|
//double w = pic.GetWidth();
|
//double h = pic.GetHeight(); // in row height units
|
|
// Move Sheet Start pos
|
m_kRange = m_kSheet.get_Range(COleVariant(_T("A1")), COleVariant(_T("A1")));
|
m_kRange.Show();
|
}
|
|
double CExcelAutomation::GetImageWidth( CString strImagePath )
|
{
|
CPictures pics = m_kSheet.Pictures(l_ValOptional);
|
CPicture pic = pics.Insert(strImagePath, l_ValOptional);
|
|
return pic.get_Width();
|
}
|
|
double CExcelAutomation::GetImageHeight( CString strImagePath )
|
{
|
CPictures pics = m_kSheet.Pictures(l_ValOptional);
|
CPicture pic = pics.Insert(strImagePath, l_ValOptional);
|
|
return pic.get_Height();
|
}
|
|
///Select(int nSheetIndex, const CString strStartSel, const CString strEndSel)
|
void CExcelAutomation::InsertPicture( const CString strStartSel, const CString strEndSel, CString strImagePath, const int nLeft, const int nTop, const int nWidth, const int nHeight )
|
{
|
m_kRange = m_kSheet.get_Range(COleVariant(strStartSel),COleVariant(strEndSel));
|
|
CShapes shapes = m_kSheet.get_Shapes();
|
///shapes.AddPicture( strImagePath, FALSE, TRUE, nLeft, nTop, nWidth, nHeight );
|
|
TRACE(_T("%f, %f\n"), (float)m_kRange.get_Width().dblVal, (float)m_kRange.get_Height().dblVal );
|
|
shapes.AddPicture( strImagePath, FALSE, TRUE, (float)m_kRange.get_Left().dblVal+nLeft, (float)m_kRange.get_Top().dblVal+nTop, nWidth, nHeight );
|
}
|
|
void CExcelAutomation::InsertPicture( CString strImagePath, const int nLeft, const int nTop, const int nWidth, const int nHeight )
|
{
|
CShapes shapes = m_kSheet.get_Shapes();
|
shapes.AddPicture( strImagePath, FALSE, TRUE, nLeft, nTop, nWidth, nHeight );
|
}
|
|
int CExcelAutomation::ConvertAlphabet2Number( CString strAlpha ) // Convert Alphabet to Number (A:1, AA:27, ...)
|
{
|
int nConvertNum = 0;
|
for( int i = 0; i < strAlpha.GetLength(); i++ )
|
{
|
nConvertNum = nConvertNum * 26 + strAlpha[i] - 64;
|
}
|
|
return nConvertNum;
|
}
|
|
CString CExcelAutomation::ConvertNumber2Alphabet( int nNum )
|
{
|
CString strConvertAlpha = _T("");
|
while (nNum > 0) {
|
strConvertAlpha = (char)(65 + (nNum - 1) % 26) + strConvertAlpha;
|
nNum = (nNum - 1) / 26;
|
}
|
|
return strConvertAlpha;
|
}
|
|
BOOL CExcelAutomation::ConvertAlphabet2Number(char *pbVal, DWORD &pdwNumber)
|
{
|
DWORD dwIndex;
|
DWORD dwResult;
|
DWORD dwTmp;
|
char *pbIndex;
|
|
for( int i=0; i<16; i++ )
|
{
|
if( pbVal[i] == 0 )
|
{
|
dwIndex = i;
|
break;
|
}
|
}
|
|
dwResult = 0;
|
pbIndex = pbVal;
|
|
for( int i=dwIndex; i>0; i-- )
|
{
|
dwTmp = (*pbIndex) - 'A' + 1;
|
for( int j=i; j>1; j-- )
|
dwTmp *= 26;
|
|
dwResult += dwTmp;
|
*pbIndex++;
|
}
|
|
pdwNumber = dwResult;
|
return TRUE;
|
}
|
|
|
void CExcelAutomation::ShowException(LPOLESTR szMember, HRESULT hr, EXCEPINFO *pexcep, unsigned int uiArgErr)
|
{
|
TCHAR szBuf[512];
|
|
switch (GetScode(hr))
|
{
|
case DISP_E_UNKNOWNNAME:
|
wsprintf(szBuf, _T("%s: Unknown name or named argument."), szMember);
|
break;
|
|
case DISP_E_BADPARAMCOUNT:
|
wsprintf(szBuf, _T("%s: Incorrect number of arguments."), szMember);
|
break;
|
|
case DISP_E_EXCEPTION:
|
wsprintf(szBuf, _T("%s: Error %d: "), szMember, pexcep->wCode);
|
if (pexcep->bstrDescription != NULL)
|
lstrcat(szBuf, (char*)pexcep->bstrDescription);
|
else
|
lstrcat(szBuf, _T("<<No Description>>"));
|
break;
|
|
case DISP_E_MEMBERNOTFOUND:
|
wsprintf(szBuf, _T("%s: method or property not found."), szMember);
|
break;
|
|
case DISP_E_OVERFLOW:
|
wsprintf(szBuf, _T("%s: Overflow while coercing argument values."), szMember);
|
break;
|
|
case DISP_E_NONAMEDARGS:
|
wsprintf(szBuf, _T("%s: Object implementation does not support named arguments."),
|
szMember);
|
break;
|
|
case DISP_E_UNKNOWNLCID:
|
wsprintf(szBuf, _T("%s: The locale ID is unknown."), szMember);
|
break;
|
|
case DISP_E_PARAMNOTOPTIONAL:
|
wsprintf(szBuf, _T("%s: Missing a required parameter."), szMember);
|
break;
|
|
case DISP_E_PARAMNOTFOUND:
|
wsprintf(szBuf, _T("%s: Argument not found, argument %d."), szMember, uiArgErr);
|
break;
|
|
case DISP_E_TYPEMISMATCH:
|
wsprintf(szBuf, _T("%s: Type mismatch, argument %d."), szMember, uiArgErr);
|
break;
|
|
default:
|
wsprintf(szBuf, _T("%s: Unknown error occured."), szMember);
|
break;
|
}
|
|
MessageBox(NULL, szBuf, _T("OLE Error"), MB_OK | MB_ICONSTOP);
|
|
}
|