PutBulk(Packet: IDtBulkPacket): Boolean;
Packet. Packet with data for export.
The PutBulk method exports the specified data packet to data consumer.
Executing the example requires that the root of the C disk contains the Data.xls file.
Sub Main;
Var
ExcelConsumer: IDtExcelConsumer;
Fields: IDtFieldDefinitions;
Field: IDtFieldDefinition;
Pack: IDtBulkPacket;
v: Array[3, 4] =
[["Buckwheat", "Milk", "Sugar", "Bread"],
[10, 20, 30, 40],
[313.12, 301.53, 254.13, 404.11]];
v1: Array[4, 3] =
[["Cheese", "Juice", "Tea", "Coffee" 10, ],
[10, 20, 30.45, 40],
[113.12, 101.53, 154.13, "A"]];
Begin
// Create a data consumer
ExcelConsumer := New DtExcelConsumer.Create;
ExcelConsumer.File := "D:\Data.xls";
ExcelConsumer.HasHeader := True;
ExcelConsumer.DriverVersion := "Excel 8.0";
ExcelConsumer.Table := "Sheet1";
// Create fields
Fields := ExcelConsumer.Fields;
Field := Fields.Add;
Field.DataType := DbDataType.String;
Field.Name := "Name";
Field := Fields.Add;
Field.DataType := DbDataType.Integer;
Field.Name := "ID";
Field := Fields.Add;
Field.DataType := DbDataType.Float;
Field.Name := "Value";
ExcelConsumer.Open;
// Load data packets to data consumer
Pack := New DtBulkPacket.Create;
Pack.FailPolicy := DatasetFailPolicy.Rollback;
// First packet
Pack.Data := v;
ExcelConsumer.PutBulk(Pack);
If Not Pack.Successful Then
Debug.WriteLine("Error on packet export");
Debug.WriteLine("Records not exported: " + Pack.FailedRows.ToString);
Else
Debug.WriteLine("Packet is exported successfully");
End If;
// Second packet
Pack.Data := v1;
ExcelConsumer.PutBulk(Pack);
If Not Pack.Successful Then
Debug.WriteLine("Error on packet export");
Debug.WriteLine("Records not exported: " + Pack.FailedRows.ToString);
Else
Debug.WriteLine("Packet is exported successfully");
End If;
ExcelConsumer.Close;
End Sub Main;
After executing the example a new data consumer that exports data in Microsoft Excel file is created. Values of two arrays are in turns written in file. If any error appears during rows export changes are undone. Information about export results is displayed in the development environment console.
See also: