beautifultable icon indicating copy to clipboard operation
beautifultable copied to clipboard

Column or Row span

Open digitronik opened this issue 5 years ago • 4 comments

I wont read code... but as per documentation beautifultable not supporting span

I am searching for spanning (row and column); for creating complex table in python cli tools.

digitronik avatar Aug 29 '19 17:08 digitronik

By span, you mean having a cell span multiple rows or columns right? It's not supported yet. However you can have tables within table which can be used to have a similar effect.

pri22296 avatar Aug 30 '19 03:08 pri22296

@pri22296 the work around is most ugly. For me it would be sufficient to have one header column spanning all columns as a "title".

Here is a workaround that works if the title fits (even number of chars i assume:

class PrettyTable:
   # construct me with the given title column headers and maxWidth of table
   def __init__(self,title,column_headers,maxWidth=80):
      self.title=title
      self.table=BeautifulTable(maxWidth,BeautifulTable.ALIGN_LEFT)
      self.table.column_headers=column_headers

   def append(self,row):
      self.table.append_row(row)

   # print with title
   def doprint(self):
      self.table._calculate_column_widths()
      topline=self.table._get_horizontal_line("-","+","-","+")
      print (topline)
      spc=math.floor((len(topline)-2-len(self.title))/2)
      print ("%s%s%s%s%s" % ("|"," "*spc,self.title," "*spc,"|"))
      print (self.table)

Example:

+------------------------------------------------------------------------------------+
|                                    UML Elements                                    |
+--------------------------+----------------+----------------------------------------+
| type                     | name           | id                                     |
+--------------------------+----------------+----------------------------------------+
| uml:Model                | AF9000_AC001   | eee_1045467100313_135436_1             |
+--------------------------+----------------+----------------------------------------+
| uml:Comment              | None           | _14_0_15600de_1212923403875_523230_98  |
+--------------------------+----------------+----------------------------------------+
| uml:Diagram              | AF9000_AC001   | _14_0_15600de_1212923424656_220623_234 |
+--------------------------+----------------+----------------------------------------+
| uml:Package              | com            | _14_0_15600de_1212925095109_943140_275 |
+--------------------------+----------------+----------------------------------------+
| uml:Package              | bitplan        | _14_0_15600de_1212928345781_915997_286 |
+--------------------------+----------------+----------------------------------------+
| uml:Package              | testcase       | _14_0_15600de_1212928371703_780096_300 |
+--------------------------+----------------+----------------------------------------+
| uml:Class                | nonModuleClass | _14_0_15600de_1219314497562_26818_220  |
+--------------------------+----------------+----------------------------------------+
| uml:Generalization       | None           | _14_0_15600de_1219314515109_159708_243 |
+--------------------------+----------------+----------------------------------------+
| uml:InterfaceRealization | None           | _14_0_15600de_1219587137703_204986_276 |
+--------------------------+----------------+----------------------------------------+
| uml:Property             | myOtherClass   | _14_0_15600de_1219314521734_73781_271  |
+--------------------------+----------------+----------------------------------------+
| uml:Property             | someAttribute  | _14_0_15600de_1219580854296_729497_190 |
+--------------------------+----------------+----------------------------------------+
| uml:Property             | m3Attribute    | _14_0_15600de_1219586720250_470018_335 |
+--------------------------+----------------+----------------------------------------+
| uml:Operation            | someOp         | _14_0_15600de_1219581060468_655557_326 |
+--------------------------+----------------+----------------------------------------+
| uml:Parameter            | None           | _14_0_15600de_1219581197968_386806_212 |
+--------------------------+----------------+----------------------------------------+
| uml:Parameter            | someParam      | _14_0_15600de_1219581095953_567006_329 |
+--------------------------+----------------+----------------------------------------+
| uml:Parameter            | m3Param        | _14_0_15600de_1219586780015_111591_406 |
+--------------------------+----------------+----------------------------------------+
| uml:Association          | None           | _14_0_15600de_1219314521734_799909_270 |
+--------------------------+----------------+----------------------------------------+
| uml:Property             | None           | _14_0_15600de_1219314521734_141888_272 |
+--------------------------+----------------+----------------------------------------+
| uml:Class                | string         | _14_0_15600de_1212928729953_262822_338 |
+--------------------------+----------------+----------------------------------------+

WolfgangFahl avatar Sep 09 '19 14:09 WolfgangFahl

@WolfgangFahl for now at least, I moved on dashtable. I love bueutifultable and planning to add row and column spanning.

digitronik avatar Sep 09 '19 14:09 digitronik

adding one more example for better planning...

+-------------+--------------------------------------------------------------------------------------------------------------------+-------+
|             |                                                      Targets                                                       |       |
|             +---------------+----------------+----------------+---------------+---------------+----------------+-----------------+       |
|  Versions   |    5.10.11    |     5.10.z     |     5.11.0     |    5.11.1     |    5.11.z     |     5.12.0     |   future        | Total |
|             +---+---+---+---+----+---+---+---+---+---+---+----+---+---+---+---+---+---+---+---+---+---+----+---+---+----+---+----+       |
|             | H | L | U | M | H  | L | U | M | H | L | U | M  | H | L | U | M | H | L | U | M | H | L | U  | M | H | L  | U | M  |       |
+-------------+---+---+---+---+----+---+---+---+---+---+---+----+---+---+---+---+---+---+---+---+---+---+----+---+---+----+---+----+-------+
|   5.10.0    | 2 | 5 | 0 | 1 | 1  | 1 | 2 | 0 | 2 | 0 | 0 | 0  | 0 | 3 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 22 | 0 | 0 | 14 | 1 | 10 |  65   |
+-------------+---+---+---+---+----+---+---+---+---+---+---+----+---+---+---+---+---+---+---+---+---+---+----+---+---+----+---+----+-------+

digitronik avatar Sep 09 '19 14:09 digitronik