Export TVirtualTable to Excel

Export TVirtualTable to Excel

Postby zemmyindrapatih » Sun 07 Jun 2015 22:40

Hi All,

Recently i want to export data using TscExcelExport.
If i'm using TVirtualTable using Design Component, it works perfectly.
Code: Select all
EmpVT.First;
  EmpVT.Filtered := False;
  while not EmpVT.Eof do
  begin
    //Salary Virtual Table
    VirtualTableBankTransferListExport.Append;
    VirtualTableBankTransferListExport.FieldByName('EMPID').AsInteger := EmpVT.FieldByName('EMPID').AsInteger;
    VirtualTableBankTransferListExport.FieldByName('EMPBANKGROUPNO').AsInteger := EmpVT.FieldByName('BANKGROUPNO').AsInteger;
    VirtualTableBankTransferListExport.FieldByName('EMPTRANSBANKACCNAME').AsString := EmpVT.FieldByName('EMPBANKACCNAME').AsString;
    VirtualTableBankTransferListExport.FieldByName('EMPTRANSBANKACCNO').AsString := EmpVT.FieldByName('EMPBANKACCNO').AsString;
    VirtualTableBankTransferListExport.FieldByName('BANKACCNO').AsString := EmpVT.FieldByName('BANKACCNO').AsString;
    VirtualTableBankTransferListExport.FieldByName('PERIOD').AsString := PaySlipPeriod;
    VirtualTableBankTransferListExport.FieldByName('BANKNAME').AsString := EmpVT.FieldByName('BANKNAME').AsString;
        VirtualTableBankTransferList.FieldByName('TRANSFERAMOUNT').AsInteger := 0;//Format('%s%s%.*d', [EmpVT.FieldByName('REGIONCODE').AsString,EmpVT.FieldByName('EMPCODE').AsString,4,EmpVT.FieldByName('EMPCODE').AsInteger]); //EmpVT.FieldByName('EMPCODE').AsString;
    VirtualTableBankTransferListExport.FieldByName('BANKID').AsString := EmpVT.FieldByName('BANKID').AsString;
    VirtualTableBankTransferListExport.FieldByName('TBANKNAME').AsString := EmpVT.FieldByName('TBANKNAME').AsString;
    VirtualTableBankTransferListExport.FieldByName('BANKLOCATION').AsString := EmpVT.FieldByName('BANKLOCATION').AsString;
    VirtualTableBankTransferListExport.Post;
    EmpVT.Next;
  end;
  scExcelExport1.WorksheetName := 'Bank Transfer List';
  scExcelExport1.Dataset:=VirtualTableBankTransferListExport;
  scExcelExport1.ExportDataset;
  scExcelExport1.Disconnect;


But if i declare TVirtualTable programmatically, it won't show the data. Are there the code i missed ?
Code: Select all
var
  VirtualTableExportAllEmployeeDetails: TVirtualTable;
begin
  ModuleCoreSalaryComputation.FetchDataToMemory();

  VirtualTableExportAllEmployeeDetails := TVirtualTable.Create(self);
  VirtualTableExportAllEmployeeDetails.Clear;
  VirtualTableExportAllEmployeeDetails.Active:= true;

  VirtualTableExportAllEmployeeDetails.FieldDefs.Add('fullname', Data.DB.ftString, 0, False);
  VirtualTableExportAllEmployeeDetails.Options := [voPersistentData, voStored, voSkipUnSupportedFieldTypes];
//  VirtualTableExportAllEmployeeDetails.DisableControls;
VirtualTableExportAllEmployeeDetails.Open;
  VirtualTableExportAllEmployeeDetails.Append;
  VirtualTableExportAllEmployeeDetails.FieldByName('fullname').AsString := 'zemmy';
  VirtualTableExportAllEmployeeDetails.Post;
  VirtualTableExportAllEmployeeDetails.Append;
  VirtualTableExportAllEmployeeDetails.FieldByName('fullname').AsString := 'arfa';
  VirtualTableExportAllEmployeeDetails.Post;
  showmessage(inttostr(VirtualTableExportAllEmployeeDetails.RecordCount));
//  VirtualTableExportAllEmployeeDetails.EnableControls;
  scExcelExport1.WorksheetName := 'asdf';
  scExcelExport1.Dataset:=VirtualTableExportAllEmployeeDetails;
  scExcelExport1.ExportDataset;
  scExcelExport1.Disconnect;
end;

Image
zemmyindrapatih
 
Posts: 3
Joined: Thu 11 Dec 2014 22:37
Location: Indonesia

Re: Export TVirtualTable to Excel

Postby zemmyindrapatih » Mon 08 Jun 2015 04:46

Help me please..

Or can someone show me how to create TVirtualTable (Init, Create Fields, and Filling Data) using code
only without droping component in form.

Thank you very much.
zemmyindrapatih
 
Posts: 3
Joined: Thu 11 Dec 2014 22:37
Location: Indonesia

Re: Export TVirtualTable to Excel

Postby AlexP » Tue 09 Jun 2015 11:32

Hello,


Below is the code for generating VirtualTable, fields, filling in the table and import to Excel using TscExcelExport.

Code: Select all
var
  VT: TVirtualTable;
  i: integer;
begin
  VT := TVirtualTable.Create(nil);
  try
    VT.AddField('test', ftString, 20);
    VT.Open;
    for i := 0 to 10 do begin
      VT.Append;
      VT.Fields[0].AsString :=  'test_' + IntToStr(i);
      VT.Post;
    end;
    scExcelExport1.WorksheetName := 'Bank Transfer List';
    scExcelExport1.Dataset := VT;
    scExcelExport1.ExportDataset;
    scExcelExport1.Disconnect;
  finally
    VT.Free;
  end;
end;
AlexP
Devart Team
 
Posts: 5528
Joined: Tue 10 Aug 2010 11:35


Return to VirtualDAC