using System.IO;
using OfficeOpenXml;
using OfficeOpenXml.ExcelPackage;
using OfficeOpenXml.ExcelRange;
System.IO.Stream stream;
ExcelSpreadsheetName sheeet;
FileUploadBuild fileUpload;
DialogGroup dlgUploadGroup;
FileUploadBuild fileUploadBuild;
FormBuildControl formBuildControl;
HpCheque _HpCheque;
COMVariantType type;
Dialog dialog = new Dialog('Import Cheques');
dlgUploadGroup = dialog.addGroup('@SYS54759');
formBuildControl = dialog.formBuildDesign().control(dlgUploadGroup.name());
fileUploadBuild = formBuildControl.addControlEx(classstr(FileUpload), 'Upload');
fileUploadBuild.style(FileUploadStyle::MinimalWithFilename);
fileUploadBuild.fileTypesAccepted('.xlsx');
str COMVariant2Str(COMVariant _cv)
{
switch (_cv.variantType())
{
case COMVariantType::VT_BSTR:
return _cv.bStr();
case COMVariantType::VT_EMPTY:
return'';
default:
throw error(strfmt('@SYS26908', _cv.variantType()));
}
}
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,columncount,j;
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;
columncount = (worksheet.Dimension.End.Column);
for (i = 2; i<= rowCount; i++)
{
//info(range.get_Item(i, 1).value);
ttsbegin;
_HpCheque.initValue();
_HpCheque.clear();
_HpCheque.ChequeNumber =range.get_Item(i, 1).value;
_HpCheque.TransDate = str2DateDMY(range.get_Item(i, 2).value);
_HpCheque.CustAccount =range.get_Item(i, 3).value;
_HpCheque.DueDate = str2DateDMY(range.get_Item(i, 4).value);
_HpCheque.CurrencyCode = range.get_Item(i, 5).value;
_HpCheque.UnitID = range.get_Item(i, 6).value;
_HpCheque.insert();
ttscommit;
}
}
}
else
{
error('Error here');
}
}
No comments:
Post a Comment