I am being sent data in CSV files. The sender is providing helpful comments and lots of headings so that it is fine to look at in a spreadsheet environment. However, when I import it into Mathematica it becomes difficult to read using TableForm
mostly because many of the cells contain comments that are very long.
How do I restrict the length of TableForm
entries?
Here is a minimum working example of the results of using Import[]
on the CSV file.
ip = {{{"", "", ""}, {"", "", ""}, {"",
"Data for tests on the 14th April 2021", ""}, {"", "", ""}, {"",
"Here is a very long line. Only the start of the line needs to
be seen since an overview of the spreadsheet is required. ", ""}, {"",
"", ""}, {"",
"The data is in 4 four sheets this sheet is the summary",
""}, {"", "", ""}, {"", "Start ", "End"}, {"Data 1", 2.`,
5.`}, {"Data 2", 5.`, 9.`}, {"Data 3", 20.`, 25.`}, {"Data 4",
12.`, 17.`}}, {{"x vals", "y vals"}, {2.`,
0.3330287479237922`}, {3.`, 0.19273318644865778`}, {4.`,
0.2689069410951601`}, {5.`, 0.08207429250157161`}}, {{"x vals",
"y vals"}, {5.`, 0.45418961829920845`}, {6.`,
0.571585992020961`}, {7.`, 0.2085062721975699`}, {8.`,
0.4228854382612791`}, {9.`, 0.8204853099017002`}}, {{"x vals",
"y vals"}, {20.`, 0.004555883050753273`}, {21.`,
0.9461665188994238`}, {22.`, 0.5266492863708679`}, {23.`,
0.993247994762222`}, {24.`, 0.40219540885589733`}, {25.`,
0.7634085960638198`}}, {{"x vals", "y vals"}, {12.`,
0.15418438184183136`}, {13.`, 0.6223264477185402`}, {14.`,
0.9009276274909394`}, {15.`, 0.6832380927198871`}, {16.`,
0.16021536248120283`}, {17.`, 0.27399014026061996`}}};
Dimensions[ip]
The Dimensions[]
tells me that there are 5 sheets. So I look at the first sheet using TableForm
.
TableForm[ip[[1]], TableSpacing -> {0, 1}]

As you can see the long comments in some CSV cells make some entries in the table much longer than others. I just want an overview of the contents so I don’t want to see all the details in each entry. I probably need to do some form of converting to strings and then limiting the number of characters in each string. I am sure there are other possibilities as well. Thanks for helping.