this is the input file
the bot has to calculate the length of each row and subtract the calculated length from reference sheet with length column and the result is the space which we have to give in the text file…
say for example - in the input sheet first row is 238 and in the reference length is 3 so length of first row in the input is 3 so if i subtract it 3-3 = 0 so there is no space…likewise for the second row length is 8 digit and if i subtract it with the length column from the reference it is 30 so 30-8 is 22…22 times space i have to give…so including the length of the each row it should be the length as mentioned in the reference length column. Please help me how to achive this
What you want is to build fixed lenght file format.
You can use approach described here
format = "{0,3}{1,30}{2,2}{3,2}{4,1}{5,2}{6,8}{7,8}{8,13}"
formatedString = String.format(format,238,86571234,4,3,1,1,13122021,12122022,12345)
Explanation:
1/ define format of the fixed lenght string (details under provided link)
2/ use “string.format” method to format data from your sheet using “format”
Hi, Thanks for your response but i dont want to hard code anything inside the code, bot should calculate the space based on the length from the reference sheet
First, make sure you’re reading the input data and the reference sheet into two separate DataTables. For each row in the input data, calculate its length. Then, for each row, get the corresponding reference length from the reference sheet using the row index.
After that, subtract the input row’s length from the reference length to get the space required. If the result is greater than 0, use PadRight() to add the necessary spaces to the row content. If no space is needed, just use the row content without padding.
Finally, write the formatted output to a text file, making sure each line has the correct number of spaces.
This will ensure that the space calculation and text formatting work dynamically for each row.