Click here to Skip to main content
15,889,879 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hello,

I have an application what is opening an excel file and I can write some date into cells, but I don`t know how to set some borders to that cells in what I put that data?

A tip be useful :).
Here is a part of the code:
C++
  char szApp[] = "EXCEL";
  char szTopic[] = "C:\\Test.xls";
  char szCmd1[] = "[APP.MINIMIZE()]";
  char szItem1[256] ;  char szDesc1[256] ;
  char szItem2[256] ;  char szDesc2[256] ;
  char szItem3[256] ;  char szData3[256] ;
  char szCmd2[] = "[SELECT(\"R3C1\")][FONT.PROPERTIES(,\"Bold\")][SAVE()][QUIT()]";

  //DDE Initialization

  DWORD idInst=0;
  UINT iReturn;
  iReturn = DdeInitialize(&idInst, (PFNCALLBACK)DdeCallback, APPCLASS_STANDARD | APPCMD_CLIENTONLY, 0 );

   if (iReturn!=DMLERR_NO_ERROR){
      //printf("DDE Initialization Failed: 0x%04xn", iReturn);
      AfxMessageBox("DDE Initialization Failed");
//      Sleep(1500);
      return;}

   //Start DDE Server and wait for it to become idle.

  HINSTANCE hRet = ShellExecute(0, "open", szTopic, "", "", SW_SHOWNORMAL);
  if ((int)hRet < 33)
  {
      //printf("Unable to Start DDE Server: 0x%04xn", hRet);
      AfxMessageBox("Unable to Start DDE Server");
      Sleep(1500); DdeUninitialize(idInst);
      return;
  }
//  Sleep(1000);

  //DDE Connect to Server using given AppName and topic.

  HSZ hszApp, hszTopic;
  HCONV hConv;
  hszApp = DdeCreateStringHandle(idInst, szApp, 0);
  hszTopic = DdeCreateStringHandle(idInst, szTopic, 0);
  hConv = DdeConnect(idInst, hszApp, hszTopic, NULL);
  DdeFreeStringHandle(idInst, hszApp);
  DdeFreeStringHandle(idInst, hszTopic);
  if (hConv == NULL)
  {
      //printf("DDE Connection Failed.n");
      AfxMessageBox("DDE Connection Failed");
      Sleep(1500); DdeUninitialize(idInst);
      return;
  }

  //Execute commands/requests specific to the DDE Server.

  DDEExecute(idInst, hConv, szCmd1);
  DDERequest(idInst, hConv, szItem1, szDesc1);
  DDERequest(idInst, hConv, szItem2, szDesc2);
  /*insert data*/
  int count_items = list.GetItemCount();
  for (int i=0; i<count_items; i++)
      for (int j=0; j<15; j++)
      {
          CString tmp_item;
          tmp_item = list.GetItemText(i,j);
          CString tmp_sz;
          tmp_sz.Format("R%dC%d",i+7,j+1);

          strcpy(szItem3,tmp_sz);
          strcpy(szData3,tmp_item);
          DDEPoke(idInst, hConv, szItem3, szData3);
      }

  DDEExecute(idInst, hConv, szCmd2);

  //DDE Disconnect and Uninitialize.

  DdeDisconnect(hConv);
  DdeUninitialize(idInst);
Posted
Updated 3-Mar-11 20:59pm
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900