Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics NAV forum
Answered

Updating existing Excel Sheet

Posted on by 70

Using NAV 2016 . I have created a processing report that pulls and calculate data based on Date filter from multiple tables and companies in NAV. The report sends the results to Excel using the Excel Buffer table. The user will build charts in the Worksheet created then he or she will periodically run the processing report to update the existing data in that Worksheet without having to recreate the charts every time. I need a way to Clear the data in the worksheet before sending the updating data. I see a code in the Excel Buffer table:

 

XlWrkSht.Range('A3:P40').ClearContents;

I'm not sure how to use the DotNet variables like XlWrkBk  and XlWrkSht inorder to use the above  line of code .   

Can you please help?

  • Suggested answer
    Ebitas Profile Picture
    Ebitas 70 on at
    RE: Updating existing Excel Sheet

    Thank yo for your help. The link you suggested helped me a lot. I used the following code and it worked I had to add the CLEARALL at the end

    XlApp := XlApp.ApplicationClass;

    XlWrkBk := XlHelper.CallOpen(XlApp,FileName);

    XlWrkSht := XlWrkBk.Worksheets.Item('Tech');

    xlRange := XlWrkSht.Range('A3','P40');

    xlRange.Activate;

    xlRange.Select;

    xlRange.ClearContents;

    XlWrkBk.Save;

    XlWrkBk.Close(TRUE,FileName,TRUE);

    XlHelper.CallQuit(XlApp);

    XlApp.Quit;

    CLEARALL;

    CLEAR(XlHelper);

    CLEAR(XlApp);

    CLEAR(XlWrkBk);

    CLEAR(XlWrkSht);

    CLEAR(xlRange);

  • Verified answer
    I Gusti Made Ari Profile Picture
    I Gusti Made Ari 3,590 on at
    RE: Updating existing Excel Sheet

    Please check below link for solution with same case :

    community.dynamics.com/.../153134

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Anton Venter – Community Spotlight

Kudos to our October Community Star of the month!

Announcing Our 2024 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Dynamics 365 Community Newsletter - September 2024

Check out the latest community news

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,556 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 228,625 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans