6

I am not even sure whether it is possible. I would like to change column headings of TableView output to letters such as A, B, C etc instead of 1,2,3. Here is an example:

RandomVariate[UniformDistribution[{10, 20}], {10, 3}] // TableView

enter image description here

I want the results to look like an excel spreadsheet as follows: enter image description here

Any help is greatly appreciated. Thank you in advance.

DLT
  • 235
  • 2
  • 10
  • 1
    using the undocumented TableView is not advised: https://mathematica.stackexchange.com/questions/170036/undocumented-tableview-function I suggest you to look into different visualisation formats. In this thread (and in many others) there are other options: https://mathematica.stackexchange.com/questions/208511/densityplot-with-text/208514#208514 – Fraccalo Jan 22 '20 at 15:41
  • @ Fraccalo, Thank you for your comment. However, my purpose is different from just data visualization. – DLT Jan 22 '20 at 21:06

2 Answers2

3

This may not be efficient but could be a good starting point. It works for data up to 26 columns. If you need more columns, you can modify the function.

    tableView[data_] := Module[{rowheadings, columnheading, output},
      rowheadings = Flatten[{Range[1, Length[data]]}];
      columnheading =Flatten[{"", CharacterRange["A", "Z"][[1 ;; Dimensions[data] 
                     [[2]]]]}];
      output = Prepend[Join[List /@ rowheadings, Map[Style[NumberForm[#, 6]] &, data, {-1}], 2], 
             columnheading];
      Grid[output, Frame -> All, FrameStyle -> GrayLevel[.9],
 Alignment -> {Center, Center}, Background -> {{GrayLevel[.8], None}, {GrayLevel[.8], None}}]
      ]

Here is an example:

data = RandomVariate[UniformDistribution[{10, 20}], {7, 5}];
tableView[data]

enter image description here

ramesh
  • 2,309
  • 16
  • 29
1

Looking at the options of TableView it seems like it's not possible.

Options[TableView]

{Alignment -> {Automatic, Automatic}, AllowedDimensions -> Automatic, Appearance -> Automatic, AppearanceElements -> All, Background -> Automatic, BaselinePosition -> Automatic, BaseStyle -> {}, ContentPadding -> True, DefaultBaseStyle -> "TableView", Enabled -> Automatic, FieldSize -> {{1., 5.}, {1., 1.}}, FrameMargins -> Automatic, ImageMargins -> Automatic, ImageSize -> Automatic, Scrollbars -> {Automatic, Automatic}, ScrollPosition -> {0., 0.}, Spacings -> Automatic}

Anyway, as I suggested in the comment, the use of TableView is not advised as it causes crashes and is still under development.

Fraccalo
  • 6,057
  • 13
  • 28
  • 2
    Looking at Options[TableView] today in version 12.3.1 shows that there is a new Header option. And yes it does exactly what is being asked. Try TableView[RandomVariate[UniformDistribution[{10, 20}], {10, 3}], Headers -> {{"A", "B", "C"}, Automatic}] – Gustavo Delfino Nov 30 '21 at 15:21
  • @GustavoDelfino perhaps you can add this as an answer? – Dunlop Dec 10 '21 at 19:25