web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics NAV (Archived)

Creating new Excel and adding required no. of sheets using .Net variables

(1) ShareShare
ReportReport
Posted on by

I'm facing problem in adding additional sheets to an excel .

while executing the below code I'm able to create new excel sheet,

 

Prob1.png

After creating the excel file I'm not able add additional sheets to that excel.

It is showing error like

prob.png

Please suggest any possible ways of adding sheets.

Thanks in Advance.

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Alexander Ermakov Profile Picture
    28,096 on at

    There is an option to use Excel Buffer:

    saurav-nav.blogspot.ru/.../nav-2013-r2-multiple-sheets-in-excel.html

    and without Excel Buffer:

    aniket-dynamicsnav.blogspot.ru/.../export-to-excel-with-multiple-sheet.html

  • Community Member Profile Picture
    on at

    Thank you for your replay.

    I have done this already using Excel buffer.

    And I have already seen the in 2nd link also. In that they are using Automation variables .

    But I want it by using only .Net variables.

    Please provide any  other possible ways of solution.

  • Verified answer
    Binesh Profile Picture
    7,885 on at

    Hello Sreekanth, 

    See the bellow screenshot, here i developed the solution for dynamic sheet adding in excel workbook.

    Loc-Var.png

    For variables see bellow screenshot.

    Loc-Var.png

  • Verified answer
    Jatin Patel Profile Picture
    2,641 on at

    Hi Sreekanth,

    You can create below function in Excel Buffer table and use it to add new sheet.

    AddNewSheet(SheetName : Text[250])

    IF SheetName = '' THEN

     ERROR(Text002);

    IF ISNULL(XlWrkBkWriter) THEN BEGIN

     CreateBook(SheetName);

     ActiveSheetName := SheetName; //first sheet activated

    END ELSE BEGIN

     WHILE XlWrkBkWriter.HasWorksheet(SheetName) DO BEGIN

       IF NOT FirstIncrement THEN BEGIN

         SheetName := SheetName + '-01';

         FirstIncrement := TRUE;

       END ELSE BEGIN

         SheetName := INCSTR(SheetName);

       END;

     END;

     XlWrkShtWriter := XlWrkBkWriter.AddWorksheet(SheetName);

     FirstIncrement := FALSE;

     ActiveSheetName := SheetName; //last sheet activated

    END;

    WriteSheet('',COMPANYNAME,USERID);

    DELETEALL;

    ClearNewRow;

  • Verified answer
    keoma Profile Picture
    32,729 on at

    better you use the .net classes which are used in table ExcelBuffer.

    xls2.PNG

    xls2.PNG

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics NAV (Archived)

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans