This post shows you how to import data from a fixed
width text file and insert records in a table.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | void importFile2Table(FileUploadTemporaryStorageResult _result) { str fileUrl; if (_result && _result.getUploadStatus()) { fileUrl = _result.getDownloadUrl(); using(System.IO.MemoryStream stream = _result.openResult() as System.IO.MemoryStream) using(System.IO.StreamReader sreader = new System.IO.StreamReader(stream, System.Text.Encoding::UTF8, true)) { this.readAndInsertFile(sreader, _result.getFileName()); } } info(strFmt("@SPBLabels:PWFIN_0618_028", _result.getFileName())); } void readAndInsertFile(System.IO.StreamReader _sreader, fileName _fileName) { str lineData; int lineNum; while (!_sreader.EndOfStream) { lineData = _sreader.ReadLine(); lineNum++; this.insertLines(lineData); } } void insertLines(str _lineData) { SPBTestImportTable spbTestImportTable; spbTestImportTable.DueDate = str2Date(subStr(_lineData, 7,8), 321); spbTestImportTable.TransDate = str2Date(subStr(_lineData, 24,8), 321); spbTestImportTable.Time = str2Time(subStr(_lineData, 32,4)); spbTestImportTable.Transmitter = subStr(_lineData, 4,13); spbTestImportTable.SDueDate = str2Date(subStr(_lineData, 17,8), 321); spbTestImportTable.Transmitter2 = subStr(_lineData, 34,13); spbTestImportTable.Observations = subStr(_lineData, 47,82); spbTestImportTable.Transmitter = subStr(_lineData, 4,13); spbTestImportTable.insert(); } |
No hay comentarios:
Publicar un comentario