D365Excel Import

using OfficeOpenXml;
using OfficeOpenXml.ExcelPackage;
using OfficeOpenXml.ExcelRange;
class ImportTEST extends RunBaseBatch
{
Dialog dialog;
str fileUrl;
FileName FileName;
Counter importedLines;

public boolean canGoBatch()
{
return false;
}

/// <summary>
///
/// </summary>
/// <returns></returns>
public ClassDescription caption()
{
return "@MCS01608";
}

/// <summary>
///
/// </summary>
/// <returns></returns>
public Object dialog()
{
FormBuildButtonControl buttonControl;
DialogGroup dlgGroup;
FormBuildGroupControl buttonGroup;
dialog = super();
dlgGroup = dialog.addGroup('');
buttonGroup = dialog.formBuildDesign().control(dlgGroup.formBuildGroup().id());
buttonControl = buttonGroup.addControl(FormControlType::Button, 'Upload');
buttonControl.text("Upload file");

buttonControl.registerOverrideMethod(methodStr(FormButtonControl, clicked),
methodStr(MSUPCProductTableImport, uploadClickedEvent),
this);
return dialog;

}

private void uploadClickedEvent(FormButtonControl _formButtonControl)
{
FileUploadTemporaryStorageResult result = File::GetFileFromUser() as FileUploadTemporaryStorageResult;

if (result && result.getUploadStatus())
{
result.getFileContentType();
fileUrl = result.getDownloadUrl();
FileName = result.getFileName();
}

}

void run()
{
#OCCRetryCount;
try
{
ttsbegin;
this.buildData();
ttscommit;
info(strFmt("@SYS59939", importedLines, fileName));
}
catch (Exception::Deadlock)
{
retry;
}
catch (Exception::UpdateConflict)
{
if (appl.ttsLevel() == 0)
{
if (xSession::currentRetryCount() >= #RetryNum)
{
throw Exception::UpdateConflictNotRecovered;
}
else
{
retry;
}
}
else
{
throw Exception::UpdateConflict;
}
}
}


public void buildData()
{
System.IO.Stream stream;
#File

stream = File::UseFileFromURL(fileUrl);
using (ExcelPackage package = new ExcelPackage(stream))
{
OfficeOpenXml.ExcelWorksheet _worksheet;

package.Load(stream);
ExcelWorksheet worksheet = package.get_Workbook().get_Worksheets().get_Item(1);
OfficeOpenXml.ExcelRange range = worksheet.Cells;
int rowCount = worksheet.Dimension.End.Row - worksheet.Dimension.Start.Row + 1;
for (int i = 2; i <= rowCount; i++)
{

}
}

 

protected boolean canGoBatchJournal()
{
return false;
}

}

上一篇:vue的dialog显示分页失败


下一篇:iOS字符串的本地化(APP 内的本地化切换) 、nib本地化、图片本地化