Hi Sergei Minozhenko below is the complete code which is based on the requirement but now with this below code when I'm trying with 3 selected records only first selected record is exported into excel and rest two selected records are not exported into excel sheet
using System.IO;
using OfficeOpenXml;
using OfficeOpenXml.Style;
using OfficeOpenXml.Table;
/// <summary>
/// DFF Division To Export Class is used to Export the data into excel sheet
/// </summary>
class DFFDivisionToExport
{
ReqPO reqPO;
DFFReqPOExtension dFFReqPOExtension;
DFFInventTableAttribute dFFInventTableAttribute;
DFFProductClass dFFProductClass;
DFFCultivationMethod dFFCultivationMethod;
DFFFruitVariety dFFFruitVariety;
DFFPackType dFFPackType;
DFFCertification dFFCertification;
InventDim inventDim;
ItemId itemid;
FormDataSource reqPo_ds;
FormRun caller;
DFFSalesQuotationTable_Expantion QuotationExp;
/// <summary>
/// Runs the class with the specified arguments.
/// </summary>
/// <param name = "_args">The specified arguments.</param>
public static void main(Args _args)
{
ReqPO reqPO;
FormDataSource reqPo_ds;
// FormRun caller;
//DFFSalesQuotationTable_Expantion QuotationExp;
MultiSelectionHelper helper = MultiSelectionHelper::construct();
reqPo_ds = formDatautil::getFormDataSource(_args.record());
helper.parmDatasource(reqPo_ds);
reqPo = reqPO_ds.getFirst(1);
if (!reqPO)
{
throw Error("@DFF:DFFRecordIsNotSelected");
}
DFFDivisionToExport dFFDivisionToExport = new DFFDivisionToExport();
while(reqPO)
{
dFFDivisionToExport.dataExport(reqPo);
reqPo = reqPo_ds.getNext();
}
}
/// <summary>
/// To get Division Export data in Excel sheet
/// </summary>
/// <param name = "_reqPO">Buffer for ReqPO</param>
public void dataExport(ReqPO _reqPO)
{
//str ordertype,state,total;
//ReqPO reqPOloc;
//LFAInventPackSpecItem lFAInventPackSpecItem;
LFAManifestVesselTable lFAManifestVesselTable;
SalesQuotationLine salesQuotationLine;
DocuFileSaveResult saveResult = DocuFileSave::promptForSaveLocation("Export","xlsx",null,"ExcelExport");
if (saveResult && saveResult.parmAction() != DocuFileSaveAction::Cancel)
{
saveResult.parmOpenParameters('web=1');
saveResult.parmOpenInNewWindow(false);
//System.IO.Stream workbookStream = new System.IO.MemoryStream();
System.IO.MemoryStream memoryStream = new System.IO.MemoryStream();
//MemoryStream memoryStream = new MemoryStream();
using (var package = new ExcelPackage(memoryStream))
{
var currentRow = 1;
var worksheets = package.get_Workbook().get_Worksheets();
var divisiontoexportworksheet = worksheets.Add("Export");
var cells = divisiontoexportworksheet.get_Cells();
OfficeOpenXml.ExcelRange cell = cells.get_Item(currentRow, 1);
System.String value = "PlannedTransferOrder";
cell.set_Value(value);
cell = null;
value = "PreorderNumber";
cell = cells.get_Item(currentRow, 2);
cell.set_Value(value);
value = "State";
cell = cells.get_Item(currentRow, 3);
cell.set_Value(value);
value = "DischargePort";
cell = cells.get_Item(currentRow, 4);
cell.set_Value(value);
value = "FinalPort";
cell = cells.get_Item(currentRow, 5);
cell.set_Value(value);
value = "Harvestweek";
cell = cells.get_Item(currentRow, 6);
cell.set_Value(value);
value = "Customers";
cell = cells.get_Item(currentRow, 7);
cell.set_Value(value);
value = "Category";
cell = cells.get_Item(currentRow, 8);
cell.set_Value(value);
value = "ContainersOrPalletsRequested";
cell = cells.get_Item(currentRow, 10);
cell.set_Value(value);
value = "Priority";
cell = cells.get_Item(currentRow, 11);
cell.set_Value(value);
value = "VirtualContainerId";
cell = cells.get_Item(currentRow, 12);
cell.set_Value(value);
value = "ContainerType";
cell = cells.get_Item(currentRow, 13);
cell.set_Value(value);
value = "BoxCount";
cell = cells.get_Item(currentRow, 14);
cell.set_Value(value);
value = "TotalBoxCount";
cell = cells.get_Item(currentRow, 15);
cell.set_Value(value);
value = "ProductCode";
cell = cells.get_Item(currentRow, 16);
cell.set_Value(value);
value = "BrandOrMark";
cell = cells.get_Item(currentRow, 17);
cell.set_Value(value);
value = "QualityGrade";
cell = cells.get_Item(currentRow, 18);
cell.set_Value(value);
value = "PackingSpec";//boxSpecification
cell = cells.get_Item(currentRow, 19);
cell.set_Value(value);
value = "PalletType";//Distribution packaging
cell = cells.get_Item(currentRow, 20);
cell.set_Value(value);
value = "BoxesPerPallet";
cell = cells.get_Item(currentRow, 21);
cell.set_Value(value);
value = "PalletsPerContainer";
cell = cells.get_Item(currentRow, 22);
cell.set_Value(value);
value = "Instruction";
cell = cells.get_Item(currentRow, 23);
cell.set_Value(value);
value = "PreferredCountry";
cell = cells.get_Item(currentRow, 24);
cell.set_Value(value);
value = "SourcingCountry";
cell = cells.get_Item(currentRow, 25);
cell.set_Value(value);
select inventDim
where inventDim.inventDimId == _reqPO.CovInventDimId
join dFFReqPOExtension where DFFReqPOExtension.RefId == _reqPO.RefId
join dFFInventTableAttribute where DFFInventTableAttribute.ItemId == _reqPO.ItemId
&& DFFInventTableAttribute.DataAreaId == _reqPO.DataAreaId
join dFFProductClass where DFFProductClass.ProductClassId == DFFInventTableAttribute.ProductClassId
join dFFCultivationMethod where DFFCultivationMethod.CultivationMethodId == DFFInventTableAttribute.CultivationMethodId
join dFFFruitVariety where DFFFruitVariety.FruitVarietyId == DFFInventTableAttribute.FruitVarietyId
join dFFPackType where DFFPackType.PackTypeId == DFFInventTableAttribute.PackTypeId
join dFFCertification where DFFCertification.CertificationId == DFFInventTableAttribute.CertificationId
join lFAManifestVesselTable where LFAManifestVesselTable.VesselId == DFFReqPOExtension.Vessel
join salesQuotationLine where SalesQuotationLine.InventDimId == inventDim.inventDimId;
currentRow ++;
cell = null;
cell = cells.get_Item(currentRow, 1);
cell.set_Value(_reqPO.RefId);
cell = null;
cell = cells.get_Item(currentRow, 2);
cell.set_Value(_reqPO.DFFPrebookingId);
cell = cells.get_Item(currentRow, 3);
cell.set_Value(_reqPO.DFFPTOState);
cell = cells.get_Item(currentRow, 4);
cell.set_Value(inventDim.InventSiteId);
cell = cells.get_Item(currentRow, 5);
cell.set_Value(dFFReqPOExtension.DischargePort);
cell = cells.get_Item(currentRow, 6);
cell.set_Value(dFFReqPOExtension.HarvestWeek);
cell = cells.get_Item(currentRow, 7);
cell.set_Value(dFFReqPOExtension.CustAccount);
cell = cells.get_Item(currentRow, 8);
cell.set_Value(dFFReqPOExtension.ContainerCategory);
cell = cells.get_Item(currentRow, 9);
cell.set_Value(dFFReqPOExtension.Priority);
cell = cells.get_Item(currentRow, 10);
cell.set_Value(dFFReqPOExtension.VirtualContainerId);
cell = cells.get_Item(currentRow, 11);
cell.set_Value(dFFReqPOExtension.ContainerType);
cell = cells.get_Item(currentRow, 12);
cell.set_Value(_reqPO.Qty);
cell = cells.get_Item(currentRow, 13);
cell.set_Value(dFFReqPOExtension.BarCode);
cell = cells.get_Item(currentRow, 14);
cell.set_Value(inventDim.InventDimension6);
cell = cells.get_Item(currentRow, 15);
cell.set_Value(inventDim.InventDimension1);
cell = cells.get_Item(currentRow, 16);//BoxSpecification
cell.set_Value(inventDim.InventDimension8);
cell = cells.get_Item(currentRow, 17);
cell.set_Value(dFFInventTableAttribute.BrandId);
cell = cells.get_Item(currentRow, 18);
cell.set_Value(dFFProductClass.ProductClassId);
cell = cells.get_Item(currentRow, 19);
cell.set_Value(dFFCultivationMethod.CultivationMethodId);
cell = cells.get_Item(currentRow, 20);
cell.set_Value(dFFFruitVariety.FruitVarietyId);
cell = cells.get_Item(currentRow, 21);
cell.set_Value(dFFPackType.PackTypeId);
cell = cells.get_Item(currentRow, 22);
cell.set_Value(dFFCertification.CertificationId);
cell = cells.get_Item(currentRow, 23);//Distribution packaging
cell.set_Value(inventDim.InventDimension7);
cell = cells.get_Item(currentRow, 24);
cell.set_Value(salesQuotationLine.OrigCountryRegionId);
cell = cells.get_Item(currentRow, 25);
cell.set_Value(lFAManifestVesselTable.DFFCarrierCode);
package.Save();
}
memoryStream.Seek(0, System.IO.SeekOrigin::Begin);
DocuFileSave::processSaveResult(memoryStream, saveResult);
}
}
Please help me to solve this
Thanks in Advance :)