Merging cells in Excel using Excel Buffer

ArchyArchy Member Posts: 70
Hi all!

I have made a report, using Excel Buffer. But I need to merge cells in report header row. It seems, that is impossible to merge cells using excel buffer. :cry: I found in previous topics one way to do it:

xlSheet.Range('A1:C1').Merge;

The only way I can imagine is to complitely modify my report and do not use Excel Buffer table. But it is so complicated! :cry: May be someone could advise some other way? :oops:

Comments

  • damirdamir Member Posts: 28
    You should add new function to Excel Buffer table and call it after CreateSheet. This function will contain xlRange.Merge command
  • ArchyArchy Member Posts: 70
    I have added such a function - it works! \:D/
    But there is one problem - it merges cells, but do not center content in this new big cell. :-k Any ideas?
  • kinekine Member Posts: 12,562
    You need to set correct property for that cell... try to record the macro and look into it.
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • keshavopkkeshavopk Member Posts: 3
    Hello,

    Can anyone help on merging of Cell, I am trying to call a new function which has a command xlRange.Merge('A1:A2') (calling this after function CreateSheet
    for Export to excel). but I am getting following Automation error

    Microsoft Dynamics NAV
    This message is for C/AL programmers:

    This Automation variable has not been instantiated.
    You can instantiate it by either creating or assigning it.

    OK

    and if I try to Initialize it then it show some other error
    Microsoft Dynamics NAV
    This message is for C/AL programmers:

    An exception was raised in method Merge. The OLE control or Automation server has returned error (HRESULT) -2147352567.
    The component did not provide the exception description.

    OK

    is anyone have correct syntex of it then pls let me know. Your co opration shall be appriciated highly.

    Thanks
  • HanenHanen Member Posts: 281
    I'm using this code and it works perfectly :
    XlBook := XlApp.Workbooks.Open(FileName);
    
    //Transfering Data to Microsoft Excel:
    XlSheet:= XlApp.ActiveSheet;
    XlSheet.Range('A1:A2').Cells.Merge;
    XlSheet.Range('A1').HorizontalAlignment :=  -4108;
    
    

    I hope it can helps!!!
    Regards

    Hanen TALBI
  • johannajohanna Member Posts: 369
    Hanen,

    Thank you so much! Your code works perfectly :)
    Best regards,

    Johanna
  • sushilhcsushilhc Member Posts: 1
    Dear Hanen,

    Please help. How to set the variables. Please define in detail.

    Thanks & Regards,
    Sushil Chaudhari
  • RockWithNAVRockWithNAV Member Posts: 1,139
    It's possible,I remember I did long for one of the Project.

    The caption part they wanted to Merge. I guess I used some Automation Variables.
Sign In or Register to comment.