Skip to content

Commit cf4512c

Browse files
docs: DOC-1139: Add HTML import/export documentation for Groovy (#7965)
1 parent 2a8e79e commit cf4512c

4 files changed

Lines changed: 61 additions & 0 deletions

File tree

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
---
2+
title: Export HTML files
3+
---
4+
5+
Deephaven can convert tables to HTML table-formatted strings via the [`html`](/core/javadoc/io/deephaven/engine/util/TableTools.html#html(io.deephaven.engine.table.Table)) method from [`TableTools`](/core/javadoc/io/deephaven/engine/util/TableTools.html). It converts a Deephaven table to a string HTML table.
6+
7+
## `html`
8+
9+
The [`html`](/core/javadoc/io/deephaven/engine/util/TableTools.html#html(io.deephaven.engine.table.Table)) method requires only a single argument — the table to convert. Here, we'll create a simple table and convert it to HTML.
10+
11+
```groovy order=:log,table
12+
table = newTable(
13+
stringCol("Letter", "A", "B", "C"),
14+
intCol("Num", 1, 2, 3),
15+
instantCol("Datetime",
16+
parseInstant("2007-12-03T10:15:30.00Z"),
17+
parseInstant("2007-12-03T10:15:30.00Z"),
18+
parseInstant("2007-12-03T10:15:30.00Z"),
19+
)
20+
)
21+
22+
htmlTable = html(table)
23+
24+
println(htmlTable)
25+
```
26+
27+
> [!NOTE]
28+
> Since HTML tables represent all data as plain, untyped text, all typing will be lost.
29+
30+
## Related documentation
31+
32+
- [Read HTML files](./html-import.md)
33+
- [Export CSV files](./csv-export.md)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
title: Read HTML files into Deephaven tables
3+
---
4+
5+
Deephaven does not provide built-in methods for reading HTML tables in Groovy. Because Groovy runs on the JVM, you can use any Java HTML parsing library to pull data from HTML into Deephaven tables.
6+
7+
[Jsoup](https://jsoup.org/) is a popular Java library for parsing HTML, similar to [BeautifulSoup](https://www.crummy.com/software/BeautifulSoup/bs4/doc/) in Python. It handles malformed real-world HTML gracefully and bundles both HTTP fetching and HTML parsing in a single dependency. It is not included in Deephaven by default and must be added to the classpath before use. See [Install and use Java packages](../install-and-use-java-packages.md) for instructions on how to add external JARs to a Deephaven worker.
8+
9+
Once Jsoup is available, you can use it in Groovy scripts to fetch and parse HTML tables, then construct Deephaven tables from the extracted data using [`newTable`](/core/javadoc/io/deephaven/engine/util/TableTools.html#newTable(io.deephaven.engine.table.impl.util.ColumnHolder...)) and column factory methods such as `stringCol`.
10+
11+
## Related documentation
12+
13+
- [Export HTML files](./html-export.md)
14+
- [Install and use Java packages](../install-and-use-java-packages.md)

docs/groovy/sidebar.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,19 @@
181181
}
182182
]
183183
},
184+
{
185+
"label": "HTML",
186+
"items": [
187+
{
188+
"label": "Read HTML files",
189+
"path": "how-to-guides/data-import-export/html-import.md"
190+
},
191+
{
192+
"label": "Export HTML files",
193+
"path": "how-to-guides/data-import-export/html-export.md"
194+
}
195+
]
196+
},
184197
{
185198
"label": "Arrow Flight",
186199
"path": "how-to-guides/data-import-export/arrow-flight.md"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"file":"how-to-guides/data-import-export/html-export.md","objects":{"table":{"type":"Table","data":{"columns":[{"name":"Letter","type":"java.lang.String"},{"name":"Num","type":"int"},{"name":"Datetime","type":"java.time.Instant"}],"rows":[[{"value":"A"},{"value":"1"},{"value":"2007-12-03 05:15:30.000"}],[{"value":"B"},{"value":"2"},{"value":"2007-12-03 05:15:30.000"}],[{"value":"C"},{"value":"3"},{"value":"2007-12-03 05:15:30.000"}]]}},":log":{"type":"Log","data":"<table border=\"1\">\n<tr>\n<th>Letter</th>\n<th>Num</th>\n<th>Datetime</th>\n</tr>\n<tr><td>A</td><td>1</td><td>2007-12-03T10:15:30.000000000 Etc/UTC</td></tr>\n<tr><td>B</td><td>2</td><td>2007-12-03T10:15:30.000000000 Etc/UTC</td></tr>\n<tr><td>C</td><td>3</td><td>2007-12-03T10:15:30.000000000 Etc/UTC</td></tr>\n</table>\n\n"}}}

0 commit comments

Comments
 (0)