I got a requirement like I have to import vendors in to my custom table. I write the below code to cmp the reqirement.
using System.IO; using OfficeOpenXml; using OfficeOpenXml.ExcelPackage; using OfficeOpenXml.ExcelRange; class ImportVendorsForAutoSettlement { /// <summary> /// excelimport used to import the invoice numbers. /// </summary> public void excelImport() { System.IO.Stream stream; DialogGroup dlgUploadGroup; FileUploadBuild fileUploadBuild; FormBuildControl formBuildControl; AutoSettlementVendorList autoSettlementVendorList; VendAccount vendAccount; Dialog dialog = new Dialog("ImportDataFromExcel"); ; dlgUploadGroup = dialog.addGroup("@SYS54759"); formBuildControl = dialog.formBuildDesign().control(dlgUploadGroup.name()); fileUploadBuild = formBuildControl.addControlEx(classstr(FileUpload), "Upload"); fileUploadBuild.style(FileUploadStyle::MinimalWithFilename); fileUploadBuild.fileTypesAccepted('.xlsx'); if (dialog.run() && dialog.closedOk()) { FileUpload fileUploadControl = dialog.formRun().control(dialog.formRun().controlId("Upload")); FileUploadTemporaryStorageResult fileUploadResult = fileUploadControl.getFileUploadResult(); if (fileUploadResult != null && fileUploadResult.getUploadStatus()) { stream = fileUploadResult.openResult(); using (ExcelPackage Package = new ExcelPackage(stream)) { int rowCount, i; Package.Load(stream); ExcelWorksheet worksheet = package.get_Workbook().get_Worksheets().get_Item(1); OfficeOpenXml.ExcelRange range = worksheet.Cells; rowCount = worksheet.Dimension.End.Row - worksheet.Dimension.Start.Row + 1; try { for (i = 2; i<= rowCount; i++) { ttsbegin; vendAccount = range.get_Item(i, 1).value; //supplierID = range.get_Item(i, 2).value; // transType = range.get_Item(i, 3).value; autoSettlementVendorList = AutoSettlementVendorList::find(vendAccount, true); if (!autoSettlementVendorList && vendAccount) { autoSettlementVendorList.clear(); autoSettlementVendorList.VendAccount = vendAccount; autoSettlementVendorList.insert(); } else if (autoSettlementVendorList && autoSettlementVendorList.IsProcess) { autoSettlementVendorList.IsProcess = false; autoSettlementVendorList.update(); } ttscommit; } } catch(Exception::Error) { info("Error"); } } Info("Sucessed"); } else { error("Error"); } } } }
Keep Daxing!!
No comments:
Post a Comment