Ejemplo n.º 1
0
extern "C" HRESULT DAPI Iis7GetPropertyString(
    __in IAppHostElement *pElement,
    __in LPCWSTR wzPropName,
    __in LPWSTR* psczGet
    )
{
    HRESULT hr = S_OK;
    VARIANT vtGet;

    ::VariantInit(&vtGet);
    hr = Iis7GetPropertyVariant(pElement, wzPropName, &vtGet);
    ExitOnFailure1(hr, "Failed to get iis7 property variant with name: %ls", wzPropName);

    if (!ISSTRINGVARIANT(vtGet.vt))
    {
        hr = E_UNEXPECTED;
        ExitOnFailure1(hr, "Tried to get property as a string, but type was %d instead.", vtGet.vt);
    }

    hr = StrAllocString(psczGet, vtGet.bstrVal, 0);

LExit:
    ReleaseVariant(vtGet);

    return hr;
}
Ejemplo n.º 2
0
//Perform Worksheets.Cells(x,y).Value = szStr
BOOL CXLAutomation::SetCellsValueToString(double Column, double Row, CString szStr)
{
	if(NULL == m_pdispWorksheet)
		return FALSE;
	if(szStr.IsEmpty())
		return FALSE;
	long nBuffSize = szStr.GetLength();
	

	VARIANTARG vargRng;
	
	ClearAllArgs();
	AddArgumentDouble(NULL, 0, Column);
	AddArgumentDouble(NULL, 0, Row);
	if(!ExlInvoke(m_pdispWorksheet, L"Cells",&vargRng, DISPATCH_PROPERTYGET, DISP_FREEARGS))
		return FALSE;

    AddArgumentCString(NULL, 0, szStr );
	if (!ExlInvoke(vargRng.pdispVal, L"Value", NULL, DISPATCH_PROPERTYPUT, 0))
		return FALSE;


	if(ReleaseVariant(&vargRng)>=1)
	{
	
	CString error;
	error.Format("Error in outputing row %d, colume %d, value %s", Row, Column, szStr);
	AfxMessageBox(error);
	}
	
	
	return TRUE;
}
Ejemplo n.º 3
0
//Perform Worksheets.Cells(x,y).Value = szStr
BOOL CXLAutomation::SetCellsValueToString(double Column, double Row, CString szStr)
{
	if(NULL == m_pdispWorksheet)
		return FALSE;
	if(szStr.IsEmpty())
		return FALSE;
	long nBuffSize = szStr.GetLength();
	

	VARIANTARG vargRng;
	
	ClearAllArgs();
	AddArgumentDouble(NULL, 0, Column);
	AddArgumentDouble(NULL, 0, Row);
	if(!ExlInvoke(m_pdispWorksheet, L"Cells",&vargRng, DISPATCH_PROPERTYGET, DISP_FREEARGS))
		return FALSE;

    AddArgumentCString(NULL, 0, szStr );
	if (!ExlInvoke(vargRng.pdispVal, L"Value", NULL, DISPATCH_PROPERTYPUT, 0))
		return FALSE;
	ReleaseVariant(&vargRng);
	
	
	return TRUE;
}
Ejemplo n.º 4
0
//Create an empty worksheet
int CXLAutomation::AddNewWorkSheet()
{
	if(NULL == m_pdispExcelApp)
		return -1;

	BOOL fResult;
	VARIANTARG varg1, varg2;
	IDispatch *pdispRange = NULL;
	IDispatch *pdispActiveSheet = NULL;
	IDispatch *pdispActiveCell = NULL;
	IDispatch *pdispCrt = NULL;
	

	
	// Set wb = [application].Workbooks.Add(template := xlWorksheet)
	ClearAllArgs();
	if (!ExlInvoke(m_pdispExcelApp, L"Workbooks", &varg1, DISPATCH_PROPERTYGET, 0))
		return -1;
	
	//First time here: no workbook yet. Create new workbook.
	if(NULL == m_pdispWorkbook)
	{
		ClearAllArgs();
		AddArgumentInt2(L"Template", 0, xlWorksheet);
		fResult = ExlInvoke(varg1.pdispVal, L"Add", &varg2, DISPATCH_METHOD, 0);
		ReleaseVariant(&varg1);
		if (!fResult)
			return -1;
		m_pdispWorkbook = varg2.pdispVal;
	
	
		// Set ws = wb.Worksheets(nNextWorksheet)
		ClearAllArgs();
		AddArgumentInt2(NULL, 0, 1);
		if (!ExlInvoke(m_pdispWorkbook, L"Worksheets", &varg2, DISPATCH_PROPERTYGET, 0))
			return -1;
		m_pdispActiveWorksheet = varg2.pdispVal;

		return GetWorksheetsCount();
	}

	//Add a new worksheet to the existing workbook
	ClearAllArgs();
	if(!ExlInvoke(m_pdispWorkbook, L"Sheets",&varg1, DISPATCH_PROPERTYGET, DISP_FREEARGS))
		return -1;
	if (!ExlInvoke(varg1.pdispVal, L"Add", &varg2, DISPATCH_PROPERTYGET, 0))
		return -1;
	
	m_pdispActiveWorksheet = varg2.pdispVal;
		
	return GetWorksheetsCount();
}
Ejemplo n.º 5
0
//Create an empty workshet
BOOL CXLAutomation::CreateWorkSheet()
{
	if(NULL == m_pdispExcelApp)
		return FALSE;

	BOOL fResult;
	VARIANTARG varg1, varg2;
	IDispatch *pdispRange = NULL;
	IDispatch *pdispActiveSheet = NULL;
	IDispatch *pdispActiveCell = NULL;
	IDispatch *pdispCrt = NULL;
	

	
	// Set wb = [application].Workbooks.Add(template := xlWorksheet)
	ClearAllArgs();
	if (!ExlInvoke(m_pdispExcelApp, L"Workbooks", &varg1, DISPATCH_PROPERTYGET, 0))
		return FALSE;
	
	
	ClearAllArgs();
	AddArgumentInt2(L"Template", 0, xlWorksheet);
	fResult = ExlInvoke(varg1.pdispVal, L"Add", &varg2, DISPATCH_METHOD, 0);
	ReleaseVariant(&varg1);
	if (!fResult)
		return FALSE;
	m_pdispWorkbook = varg2.pdispVal;
	
	// Set ws = wb.Worksheets(1)
	ClearAllArgs();
	AddArgumentInt2(NULL, 0, 1);
	if (!ExlInvoke(m_pdispWorkbook, L"Worksheets", &varg2, DISPATCH_PROPERTYGET, 0))
		goto CreateWsBail;
	m_pdispWorksheet = varg2.pdispVal;

	fResult = TRUE;

CreateWsExit:
	
	if (pdispRange != NULL)
		pdispRange->Release();
	if (pdispCrt != NULL)
		pdispCrt->Release();
	return fResult;
	
CreateWsBail:
	fResult = FALSE;
	goto CreateWsExit;

}
Ejemplo n.º 6
0
/*
 *  ClearAllArgs
 *
 *  Clears the existing contents of the arg array in preparation for
 *  a new invocation.  Frees argument memory if so marked.
 */
