...feel the spirit of Microsoft Dynamics AX RSS 2.0
 Thursday, September 14, 2006

Oft wird ein Export von Dynamics AX Daten in ein Exceldokument benötigt. Z.B. für einfache Auswertungen oder für Datenimporte in andere Systeme.

Hier ein kurzes Beispiel, wie man aus Dynamics AX ein neues Exceldokument per Code erstellen kann.

static void CreateExcelDokument(Args _args)
{
   SysExcelApplication xlsApplication;
   SysExcelWorkBooks xlsWorkBookCollection;
   SysExcelWorkBook xlsWorkBook;
   SysExcelWorkSheets xlsWorkSheetCollection;
   SysExcelWorkSheet xlsWorkSheet;
   SysExcelRange xlsRange;
   CustTable custTable;
   int row = 1;
   str fileName;
   ;
   // Name des Exceldokuments.
   fileName = "C:\\test.xsl";

   // Excel initalisieren und öffnen.
   xlsApplication = SysExcelApplication::construct();
   xlsApplication.visible(true);

   // Neues Excel Worksheet erzeugen.
   xlsWorkBookCollection = xlsApplication.workbooks();
   xlsWorkBook = xlsWorkBookCollection.add();
   xlsWorkSheetCollection = xlsWorkBook.worksheets();
   xlsWorkSheet = xlsWorkSheetCollection.itemFromNum(1);

   // Zellenüberschriften in das Worksheet schreiben.
   xlsWorkSheet.cells().item(row,1).value('Account Num');
   xlsWorkSheet.cells().item(row,2).value('Name');

   row++;

   // Excel Worksheet mit Daten füllen (Excel-Zellen füllen).
   while select custTable
   {
      xlsWorkSheet.cells().item(row,1).value(custTable.AccountNum);
      xlsWorkSheet.cells().item(row,2).value(custTable.Name);
      row++;
   }

   // Prüfen ob das Dokument schon existiert.
   if(WinApi::fileExists(fileName))
   {
      WinApi::deleteFile(fileName);
   }

   // Excel Dokument speichern.
   xlsWorkbook.saveAs(fileName);

   // Excel schließen.
   xlsApplication.quit();
   xlsApplication.finalize();
}


 

Thursday, September 14, 2006 9:54:10 AM (Mitteleuropäische Zeit, UTC+01:00)  Axel Kühn  #    Comments [1] - Trackback
 | 

Tuesday, April 29, 2008 1:34:06 PM (Mitteleuropäische Zeit, UTC+01:00)
Danke, der Eintrag hat mir weitergeholfen.
Hilfreiche Tools in Richtung Excel sind auch
http://www.print2excel.com/ und http://www.atlasxl.de

Auch die Axaptapedia hilft bei diesem Thema.
Comments are closed.


Translate
Über/Kontakt

     







© Copyright 2012 Axel Kühn
Sign In
Subscribe this blog
Blogroll
 Arijit Basu
 Axapta Blog
Blog around Microsoft Business Solutions Axapta by Helmut Wimmer
 BlaBlubBlog
Der Blog von Kai Gloth
 Dave Bowles
 Dick Wenning
Ax(apta) start pages
 Fred Shen
 Harish Mohanbabu
 jinx´s AX Blog
Everything about Microsoft Dynamcis AX
 Lars Keller
All about .NET, VSTS, VSTO and more
 Max Belugin
 TaReMoTi Blog
Der Blog von Karsten Döring
Archiv
<February 2012>
SunMonTueWedThuFriSat
2930311234
567891011
12131415161718
19202122232425
26272829123
45678910
Statistik
Gesamte Posts: 137
Dieses Jahr: 0
Dieser Monat: 0
Diese Woche: 0
Kommentare: 49





All Content © 2012, Axel Kühn
DasBlog theme 'Business' created by Christoph De Baene (delarou)