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)

Autofit with Excel Buffer and sending as attachment via Mail

(0) ShareShare
ReportReport
Posted on by

Hi,

I have a problem with Excel Buffer,I'm working on Nav 2015 and I have to create a report that export data from Purchase Line to Excel. After creating the excel have this code on PostDataItem :

TempExcelBuffer.CreateBook(Title);
TempExcelBuffer.WriteSheet(Title,COMPANYNAME,USERID);
TempExcelBuffer.CloseBook;

.... 

Then I send the excel directly from the server via Mail to the target Recipient. The problem is that in the new Excel Buffer, the excel is generated using only XlWrkBkWriter,  XlWrkShtWriter and the XlWrkBk or XlWrkSht  are not initialized. I don't know how to initialized those variable to make the autofit of column, without using TempExcelBuffer.OpenExcel that download the file to client (I need to have the file modified server side).

Does anyone have any idea? 

Thank You

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Andrey Baludin Profile Picture
    3,941 on at

    Hi! In 2016 version there is an AutoFit function directly in Excel buffer Table.

    Works like ExcelBuffer.AutoFit('A:Z');

    Please, check it in 2015.

  • Community Member Profile Picture
    on at

    Thank you, there is an Autofit function even in 2015, XlHelper.AutoFitRangeColumns(XlWrkBk,ActiveSheetName,RangeName);

    But I have to pass XlWrkBk that is not initialized, I don't know how...

  • Suggested answer
    Andrey Baludin Profile Picture
    3,941 on at

    Try next:

    TempExcelBuffer.CreateBook(Title);

    TempExcelBuffer.WriteSheet(Title,COMPANYNAME,USERID);

    TempExcelBuffer.PostOpenExcel;

    TempExcelBuffer.CloseBook;

  • Community Member Profile Picture
    on at

    It pops this error with this code:

    An instance of a DOTNET variable has not been created. Attempt to call microsoft.office.interop.Excel.ApplicationClass.ActiveWorkbook in table excel buffer: PostOpenExcel

  • Suggested answer
    Andrey Baludin Profile Picture
    3,941 on at

    I've made small experiment and autofit works in it without additional initialization:

    xcel-result.JPG

    xcel-result.JPG

  • Suggested answer
    4BzSoftware Profile Picture
    6,073 on at

    Hi Denis R.,

    If you need to modify the file at Server Side, you have to install Excel for the Server.

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