void CXLAutomation::ClearAllArgs()
{
	int i;
	
	for (i = 0; i < m_iArgCount; i++) 
	{
		if (m_awFlags[i] & DISPARG_NOFREEVARIANT)
			// free the variant's contents based on type
			ClearVariant(&m_aVargs[i]);
		else
			ReleaseVariant(&m_aVargs[i]);
	}

	m_iArgCount = 0;
	m_iNamedArgCount = 0;

}
Ejemplo n.º 7
0
void ClearAllArgs()
{
    int i;




    for (i = 0; i < g_iArgCount; i++) 
    {
        if (g_awFlags[i] & DISPARG_NOFREEVARIANT)
            // free the variant's contents based on type
            ClearVariant(&g_aVargs[i]);
        else
            ReleaseVariant(&g_aVargs[i]);
    }

    g_iArgCount = 0;
    g_iNamedArgCount = 0;
}
Ejemplo n.º 8
0
BOOL CXLAutomation::SetRangeValueDouble(LPOLESTR lpszRef, double d)
{
	if(NULL == m_pdispWorksheet)
		return FALSE;

	VARIANTARG vargRng;
	BOOL fResult;
	
	ClearAllArgs();
	AddArgumentOLEString(NULL, 0, lpszRef);
	if (!ExlInvoke(m_pdispWorksheet, L"Range", &vargRng, DISPATCH_PROPERTYGET, DISP_FREEARGS))
		return FALSE;
	
	AddArgumentDouble(NULL, 0, d);
	fResult = ExlInvoke(vargRng.pdispVal, L"Value", NULL, DISPATCH_PROPERTYPUT, 0);
	ReleaseVariant(&vargRng);
	
	return fResult;

}
Ejemplo n.º 9
0
extern "C" HRESULT DAPI Iis7PutPropertyString(
    __in IAppHostElement *pElement,
    __in LPCWSTR wzPropName,
    __in LPCWSTR wzString
    )
{
    HRESULT hr = S_OK;
    VARIANT vtPut;

    ::VariantInit(&vtPut);
    vtPut.vt = VT_BSTR;
    vtPut.bstrVal = ::SysAllocString(wzString);
    ExitOnNull(vtPut.bstrVal, hr, E_OUTOFMEMORY, "failed SysAllocString");

    hr = Iis7PutPropertyVariant(pElement, wzPropName, vtPut);

LExit:
    ReleaseVariant(vtPut);

    return hr;
}
Ejemplo n.º 10
0
//Copy string to clipboard and paste it to worksheet
BOOL CXLAutomation::PasteStringToWorksheet(CString pDataBuffer)
{
	if(NULL == m_pdispWorksheet)
		return FALSE;
	if(pDataBuffer.IsEmpty())
		return FALSE;

	long nBuffSize = pDataBuffer.GetLength(); 
	//Nothing to copy
	if(0 == nBuffSize)
		return FALSE;

	HANDLE hMem = GlobalAlloc(GMEM_MOVEABLE|GMEM_DDESHARE, 24);
  
	  if (OpenClipboard(NULL) )
	  {
		HGLOBAL hClipMem;
		char* buffer;
		BOOL bResult = TRUE;
		
		EmptyClipboard();
		hClipMem = GlobalAlloc(GMEM_DDESHARE, nBuffSize);
		buffer = (char*)GlobalLock(hClipMem);
		memcpy(buffer, pDataBuffer, nBuffSize);
		GlobalUnlock(hClipMem);
		SetClipboardData(CF_TEXT, hClipMem);
		CloseClipboard();
		
		//Paste data from clipboard
		// set sourceRange = ws.Range("A1")
		IDispatch* pdispRange = NULL;
		VARIANTARG varg1, varg2;

		ClearAllArgs();
		AddArgumentOLEString(NULL, 0, L"A1");
		if (!ExlInvoke(m_pdispWorksheet, L"Range", &varg2, DISPATCH_PROPERTYGET, DISP_FREEARGS))
			return FALSE;
		pdispRange = varg2.pdispVal;


		//Force past from clipboard
		//set as = sourceRange.Select
		ClearAllArgs();
		if (!ExlInvoke(pdispRange, L"Select", &varg2, DISPATCH_PROPERTYGET, DISP_FREEARGS))
			goto Failed;

		// set wb.ActiveSheet.Paste
		ClearAllArgs();
		if (!ExlInvoke(m_pdispWorkbook, L"ActiveSheet", &varg1, DISPATCH_PROPERTYGET, 0))
			goto Failed;
		ClearAllArgs();

		// set wb.ActiveSheet.Paste
		ClearAllArgs();
		if (!ExlInvoke(m_pdispWorkbook, L"ActiveSheet", &varg1, DISPATCH_PROPERTYGET, 0))
			goto Failed;
		ClearAllArgs();
		bResult = ExlInvoke(varg1.pdispVal, L"Paste", &varg2, DISPATCH_METHOD, 0);
		ReleaseVariant(&varg1);
	
		goto Success;

Failed:
		bResult = FALSE;
Success:
		if(NULL != pdispRange)
		{
			pdispRange->Release();
			pdispRange = NULL;
		}

		return bResult;
	  }
	  return FALSE;

}
Ejemplo n.º 11
0
//Create XY chart. Y values are in column nYColumn.
BOOL CXLAutomation::CreateXYChart(int nYColumn)
{
	if(NULL == m_pdispWorksheet)
		return FALSE;

	BOOL fResult;
	VARIANTARG varg1, varg2;
	IDispatch *pdispRange = NULL;
	IDispatch *pdispCrt = NULL;

		
	// set sourceRange = ws.Columns(nYColumn)
	ClearAllArgs();
	AddArgumentDouble(NULL, 0, nYColumn);
	if (!ExlInvoke(m_pdispWorksheet, L"Columns", &varg2, DISPATCH_PROPERTYGET, DISP_FREEARGS))
		goto CreateChartBail;
	pdispRange = varg2.pdispVal;
	
	// set crt = wb.Charts.Add
	ClearAllArgs();
	if (!ExlInvoke(m_pdispWorkbook, L"Charts", &varg1, DISPATCH_PROPERTYGET, 0))
		goto CreateChartBail;
	ClearAllArgs();
	fResult = ExlInvoke(varg1.pdispVal, L"Add", &varg2, DISPATCH_METHOD, 0);
	ReleaseVariant(&varg1);
	if (!fResult)
		goto CreateChartBail;
	pdispCrt = varg2.pdispVal;

	ClearAllArgs();
	if (!ExlInvoke(m_pdispWorkbook, L"ActiveChart", &varg1, DISPATCH_PROPERTYGET, 0))
		goto CreateChartBail;
	m_pdispActiveChart = varg1.pdispVal;

	ClearAllArgs();
	AddArgumentInt2(NULL, 0, xlXYScatterLinesNoMarkers);
	if (!ExlInvoke(m_pdispActiveChart, L"ChartType", &varg1, DISPATCH_PROPERTYPUT, 0))
		goto CreateChartBail;

	//Charts.Add
    //ActiveChart.ChartType = xlXYScatterLinesNoMarkers
    //ActiveChart.SetSourceData Source:=Sheets("Sheet1").Range("A:A, B:B"), PlotBy:= _
    //    xlColumns
	ClearAllArgs();
	AddArgumentInt2(L"PlotBy", 0, xlColumns);
	AddArgumentDispatch(L"Source", 0, pdispRange);	// will auto-free
	pdispRange = NULL;
	if (!ExlInvoke(m_pdispActiveChart, L"SetSourceData", NULL, DISPATCH_METHOD, DISP_FREEARGS))
		goto CreateChartBail;


	fResult = TRUE;

CreateChartExit:
	if (pdispRange != NULL)
		pdispRange->Release();
	if (pdispCrt != NULL)
		pdispCrt->Release();
	return fResult;
	
CreateChartBail:
	fResult = FALSE;
	goto CreateChartExit;

	return TRUE;

}
Ejemplo n.º 12
0
/*
 *  ReleaseVariant
 *
 *  Clears a particular variant structure and releases any external objects
 *  or memory contained in the variant.  Supports the data types listed above.
 */
