TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Enrico Hasnawi
NA
5
440
How to loop data (or the best logic) to generate output
Oct 15 2019 2:51 AM
so i have a data(in .txt)
```
ABC@ID@550656019@IDR@2667378@
[email protected]
INV@======================================================================
INV@REFERENCE AMOUNT
INV@956VII2019 2,667,378
INV@TOTAL INVOICE 2,667,378
DEF@ID@550656019@IDR@100186049|
[email protected]
INV@======================================================================
INV@REFERENCE AMOUNT
INV@A019128B 2,726,903
INV@A019206 3,119,665
INV@A019126 6,296,663
INV@A019138 6,405,257
INV@A019036 6,700,000
INV@19149 7,101,957
INV@A019128A 9,171,400
INV@A019164 9,814,861
INV@A019168 12,638,424
INV@19109 12,675,303
INV@A018928 23,535,617
INV@TOTAL INVOICE 100,186,049
ABC@ID@550656019@IDR@97160972@
[email protected]
INV@======================================================================
INV@REFERENCE AMOUNT
INV@190700185 2,786,589
INV@190700184 10,191,000
INV@190700164 11,844,283
INV@190700218 11,930,350
INV@190700165 19,017,750
INV@190700163 41,391,000
INV@TOTAL INVOICE 97,160,972
```
how to process the data so i can get the output like :
```
0|ABC|550656019|99828350|2
1|ABC|
[email protected]
2|956VII2019|2667378
1|ABC|
[email protected]
2|190700185|2,786,589
2|190700184|10,191,000
2|190700164|11,844,283
2|190700218|11,930,350
2|190700165|19,017,750
2|190700163|41,391,000
0|DEF|550656019|100186049|1
1|DEF|
[email protected]
2|A019128B|2,726,903
2|A019206|3,119,665
2|A019126|6,296,663
2|A019138|6,405,257
2|A019036|6,700,000
2|19149|7,101,957
2|A019128A|9,171,400
2|A019164|9,814,861
2|A019168|12,638,424
2|19109|12,675,303
2|A018928|23,535,617
```
Explanation :
```
0 is for header
it will check if the data ( not the row with invoice) has the same field or not ( field 1("ABC") - field 4("IDR")) if yes, it will total the amount of the total invoice , and count the total record who has the same field
so the format will be "0|field1|field3|total invoice amount|total record"
1 is for detail
it will list the detail of the header -> you can check that each row has different email , the detail will be split between the email.
2 is for invoice detail
just list the Invoice (after references) and the amount , but not the total invoice
after you put the detail for one email , it will list the invoice then it will start to list the detail with different emails
```
im already stuck here and already try to convert .txt to .xlsx(hope it will be easier) but its not , im stuck at the logic and maybe you guys can help
Code to convert to xlsx
```
//string[]
var lines = File.ReadAllLines(textBox1.Text);
//read line then split
xlApp = new excel.Application();
xlWb = xlApp.Workbooks.Add();
xlWs = (excel.Worksheet)xlWb.Worksheets.get_Item(1);
row = 1;
col = 1;
for (int i = 0; i < lines.Length; i++)
{
textsplit = lines[i].Split('@');
for (int j = 0; j < textsplit.Length; j++)
{
try
{
xlWs.Cells[row, col] = textsplit[j].ToString();
col++;
}
catch (Exception ex)
{
}
}
row++;
col = 1;
}
//save ke file excel tampungan
xlWb.SaveAs(appPath + "testing.xlsx", excel.XlFileFormat.xlOpenXMLWorkbook, missing, missing,
false, false, excel.XlSaveAsAccessMode.xlNoChange, missing, missing, missing, missing, missing);
xlWb.Close();
closeExcel(xlApp); closeExcel(xlApp);
textBox2.Text = appPath + "testing.xlsx";
//ambil field penting dan dimasukkkan ke .txt
```
Thanks for the help
Reply
Answers (
1
)
Websocket sendasync response from request
C# automation testing