Groovy column formatting with text wrapping - text

I am printing some output from a database to a text file. I will basically print out four fixed-width columns. The last column may need to wrap to the next line as the output from the db may be longer than the column-width. Is there an easy way (or plugin) to do this in groovy? Obviously if the column wraps, I don't want any further output from the other three columns to display until I'm done wrapping the last column.
This next part I'm more worried about. Two of the other columns may also need to wrap - but can only wrap if that last column also needs to wrap. Otherwise, I don't need to wrap those other two columns. Output would be something like this:
Col1 ..... Col2 no-wrap.......Col3 no-wrap.......Col4 no-wrap
Col1 ..... Col2 can..............Col3 can..............Col4 now needs
.............. now wrap.............now wrap.............to wrap so wrap
......................................................................the others

look at
http://groovy.codehaus.org/Formatting+simple+tabular+text+data
for an example on how to format in columns with wrapping

Related

Converting grouped /nested data table to tabular form

I have been trying to covert tables that I get in the grouped format as in the picture to tabular form to make it pivotable. I have tried to use power query but not sure how to do it. I am not sure where to start and I appreciate your guidance as to where to start or how to make it
if you want to use powerquery, Assuming those are spaces, your best bet is probably to add some custom columns that check the number of leading spaces from column one to determine the level. For example,
= if Text.StartsWith([Column1], " ") then Text.Trim([Column1]) else null
then do something similar but with different leading space counts into separate columns, and then fill down to populate a table
You could alternately try to split the column on, lets say, 3 spaces, depending on what the indentions are. (0/3/6/9)

How to replace numbers with corresponding text values in Excel without making it treat a number individually?

Okay, so here's the thing. I have a list of compounds which are listed as compound_1,compound_2,compound_3 and so on. I would like to change it to the corresponding compound names using Excel. There are over 140 compounds and in the datatable, the compound repeats itself for a number of times.
The problem arises when the Excel treats two digit numbers as two individual numbers instead of treating them as a one whole unit and substitutes value accordingly. I'll give you an example. Say, compound_2 is Nicotine and compound_20 is quercetin, it treats 20 as 2 and 0, and the cell is replaced with Nicotine0 instead of quercetin.
Is there a way to replace it without this hassle?
P.S: The table looks something like this:
compound_1 Nicotine
compound_2 β- sitosterol
compound_3 D - mannitol
compound_4 Stigma Sterol
compound_5 Betulinic Acid
And, I've attached a collage comparing the column values before(left) and after(right) I tried replacing compound_2 with Nicotine.(This is only for example and not the real pair)image

csv.writer inserting comma between each character

I'm using the following code:
plugara=['CNPJ', 56631781000177, 21498104000148, 3914296000144, 28186370000184]
plugara=map(str,plugara)
with open(result.csv, 'w') as f:
wr = csv.writer(f,dialect='excel')
wr.writerows(plugara)
The result I'm getting is putting a comma between each character and is breaking into a different column:
I would like it to be without those commas like this:
Any ideas?
The writerows method that you're calling expects its argument to be an iterable containing rows. Each row should be iterable itself, with its values being the items in the row. In your case, the values are strings, which can be iterated upon to give their characters. Unfortunately, that's not what you intended!
Exactly how to fix this issue depends on what you want the output to be.
If you want your output to consist of a single row, then just change your call to writerow to instead of writerows (note the plural). The writerow method will only write a single row out, rather than trying to write several of them at once.
On the other hand, if you want many rows, with just one item in each one (forming a single column), then you'll need to transform your data a little bit. Rather than directly passing in your list of strings, you need to produce an iterable of rows with one item in them (perhaps 1-tuples). Try something like this:
wr.writerows((item,) for item in plugara)
This call uses a generator expression to transform each string from plugara into a 1-tuple containing the string. This should produce the output you want.

Excel Text to column

Does any of you know if exist any function to split the double brake line to column? I do know how to split by spaces like: =SUBSTITUTE(SUBSTITUTE(B2;CHAR(13);"");CHAR(10);"|"), but I want something like the image bellow:
The solution is depend on your string. If you have only one separation as shown, you can use following equations.
for the 1st part
=LEFT(SUBSTITUTE(A1,CHAR(10),",",1),FIND(",",SUBSTITUTE(A1,CHAR(10),",",1),1)-1)
for the 2nd part
=MID(SUBSTITUTE(A1,CHAR(10),",",1),FIND(",",SUBSTITUTE(A1,CHAR(10),",",1),1)+1,10000)
This is independent from the number of consecutive char(10) characters between text.
Just use two different formulas, there are many ways you could go about it. Say something like =LEFT(A1,FIND(CHAR(10),A1)) for the first column and =RIGHT(A1,LEN(A1)-SEARCH(CHAR(10),A1)) for the second one.

Excel: Multiple Substitute without nesting and without VBA

I have cells that have data that I want to remove. The cells typically look like this:
alm1 105430_65042M
1993_5689IB
ALM99 3455 344C
0001_4555Alm5
Some but not all of the cells contain text like "almj" where "j" is a positive integer. I want to remove that part. I want the output to look like this:
105430_65042M
1993_5689IB
3455 344C
0001_4555
So something like this works
SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(A2,"alm1",""),"ALM99",""),"Alm5","")
But for my full data set I would need this to be several-hundred-deep nested function because my "alm" is sometimes in capital letters and sometimes not and the integer can vary from 1 to 100. This seems like a painful way to do this.
Is there a way that I can tell it to look for text listed in a column (so I can have a column in a different sheet that just goes from alm, alm1, ..., alm100 ) and then also ask it to ignore capitalization and then just replace stuff?
I tried referencing a column $M$1:$M$100 in the second argument of the function substitute but it's not working.
SUBSTITUTE(A2,$M$1:$M$100,"")
Where the column M contains "alm" alm1", ..., "alm100" etc.
This should work for you, it returned expected results on your provided sample data:
=IF(COUNTIF(A2,"*alm*")=0,A2,TRIM(SUBSTITUTE(A2&" ",MID(A2&" ",SEARCH("alm",A2),FIND(" ",A2&" ",SEARCH("alm",A2))),"")))
Excel has lousy string-handling capabilities. Regular expressions would make this task much easier.
In JavaScript, it's as simple as:
string.replace(/ *alm[0-9]+ */gi,'')
This does a global (g) case-insensitive (i) search of everything with:
0 or more spaces
followed by "alm" (in any case)
followed by 1 or more numbers
followed by 0 or more spaces
You can paste your data in the HTML box in this fiddle, and it will fix it:
http://jsfiddle.net/xs71bvan/2/

Resources