Pages

Thursday, 13 November 2014

Navision 2009 : Excel create in Report using Excel buffer and Automation

There are many ways to create a Excel from Report in the Microsoft Dynamics NAV 2009.
1. Using Excel Buffer table
2. Using Automation variable

Using Automation variable is faster way to create Excel.

Variable in Report
Name    DataType    Subtype
Excel    Automation    'Microsoft Excel 12.0 Object Library'.Application   
Book    Automation    'Microsoft Excel 12.0 Object Library'.Workbook   
Range    Automation    'Microsoft Excel 12.0 Object Library'.Range   
Sheet    Automation    'Microsoft Excel 12.0 Object Library'.Worksheet
j           Text                 30

OnPreReport
  CREATE(Excel,TRUE,TRUE);
  Excel.Visible(TRUE);
  Book:=Excel.Workbooks.Add();
  Sheet:=Excel.ActiveSheet;
  Sheet.Name := 'Sheet Name';




OnPreSection()
  Sheet.Range('A'+j).Value :=  'Inward Date';
  Sheet.Range('B'+j).Value :=  'Item No.';
  Sheet.Range('C'+j).Value :=  'Description';
  j := INCSTR(j);

Merge Column in Excel
Sheet.Range('A'+'1' + ':' + 'D'+'1').Merge;
Sheet.Range('A'+'1').Value :=  ' Excel Report';

Fill Colour in Excel Column
Sheet.Range('A'+'1').Interior.Color := 880088;

Font Bold
  Sheet.Range('A'+'1').Font.Bold := TRUE;

Font Italic
  Sheet.Range('A'+'1').Font.Italic := TRUE;

Font Size
  Sheet.Range('A'+'1').Font.Size := 12;

Border Cell
  Sheet.Range('A'+'1').Borders.LineStyle := 0;

 SavaAs Excel
  Sheet.SaveAs('abc123.xlsx');

Password Protect Sheet
Sheet.Protect('Test123');


2 comments:

  1. how i can format the Cell,i want to display '03' instead of '3'.i have written like this.

    XLSHEET.Range('H'+J).Value := '03';
    but 0 is getting cropped.

    ReplyDelete