int CXLAutomation::ReleaseVariant(VARIANTARG *pvarg)
{
	VARTYPE vt;
	VARIANTARG *pvargArray;
	long lLBound, lUBound, l;
	
	vt = pvarg->vt & 0xfff;		// mask off flags
	
	// check if an array.  If so, free its contents, then the array itself.
	if (V_ISARRAY(pvarg)) 
	{
		// variant arrays are all this routine currently knows about.  Since a
		// variant can contain anything (even other arrays), call ourselves
		// recursively.
		if (vt == VT_VARIANT) 
		{
			SafeArrayGetLBound(pvarg->parray, 1, &lLBound);
			SafeArrayGetUBound(pvarg->parray, 1, &lUBound);
			
			if (lUBound > lLBound) 
			{
				lUBound -= lLBound;
				
				SafeArrayAccessData(pvarg->parray, (void**)&pvargArray);
				
				for (l = 0; l < lUBound; l++) 
				{
					ReleaseVariant(pvargArray);
					pvargArray++;
				}
				
				SafeArrayUnaccessData(pvarg->parray);
			}
		}
		else 
		{
			return 1; //  non-variant type

			// MessageBox(NULL, _T("ReleaseVariant: Array contains non-variant type"), "Failed", MB_OK | MB_ICONSTOP);
		}
		
		// Free the array itself.
		SafeArrayDestroy(pvarg->parray);
	}
	else 
	{
		switch (vt) 
		{
			case VT_DISPATCH:
				//(*(pvarg->pdispVal->lpVtbl->Release))(pvarg->pdispVal);
				pvarg->pdispVal->Release();
				break;
				
			case VT_BSTR:
				SysFreeString(pvarg->bstrVal);
				break;
				
			case VT_I2:
			case VT_BOOL:
			case VT_R8:
			case VT_ERROR:		// to avoid erroring on an error return from Excel
				// no work for these types
				break;
				
			default:

				return 2; //unknonw type
				// MessageBox(NULL, _T("ReleaseVariant: Unknown type"), "Failed", MB_OK | MB_ICONSTOP);
				break;
		}
	}
	
	ClearVariant(pvarg);
	return 0;

}
Ejemplo n.º 13
0
//Set chart's X and Y titles by executing this macros:
//ActiveChart.ChartArea.Select
//ActiveChart.Axes(xlCategory, xlPrimary).HasTitle = True
//ActiveChart.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = szXTitle
//ActiveChart.Axes(xlValue, xlPrimary).HasTitle = True
// ActiveChart.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = szYTitle
//xlCategory = 1
//xlPrimary = 1
//xlValue = 2
BOOL CXLAutomation::SetAxesTitle(CString szXTitle, CString szYTitle)
{
	//Leave if there is no chart
	if(NULL == m_pdispActiveChart)
		return FALSE;
	
	int xlCategory = 1;
	int xlPrimary = 1;
	int xlValue = 2;
	VARIANTARG varg1, varg2;

	//Select chart: ActiveChart.ChartArea.Select
	ClearAllArgs();
	if(!ExlInvoke(m_pdispActiveChart, L"ChartArea",&varg1, DISPATCH_PROPERTYGET, DISP_FREEARGS)) //DISP_FREEARGS))
		return FALSE;
	ClearAllArgs();
	if (!ExlInvoke(varg1.pdispVal, L"Select", NULL, DISPATCH_PROPERTYGET, DISP_FREEARGS))
		return FALSE;
	
	//Set title only if the title has been provided by user
	if(!szXTitle.IsEmpty())
	{
			//ActiveChart.Axes(xlCategory, xlPrimary).HasTitle = True
			ClearAllArgs();
			AddArgumentInt2(NULL, 0, xlPrimary);
			AddArgumentInt2(NULL, 0, xlCategory);
			if(!ExlInvoke(m_pdispActiveChart, L"Axes",&varg2, DISPATCH_PROPERTYGET, DISP_FREEARGS))
				return FALSE;
			
			ClearAllArgs();
			AddArgumentBool(NULL, 0, TRUE);
			if(!ExlInvoke(varg2.pdispVal, L"HasTitle",NULL, DISPATCH_PROPERTYPUT, DISP_FREEARGS))
				return FALSE;

			//ActiveChart.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = szXTitle
			VARIANTARG vargTitle, vargChar;
			ClearAllArgs();
			if (!ExlInvoke(varg2.pdispVal, L"AxisTitle", &vargTitle, DISPATCH_PROPERTYGET, 0))
				return FALSE;
			ClearAllArgs();
			if (!ExlInvoke(vargTitle.pdispVal, L"Characters", &vargChar, DISPATCH_PROPERTYGET, 0))
				return FALSE;
			ClearAllArgs();
			AddArgumentCString(NULL, 0, szXTitle);
			if (!ExlInvoke(vargTitle.pdispVal, L"Text", NULL, DISPATCH_PROPERTYPUT, 0))
				return FALSE;

			ReleaseVariant(&vargChar);
			ReleaseVariant(&vargTitle);
			ReleaseVariant(&varg2);
	}
	
	if(!szYTitle.IsEmpty())
	{
			//ActiveChart.Axes(xlValue, xlPrimary).HasTitle = True
			ClearAllArgs();
			AddArgumentInt2(NULL, 0, xlPrimary);
			AddArgumentInt2(NULL, 0, xlValue);
			if(!ExlInvoke(m_pdispActiveChart, L"Axes",&varg2, DISPATCH_PROPERTYGET, DISP_FREEARGS))
				return FALSE;
			
			ClearAllArgs();
			AddArgumentBool(NULL, 0, TRUE);
			if(!ExlInvoke(varg2.pdispVal, L"HasTitle",NULL, DISPATCH_PROPERTYPUT, DISP_FREEARGS))
				return FALSE;

			//ActiveChart.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = szYTitle
			VARIANTARG vargTitle, vargChar;
			ClearAllArgs();
			if (!ExlInvoke(varg2.pdispVal, L"AxisTitle", &vargTitle, DISPATCH_PROPERTYGET, 0))
				return FALSE;
			ClearAllArgs();
			if (!ExlInvoke(vargTitle.pdispVal, L"Characters", &vargChar, DISPATCH_PROPERTYGET, 0))
				return FALSE;
			ClearAllArgs();
			AddArgumentCString(NULL, 0, szYTitle);
			if (!ExlInvoke(vargTitle.pdispVal, L"Text", NULL, DISPATCH_PROPERTYPUT, 0))
				return FALSE;
	}

	return TRUE;
}
Ejemplo n.º 14
0
/*******************************************************************
 XmlLoadDocumentFromFileEx

********************************************************************/
extern "C" HRESULT DAPI XmlLoadDocumentFromFileEx(
    __in_z LPCWSTR wzPath,
    __in DWORD dwAttributes,
    __out IXMLDOMDocument** ppixdDocument
    )
{
    HRESULT hr = S_OK;
    VARIANT varPath;
    VARIANT_BOOL vbSuccess = 0;

    IXMLDOMDocument* pixd = NULL;
    IXMLDOMParseError* pixpe = NULL;

    ::VariantInit(&varPath);
    varPath.vt = VT_BSTR;
    varPath.bstrVal = ::SysAllocString(wzPath);
    ExitOnNull(varPath.bstrVal, hr, E_OUTOFMEMORY, "failed to allocate bstr for Path in XmlLoadDocumentFromFileEx");

    hr = XmlCreateDocument(NULL, &pixd);
    if (hr == S_FALSE)
    {
        hr = E_FAIL;
    }
    ExitOnFailure(hr, "failed XmlCreateDocument");

    if (dwAttributes & XML_LOAD_PRESERVE_WHITESPACE)
    {
        hr = pixd->put_preserveWhiteSpace(VARIANT_TRUE);
        ExitOnFailure(hr, "failed put_preserveWhiteSpace");
    }

    // Avoid triggering anything external.
    hr = pixd->put_validateOnParse(VARIANT_FALSE);
    ExitOnFailure(hr, "failed put_validateOnParse");
    hr = pixd->put_resolveExternals(VARIANT_FALSE);
    ExitOnFailure(hr, "failed put_resolveExternals");

    pixd->put_async(VARIANT_FALSE);
    hr = pixd->load(varPath, &vbSuccess);
    if (S_FALSE == hr)
    {
        hr = HRESULT_FROM_WIN32(ERROR_OPEN_FAILED);
    }

    if (FAILED(hr) && S_OK == pixd->get_parseError(&pixpe))
    {
        XmlReportParseError(pixpe);
    }

    ExitOnFailure1(hr, "failed to load XML from: %ls", wzPath);

    if (ppixdDocument)
    {
        *ppixdDocument = pixd;
        pixd = NULL;
    }

    hr = S_OK;
LExit:
    ReleaseVariant(varPath);
    ReleaseObject(pixd);
    ReleaseObject(pixpe);

    return hr;
}
Ejemplo n.º 15
0
//Insert image to worksheet using clipboard
BOOL CXLAutomation::InsertPictureToWorksheet(BYTE *pImage, int Column, int Row, double dPicWidth, double dPicHeight)
{
	//Place image to clipboard
	if(NULL != pImage)
		if(!PlaceImageToClipboard(pImage))
			return FALSE;
	
	//Select cell where you want copy the picture (i.e., the top left corner of the picture
	//Leave if Column and Row are outside the worksheet
	if((Column < 1) || (Row < 1))
		return FALSE;

	VARIANTARG vargCell, vargActiveCell;
	VARIANTARG vargActiveSelection;
	
	ClearAllArgs();
	AddArgumentDouble(NULL, 0, Column);
	AddArgumentDouble(NULL, 0, Row);
	if(!ExlInvoke(m_pdispWorksheet, L"Cells",&vargCell, DISPATCH_PROPERTYGET, DISP_FREEARGS))
		return FALSE;
	ClearAllArgs();
	if(!ExlInvoke(vargCell.pdispVal, L"Select",&vargActiveCell, DISPATCH_PROPERTYGET, DISP_FREEARGS))
		return FALSE;
	ReleaseVariant(&vargCell);
	ReleaseVariant(&vargActiveCell);

	//Paste image from clipboard
	//by runing:
	//ActiveSheet.Paste
	ClearAllArgs();
	if (!ExlInvoke(m_pdispWorksheet, L"Paste", &vargActiveSelection, DISPATCH_PROPERTYGET, DISP_FREEARGS))
		return FALSE;
	ReleaseVariant(&vargActiveSelection);

	//Select image
	if (!ExlInvoke(m_pdispWorksheet, L"Pictures", &vargActiveSelection, DISPATCH_PROPERTYGET, DISP_FREEARGS))
		return FALSE;
	//Resize image
	if((dPicWidth != 0.0) && (dPicHeight != 0.0))
	{
	
		//Run this macros to resize the picture:
		//Selection.ShapeRange.ScaleWidth dPicWidth, msoFalse, msoScaleFromTopLeft
		//Selection.ShapeRange.ScaleHeight dPicWidth, msoFalse, msoScaleFromTopLeft
		VARIANTARG vargImage;
		ClearAllArgs();
		if (!ExlInvoke(vargActiveSelection.pdispVal, L"ShapeRange", &vargImage, DISPATCH_PROPERTYGET, DISP_FREEARGS))
			return FALSE;

		ClearAllArgs();
		//msoScaleFromTopLeft = 0 - this argument indicate scaling from top left
		AddArgumentInt2(NULL, 0, 0);
		AddArgumentDouble(NULL, 0, dPicWidth);
     	if (!ExlInvoke(vargImage.pdispVal, L"ScaleWidth", NULL, DISPATCH_METHOD, 0)) //DISP_FREEARGS))
			return FALSE;
		if (!ExlInvoke(vargImage.pdispVal, L"ScaleHeight", NULL, DISPATCH_METHOD, 0)) //DISP_FREEARGS))
			return FALSE;
		ClearAllArgs();
		ReleaseVariant(&vargImage);
		
	}
	ReleaseVariant(&vargActiveSelection);
	return TRUE;
}
Ejemplo n.º 16
0
//Insert picture from file szFileName to worksheet
//The left top corner of the picture is position in (Column, nRow)  
//on the worksheet
//Size of the picture in % of original size is given by dPicWidth, dPicHeight
//If dPicWidth = 0.0, dPicHeight = 0.0 or dPicWidth = 1.0, dPicHeight = 1.0
//the picture has default (i.e., original) size 
BOOL CXLAutomation::InsertPictureToWorksheet(CString szFileName, int Column, int Row, double dPicWidth, double dPicHeight)
{
	//No file name provided. Leave. 
	if(szFileName.IsEmpty())
		return FALSE;
	if(NULL == m_pdispWorksheet)
		return FALSE;

	//First, select cell where you want copy the picture (i.e., the top left corner of the picture
	//Leave if Column and Row are outside the worksheet
	if((Column < 1) || (Row < 1))
		return FALSE;

	VARIANTARG vargRng, vargActiveCell;
	VARIANTARG varg1, varg2;
	
	ClearAllArgs();
	AddArgumentDouble(NULL, 0, Column);
	AddArgumentDouble(NULL, 0, Row);
	if(!ExlInvoke(m_pdispWorksheet, L"Cells",&vargRng, DISPATCH_PROPERTYGET, DISP_FREEARGS))
		return FALSE;
	ClearAllArgs();
	if(!ExlInvoke(vargRng.pdispVal, L"Select",&vargActiveCell, DISPATCH_PROPERTYGET, DISP_FREEARGS))
		return FALSE;
	ReleaseVariant(&vargRng);
	ReleaseVariant(&vargActiveCell);

	//Run this macros to incert picture from file 
	//ActiveSheet.Pictures.Insert("c:\mypicture.bmp").Select
	//or
	//ActiveSheet.Pictures.Insert ("C:\mypicture.bmp")
    //ActiveSheet.Pictures.ShapeRange.ScaleWidth 0.31, msoScaleFromTopLeft
	ClearAllArgs();
	if (!ExlInvoke(m_pdispWorksheet, L"Pictures", &varg1, DISPATCH_PROPERTYGET, DISP_FREEARGS))
		return FALSE;
	ClearAllArgs();
	AddArgumentCString(NULL, 0, szFileName);
	if (!ExlInvoke(varg1.pdispVal, L"Insert", &varg2, DISPATCH_PROPERTYGET, DISP_FREEARGS))
		return FALSE;

	if((dPicWidth != 0.0) && (dPicHeight != 0.0))
	{

		//Run this macros to resize the picture:
		//Selection.ShapeRange.ScaleWidth dPicWidth, msoFalse, msoScaleFromTopLeft
		//Selection.ShapeRange.ScaleHeight dPicWidth, msoFalse, msoScaleFromTopLeft
		VARIANTARG vargImage;
		ClearAllArgs();
		if (!ExlInvoke(varg1.pdispVal, L"ShapeRange", &vargImage, DISPATCH_PROPERTYGET, DISP_FREEARGS))
			return FALSE;

		ClearAllArgs();
		//msoScaleFromTopLeft = 0 - this argument indicate scaling from top left
		AddArgumentInt2(NULL, 0, 0);
		AddArgumentDouble(NULL, 0, dPicWidth);
     	if (!ExlInvoke(vargImage.pdispVal, L"ScaleWidth", NULL, DISPATCH_METHOD, 0)) //DISP_FREEARGS))
			return FALSE;
		if (!ExlInvoke(vargImage.pdispVal, L"ScaleHeight", NULL, DISPATCH_METHOD, 0)) //DISP_FREEARGS))
			return FALSE;
		ClearAllArgs();
		ReleaseVariant(&vargImage);
		
	}
	ReleaseVariant(&varg1);
	ReleaseVariant(&varg2);
	return TRUE;
}
Ejemplo n.º 17
0
void ReleaseVariant(VARIANTARG *pvarg)
{
    VARTYPE vt;
    VARIANTARG HUGEP *pvargArray;
    long lLBound, lUBound, l;

    vt = pvarg->vt & 0xfff;        // mask off flags

    // check if an array.  If so, free its contents, 
    // then the array itself.
    if (V_ISARRAY(pvarg)) 
    {
        // variant arrays are all this routine currently knows about.
        // Since a variant can contain anything (even other arrays), 
        // call ourselves recursively.
        if (vt == VT_VARIANT) 
        {
            SafeArrayGetLBound(pvarg->parray, 1, &lLBound);
            SafeArrayGetUBound(pvarg->parray, 1, &lUBound);

            if (lUBound > lLBound) 
            {
                lUBound -= lLBound;

                SafeArrayAccessData(pvarg->parray,(void **) &pvargArray);




                for (l = 0; l < lUBound; l++) 
                {
                    ReleaseVariant(pvargArray);
                    pvargArray++;
                }

                SafeArrayUnaccessData(pvarg->parray);
            }
        }
        else 
        {
            MessageBox(g_hwndApp, "ReleaseVariant: Array contains non-variant type", g_szAppTitle, MB_OK | MB_ICONSTOP);
        }

        // Free the array itself.
        SafeArrayDestroy(pvarg->parray);
    }
    else 
    {
        switch (vt) 
        {
            case VT_DISPATCH:
				//14/12/2004
				//!!!all comments had to be added
                (/***/(pvarg->pdispVal/*->lpVtbl*/->Release))(/*pvarg->pdispVal*/);
                break;

            case VT_BSTR:
                SysFreeString(pvarg->bstrVal);
                break;

            case VT_I2:
            case VT_BOOL:
            case VT_R8:
            case VT_ERROR:        // to avoid erroring on an error return 
                                // from Excel
                // no work for these types
                break;

            default:
                MessageBox(g_hwndApp, "ReleaseVariant: Unknown type",g_szAppTitle, MB_OK | MB_ICONSTOP);
                break;
        }
    }

    ClearVariant(pvarg);
}