Skip to main content

Navision Export To Excel with Merge Cell Function

Hi all,

While developing reports in classic client with Export to Excel Enabled, client wants to have Header cell merged. This is mostly faced issue.

Resolution -
What i did is that i added a function in Excel Buffer table which merge specified cell.

Function -

PROCEDURE MergeRange(FromRow : Integer;FromCol : Integer;ToRow : Integer;ToCol : Integer);
  FromRec : Record 370;
  ToRec : Record 370;
  FromRec.VALIDATE("Row No.",FromRow);
  FromRec.VALIDATE("Column No.",FromCol);
  ToRec.VALIDATE("Row No.",ToRow);
  ToRec.VALIDATE("Column No.",ToCol);
  XlWrkSht.Range(FromRec.xlColID + FromRec.xlRowID + ':' + ToRec.xlColID + ToRec.xlRowID).Merge;

Function Definition -

1) Function contain 4 Parameters - From Row No, From Column No, To Row No, To Column No., which specify the Cells that need to merge.

2) After you created the sheet and before you save it away or give the user control call that function.

As per Promod Request here is a sample example of how to use the function-

* Its just a sample code where i hardcoded the column and Row Numbers, you can change it to dynamic as per your requirment.

This is what i was getting output earlier using this function -

Now what i wanted is to merge the cells so Blog name comes in one cell. Below is the code that i have written in my report.

And here is the output that i get after that -

@pramod patil i hope this is what you wanted. Let me know if you have any issues.

Thanks & Regards,
Saurav Dhyani


  1. Very Help Full Dude......!
    Shravan Kumar
    Nav Developer

  2. Plz send how to use this code. I can't use it I face error at run time when I call this code!

    1. Hi Pramod -

      I have updated the Blog entry. Let me know if you have any issues.

  3. Thanks, I was use your code, its work very nice!
    But, I want to assign FromRow,FromCol,ToRow,ToCol dynamically. So how I do this?

    1. Hi Pramod,

      Can you explain me the exact issue.

      If possible drop me the object at, i will have a look.

      Also please explain the whole issue in mail.


    2. Thanks friend. Actually I want to add Message after completion of records.SO how we find row number dynamically? Friend,also will you tell me how we can add font to any record like(e.g Times new roman, then size) things when we export to excel? Then also how we add box, colour, etc to fields?

    3. Hi Pramod,

      For Font color, size and background color refer to post -

  4. Thanks Saurav an pramod, u helped me understand Excel cell merging!!!....

    1. Hi Sachin,

      You are always welcome and it great to hear that my posts are helping someone.


    2. This comment has been removed by a blog administrator.

  5. How to generate random strings in navision??

    1. Dear Sachin,

      Can you explain what you want to do?

  6. hi sir ..
    very helpfull for me..

    1. Hi vimal,

      Great to Hear that..

      Saurav Dhyani

  7. halo sir, for XlWrkSht where is the definition of this variable

    1. @Sharing iimu -
      Which version you are trying this. This is for Classic Dynamics NAV Classic Version and definition of that variable is in the table 370.
      The function need to be added in table 370 where that variable is already available.


Post a Comment

Popular posts from this blog

Send Mail with Attachment From Navision.

Hi all, We have seen how to save a report into PDF and how to send mail to a customer. Let's link these two post in one i.e. Mailing statement to a customer into PDF Format. This article is part of the Series. Please Refer  Table of Content here . If you have the old objects set let me brief you what I will be changing - 

Microsoft Dynamics NAV 2016 - How to Configure Phone Client.

Hi All, In this article we will discuss how we can connect Microsoft Dynamics NAV 2016 with New Client Launched i.e. Phone Client. This Article Contain Steps for a Android Phone as I have Only Android Phone. I am doing it having all tiers on my windows 8 machine, steps remain same for multiple servers but issues might be different. What we Need (Other what we discuss in this article) -  The Service Tier should be on Public IP . Some of the Data-card does not Provide you Public IP. check it for sure.

Download Microsoft Dynamics Business Central on Premises 2020 Wave 2 Release.

 Hi Readers, As Expected Microsoft have released #msdyn365bc 2020 wave 2 is available.  This article provides details of the new release. The 2020 release wave 2 for Business Central delivers a wealth of new features. Read What's new in 2020 Release Wave 2 here .  Dynamics NAV Customers upgrading to Business Central on Prem will be able to run business central on premises, move to cloud or choose a hybrid approach.