Here is the code,it does exactly what i was asking for.
Well, I said you should transpose if needed. The only reason I did not transpose was because the indicator would have been too wide.
I have no idea why you decided to use a while loop at all, because it only iterates once. So what's the point?
What's the point of the shift register? The value in it never changes!
If you set transpose=true when writing to the spreadsheet, you are undoing the earlier transpose array. Eliminate all these extra operations.
The output fields are tab delimited and these files are typically not suitable to look at in a simple text editor or on a console. If you paste it into excel, all fields will be aligned, same as when you would paste it into word, as long as you set the tabs correctly.
You only need to pad the header and number fields with spaces if you use a simple text editor such as notepad wich does not understand tabs. You also cannot use a proportional font in that case.
I would not use padding with spaces. It is pretty pointless..