Wednesday, May 21, 2014

Tree node to Excel file:

Tree node to Excel file:

static void CreateExcelTreeNode(Args _args)


{



SysExcelApplication xlsApplication;

SysExcelWorkBooks xlsWorkBookCollection;

SysExcelWorkBook xlsWorkBook;

SysExcelWorkSheets xlsWorkSheetCollection;

SysExcelWorkSheet xlsWorkSheet;

SysExcelRange xlsRange;

AsciiIO tmpfile;

Filename tmpfilename;

FileIOPermission permission;

TreeNode treeNode;

TreeNode treeNodeTables;

#File

#AOT

int row = 1;

str fileName;

;



treeNodeTables = TreeNode::findNode(#SecurityKeysPath);



// Name of the Excel document.



fileName = "C:\\test.xsl";



// Excel open and initialize.



xlsApplication = SysExcelApplication::construct();

xlsApplication.visible(true); //Generate new Excel worksheet.

xlsWorkBookCollection = xlsApplication.workbooks();

xlsWorkBook = xlsWorkBookCollection.add();

xlsWorkSheetCollection = xlsWorkBook.worksheets();

xlsWorkSheet = xlsWorkSheetCollection.itemFromNum(1);

// Write headlines cells in the worksheet.

xlsWorkSheet.cells().item(row,1).value('Name'); xlsWorkSheet.cells().item(row,2).value('ID');

row++;

// first table

treeNode = treeNodeTables.AOTfirstChild();

// Excel worksheet with fill data (Excel fill-cells).

while (treeNode != null)

{

xlsWorkSheet.cells().item(row,1).value(treeNode.AOTname()); xlsWorkSheet.cells().item(row,2).value(treeNode.applObjectId());

row++; // next table

treeNode = treeNode.AOTnextSibling();

}

// Check whether the document already exists.

if(WinApi::fileExists(fileName))

{

WinApi::deleteFile(fileName);

}

// Excel document store.

xlsWorkbook.saveAs(fileName);

//Close Excel.

xlsApplication.quit(); xlsApplication.finalize();

}

No comments:

Post a Comment

Convert Call stack to readable format in D365FO X++

//Input --container _xppCallStack = xSession::xppCallStack();  Public static str POL_formatXppCallStack(container _xppCallStack, int _skipFr...