How to send data to Excel

static void Send_toExcel(Args _args) {

   SysExcelApplication         ExcelApplication;
   SysExcelWorkBooks           ExcelWorkBooks;
   SysExcelWorkBook            ExcelWorkBook;
   SysExcelWorkSheets          ExcelWorkSheets;
   SysExcelWorkSheet           ExcelWorkSheet;
   SysExcelRange               ExcelRange;
   CustTable                   ct;
   int                         row;
   ;
   ExcelApplication = SysExcelApplication::construct();
   ExcelApplication.visible(true);
   ExcelWorkBooks = ExcelApplication.workbooks();
   ExcelWorkBook = ExcelWorkBooks.add();
   ExcelWorkSheets = ExcelWorkBook.worksheets();
   ExcelWorkSheet = ExcelWorkSheets.itemFromNum(1);
   while select * from ct
   {
       row++;
       ExcelWorkSheet.cells().item(row,1).value(ct.AccountNum);
       ExcelWorkSheet.cells().item(row,2).value(ct.Name);
   }

}

=================================================================

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();
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: