CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Jan 2008
    Location
    India
    Posts
    780

    How can Write and Display Date and currency in excel?

    Hi all,

    i m using excel automation to write excel but is write date or any amount with currency symbol its not displayed properly in excel sheet.

    please help me how can i display it.

    thank in advance.
    IN A DAY, WHEN YOU DON'T COME ACROSS ANY PROBLEMS - YOU CAN BE SURE THAT YOU ARE TRAVELLING IN A WRONG PATH

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: How can Write and Display Date and currency in excel?

    And how are you doing it now?
    Victor Nijegorodov

  3. #3
    Join Date
    Jan 2008
    Location
    India
    Posts
    780

    Re: How can Write and Display Date and currency in excel?

    Code:
    CoInitialize(NULL);
    	{
    		Excel::_ApplicationPtr XL;
    		HRESULT hr;
    		try
    		{
    			XL.CreateInstance(L"Excel.Application");
    
    			// create workbook & worksheet	
    			// identify range to which array will be assigned
    
    			_variant_t var((long)DISP_E_PARAMNOTFOUND,VT_ERROR);
    
    			XL->Workbooks->Add(Excel::xlWorksheet);
    			Excel::_WorksheetPtr pSheet = XL->ActiveSheet;
    
    			Excel::RangePtr pRange = pSheet->Cells;
    
    			Excel::RangePtr pBeginRange = pRange->Item[1][1];
    			Excel::RangePtr pEndRange = pRange->Item[1][1];
    			Excel::RangePtr pTotalRange = pSheet->Range[(Excel::Range*)pBeginRange][(Excel::Range*)pEndRange];	
    
    			// create some BSTRs	
    			wchar_t wsz1[] = L"C";	
    			wchar_t wsz2[] = L"D";	
    			BSTR bstr1;	
    			bstr1 = SysAllocString(wsz1);
    
    			BSTR bstr2;	
    			bstr2 = SysAllocString(wsz2);
    
    			// create safearray		
    			SAFEARRAYBOUND rgsabound[2] = { 0 };
    			rgsabound[0].cElements = 1; // num rows
    			rgsabound[0].lLbound = 0; // lower bound	
    			rgsabound[1].cElements = 1; // num cols	
    			rgsabound[1].lLbound = 0; // lower bound		
    
    			VARIANT arr;	
    			arr.vt = VT_ARRAY | VT_BSTR;
    			arr.parray = SafeArrayCreate(VT_BSTR,2,rgsabound);
    			// identify index we want to change	
    			long index[2];
    			// modify first element <0,0>	
    			index[0] = 0;	
    			index[1] = 0;	
    			hr = SafeArrayPutElement(arr.parray,index,bstr1);
    
    			// assign safearray to range	
    			pTotalRange->PutValue2(&arr);
    			// cleanup	
    			VariantClear(&arr);	
    			SysFreeString(bstr1);
    			SysFreeString(bstr2);
    
    			XL->Visible = true;
    
    		}
    		catch(_com_error &error)
    		{
    			cout << "COM error " << endl;
    		}
    	}
    	CoUninitialize();
    This happens when i run application on Office 2010 Beta version.while i run application on office 2007 its working fine.

    and also tell me how to write date or any amount with currency symbol in excel because by this metod its not displayed properly in excel sheet.

    thanks.
    IN A DAY, WHEN YOU DON'T COME ACROSS ANY PROBLEMS - YOU CAN BE SURE THAT YOU ARE TRAVELLING IN A WRONG PATH

  4. #4
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: How can Write and Display Date and currency in excel?

    This happens when i run application on Office 2010 Beta version.while i run application on office 2007 its working fine.[/QUOTE]Then check out how, where and why "Office 2010 Beta" differs from "office 2007".
    Or, at least, wait for the finale release of Office 2010.
    Victor Nijegorodov

  5. #5
    Join Date
    Jan 2008
    Location
    India
    Posts
    780

    Re: How can Write and Display Date and currency in excel?

    sir there is no other option for this?
    IN A DAY, WHEN YOU DON'T COME ACROSS ANY PROBLEMS - YOU CAN BE SURE THAT YOU ARE TRAVELLING IN A WRONG PATH

  6. #6
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: How can Write and Display Date and currency in excel?

    Quote Originally Posted by vjshankwar View Post
    sir there is no other option for this?
    "other option for" what? For not read the documentation?
    Victor Nijegorodov

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured