Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions docs/groovy/how-to-guides/data-import-export/html-export.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---
title: Export HTML files
---

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.

## `html`

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.

```groovy order=:log,table
table = newTable(
stringCol("Letter", "A", "B", "C"),
intCol("Num", 1, 2, 3),
instantCol("Datetime",
parseInstant("2007-12-03T10:15:30.00Z"),
parseInstant("2007-12-03T10:15:30.00Z"),
parseInstant("2007-12-03T10:15:30.00Z"),
)
)

htmlTable = html(table)

println(htmlTable)
```

> [!NOTE]
> Since HTML tables represent all data as plain, untyped text, all typing will be lost.

## Related documentation

- [Read HTML files](./html-import.md)
- [Export CSV files](./csv-export.md)
14 changes: 14 additions & 0 deletions docs/groovy/how-to-guides/data-import-export/html-import.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
title: Read HTML files into Deephaven tables
---

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.

[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.

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`.

## Related documentation

- [Export HTML files](./html-export.md)
- [Install and use Java packages](../install-and-use-java-packages.md)
13 changes: 13 additions & 0 deletions docs/groovy/sidebar.json
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,19 @@
}
]
},
{
"label": "HTML",
"items": [
{
"label": "Read HTML files",
"path": "how-to-guides/data-import-export/html-import.md"
},
{
"label": "Export HTML files",
"path": "how-to-guides/data-import-export/html-export.md"
}
]
},
{
"label": "Arrow Flight",
"path": "how-to-guides/data-import-export/arrow-flight.md"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +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"}}}
Loading