gotabulate

package module
v1.2.10 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 17, 2026 License: Apache-2.0 Imports: 8 Imported by: 3 modules, 2 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Gotabulate - Easily pretty-print tabular data

Fork of https://github.com/bndr/gotabulate. Added formatting output for mysqlrun.

GoDoc Build Status

Summary

Go-Tabulate - Generic Go Library for easy pretty-printing of tabular data.

Installation

cd <HOME DIRECTORY>/go/codecloud.web.att.com/st_cloudutils #(Make directories if they don't exist)
mkdir gotabulate
git clone ssh://git@codecloud.web.att.com:7999/st_cloudutils/gotabulate.git gotabulate
cd gotabulate
export GOOS=linux;export GOARCH=amd64
go install `go list`

Description

Supported data types:

  • 2D Array of Int, Int64, Float64, String, interface{}
  • Map of String, interface{} (Keys will be used as header)

Supported output formats:

  • Text grids: simple, grid, gridt, mysql, mysqlg, bingo
  • Data formats: csv, tab, plain, text
  • Markup: markdown, rst
  • HTML: Modern Bootstrap 5 tables (CDN or offline mode)

Usage


// Create Some Fake Rows
row_1 := []interface{}{"john", 20, "ready"}
row_2 := []interface{}{"bndr", 23, "ready"}

// Create an object from 2D interface array
t := gotabulate.Create([][]interface{}{row_1, row_2})

// Set the Headers (optional)
t.SetHeaders([]string{"age", "status"})

// Set the Empty String (optional)
t.SetEmptyString("None")

// Set Align (Optional)
t.SetAlign("right")

// Print the result: grid, or simple
fmt.Println(t.Render("grid"))

+---------+--------+-----------+
|         |    age |    status |
+=========+========+===========+
|    john |     20 |     ready |
+---------+--------+-----------+
|    bndr |     23 |     ready |
+---------+--------+-----------+

HTML Table Generation

Generate modern Bootstrap tables in multiple modes:

Default - CDN mode (small files, assumes internet):

table := gotabulate.Create(data)
table.SetHeaders([]string{"Name", "Value"})
html := table.Render("html")  // ~2KB file, uses CDN

Offline mode (embedded CSS, no internet needed):

table := gotabulate.Create(data)
table.SetHeaders([]string{"Name", "Value"})
table.SetHTMLOfflineMode()  // Embed Bootstrap CSS
html := table.Render("html")  // ~100KB file, self-contained

Minimal CSS (no Bootstrap):

table := gotabulate.Create(data)
table.SetHeaders([]string{"Name", "Value"})
table.SetHTMLMinimal()
html := table.Render("html")  // Clean styling, offline

Supported HTML options:

  • SetHTMLBootstrap(version) - Bootstrap 4 or 5
  • SetHTMLTitle(title) - Add table title
  • SetHTMLOfflineMode() - Embed CSS for offline use
  • SetHTMLUseCDN(true/false) - Toggle CDN vs embedded
  • SetHTMLCustomCSS(css) - Add custom styles

Example with String

// Some Strings
string_1 := []string{"TV", "1000$", "Sold"}
string_2 := []string{"PC", "50%", "on Hold"}

// Create Object
tabulate := gotabulate.Create([][]string{string_1, string_2})

// Set Headers
tabulate.SetHeaders([]string{"Type", "Cost", "Status"})

// Render
fmt.Println(tabulate.Render("simple"))

---------  ----------  ------------
    Type        Cost        Status
---------  ----------  ------------
      TV       1000$          Sold

      PC         50%       on Hold
---------  ----------  ------------

Example with String Wrapping


tabulate := gotabulate.Create([][]string{[]string{"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus laoreet vestibulum pretium. Nulla et ornare elit. Cum sociis natoque penatibus et magnis",
	"Vivamus laoreet vestibulum pretium. Nulla et ornare elit. Cum sociis natoque penatibus et magnis", "zzLorem ipsum", " test", "test"}, []string{"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus laoreet vestibulum pretium. Nulla et ornare elit. Cum sociis natoque penatibus et magnis",
	"Vivamus laoreet vestibulum pretium. Nulla et ornare elit. Cum sociis natoque penatibus et magnis", "zzLorem ipsum", " test", "test"}, STRING_ARRAY, []string{"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus laoreet vestibulum pretium. Nulla et ornare elit. Cum sociis natoque penatibus et magnis",
	"Vivamus laoreet vestibulum pretium. Nulla et ornare elit. Cum sociis natoque penatibus et magnis", "zzLorem ipsum", " test", "test"}, STRING_ARRAY})

tabulate.SetHeaders([]string{"Header 1", "header 2", "header 3", "header 4"})
// Set Max Cell Size
tabulate.SetMaxCellSize(16)

// Turn On String Wrapping
tabulate.SetWrapStrings(true)

// Render the table
fmt.Println(tabulate.Render("grid"))

+---------------------+---------------------+----------------+-------------+-------------+
|                     |            Header 1 |       header 2 |    header 3 |    header 4 |
+=====================+=====================+================+=============+=============+
|    Lorem ipsum dolo |    Vivamus laoreet  |    Lorem ipsum |        test |        test |
|    r sit amet, cons |    vestibulum preti |                |             |             |
|    ectetur adipisci |    um. Nulla et orn |                |             |             |
|    ng elit. Vivamus |    are elit. Cum so |                |             |             |
|     laoreet vestibu |    ciis natoque pen |                |             |             |
|    lum pretium. Nul |    atibus et magnis |                |             |             |
|    la et ornare eli |                     |                |             |             |
|    t. Cum sociis na |                     |                |             |             |
|    toque penatibus  |                     |                |             |             |
|           et magnis |                     |                |             |             |
+---------------------+---------------------+----------------+-------------+-------------+
|    Lorem ipsum dolo |    Vivamus laoreet  |    Lorem ipsum |        test |        test |
|    r sit amet, cons |    vestibulum preti |                |             |             |
|    ectetur adipisci |    um. Nulla et orn |                |             |             |
|    ng elit. Vivamus |    are elit. Cum so |                |             |             |
|     laoreet vestibu |    ciis natoque pen |                |             |             |
|    lum pretium. Nul |    atibus et magnis |                |             |             |
|    la et ornare eli |                     |                |             |             |
|    t. Cum sociis na |                     |                |             |             |
|    toque penatibus  |                     |                |             |             |
|           et magnis |                     |                |             |             |
+---------------------+---------------------+----------------+-------------+-------------+
|         test string |       test string 2 |           test |         row |        bndr |
+---------------------+---------------------+----------------+-------------+-------------+
|    Lorem ipsum dolo |    Vivamus laoreet  |    Lorem ipsum |        test |        test |
|    r sit amet, cons |    vestibulum preti |                |             |             |
|    ectetur adipisci |    um. Nulla et orn |                |             |             |
|    ng elit. Vivamus |    are elit. Cum so |                |             |             |
|     laoreet vestibu |    ciis natoque pen |                |             |             |
|    lum pretium. Nul |    atibus et magnis |                |             |             |
|    la et ornare eli |                     |                |             |             |
|    t. Cum sociis na |                     |                |             |             |
|    toque penatibus  |                     |                |             |             |
|           et magnis |                     |                |             |             |
+---------------------+---------------------+----------------+-------------+-------------+
|         test string |       test string 2 |           test |         row |        bndr |
+---------------------+---------------------+----------------+-------------+-------------+

Examples

t := gotabulate.Create([][]string{STRING_ARRAY, STRING_ARRAY})

t.SetHeaders(HEADERS) // If not headers are set, the first row will be used.

t.SetEmptyString("None") // Set what will be printed in the empty cell

rendered_string := t.Render("simple") // Render() will return a string

Simple Table
----------------------  ----------------------  ----------------------  -------------  -------------
             Header 1                Header 2                Header 3       Header 4       Header 5 
----------------------  ----------------------  ----------------------  -------------  -------------
          test string           test string 2                    test            row           bndr 

          test string           test string 2                    test            row           bndr 

    4th element empty       4th element empty       4th element empty           None           None 
----------------------  ----------------------  ----------------------  -------------  -------------

Grid Table (Align Right)
+-------------+-------------+-------------+-------------+-------------+
|    Header 1 |    Header 2 |    Header 3 |    Header 4 |    Header 5 |
+=============+=============+=============+=============+=============+
|       10.01 |      12.002 |      -123.5 |    20.00005 |        1.01 |
+-------------+-------------+-------------+-------------+-------------+
|       10.01 |      12.002 |      -123.5 |    20.00005 |        1.01 |
+-------------+-------------+-------------+-------------+-------------+
|       10.01 |      12.002 |      -123.5 |    20.00005 |        None |
+-------------+-------------+-------------+-------------+-------------+

Padded Headers:
+----------------------+----------------------+----------------------+-------------+-------------+
|                      |             Header 1 |             header 2 |    header 3 |    header 4 |
+======================+======================+======================+=============+=============+
|          test string |        test string 2 |                 test |         row |        bndr |
+----------------------+----------------------+----------------------+-------------+-------------+
|          test string |        test string 2 |                 test |         row |        bndr |
+----------------------+----------------------+----------------------+-------------+-------------+
|    4th element empty |    4th element empty |    4th element empty |        None |        None |
+----------------------+----------------------+----------------------+-------------+-------------+

Align Center:
+-------------+-------------+-------------+-------------+-------------+
|   Header 1  |   Header 2  |   Header 3  |   Header 4  |   Header 5  |
+=============+=============+=============+=============+=============+
|    10.01    |    12.002   |    -123.5   |   20.00005  |     1.01    |
+-------------+-------------+-------------+-------------+-------------+
|    10.01    |    12.002   |    -123.5   |   20.00005  |     1.01    |
+-------------+-------------+-------------+-------------+-------------+
|    10.01    |    12.002   |    -123.5   |   20.00005  |     1.01    |
+-------------+-------------+-------------+-------------+-------------+

Align Left:
+-------------+-------------+-------------+-------------+-------------+
| Header 1    | Header 2    | Header 3    | Header 4    | Header 5    |
+=============+=============+=============+=============+=============+
| 10.01       | 12.002      | -123.5      | 20.00005    | 1.01        |
+-------------+-------------+-------------+-------------+-------------+
| 10.01       | 12.002      | -123.5      | 20.00005    | 1.01        |
+-------------+-------------+-------------+-------------+-------------+
| 10.01       | 12.002      | -123.5      | 20.00005    | 1.01        |
+-------------+-------------+-------------+-------------+-------------+
Status

Beta version. There may be edge cases that I have missed, so if your tables don't render properly please open up an issue.

Contribute

All Contributions are welcome. The todo list is on the bottom of this README. Feel free to send a pull request.

License

Apache License 2.0

TODO

  • Add more examples
  • Better Documentation
  • Implement more data table formats
  • Decimal point alignment for floats

Acknowledgement

Inspired by Python package https://pypi.python.org/pypi/tabulate

Documentation

Overview

Package gotabulate provides table formatting and rendering capabilities. It supports multiple output formats including text grids, HTML, CSV, and more.

Index

Constants

This section is empty.

Variables

View Source
var TableFormats = map[string]TableFormat{

	"simple": {
		LineTop:         Line{"", "-", "  ", ""},
		LineBelowHeader: Line{"", "-", "  ", ""},
		LineBottom:      Line{"", "-", "  ", ""},
		HeaderRow:       Row{"", "  ", ""},
		DataRow:         Row{"", "  ", ""},
		Padding:         1,
	},
	"plain": {
		HeaderRow: Row{"", "  ", ""},
		DataRow:   Row{"", "  ", ""},
		Padding:   1,
	},
	"tab": {
		HeaderRow: Row{"", "\t", ""},
		DataRow:   Row{"", "\t", ""},
		Padding:   0,
	},
	"text": {
		HeaderRow: Row{"", " ", ""},
		DataRow:   Row{"", " ", ""},
		Padding:   0,
	},
	"csv": {
		HeaderRow: Row{"", ",", ""},
		DataRow:   Row{"", ",", ""},
		Padding:   0,
	},

	"mysql": {
		LineTop:         Line{"+", "-", "+", "+"},
		LineBelowHeader: Line{"+", "=", "+", "+"},
		LineBottom:      Line{"+", "-", "+", "+"},
		HeaderRow:       Row{"|", "|", "|"},
		DataRow:         Row{"|", "|", "|"},
		Padding:         1,
	},
	"mysqlg": {
		LineTop:         Line{"╒", "═", "╤", "╕"},
		LineBelowHeader: Line{"╞", "═", "╪", "╡"},
		LineBottom:      Line{"└", "─", "┴", "┘"},
		HeaderRow:       Row{"│", "│", "│"},
		DataRow:         Row{"│", "│", "│"},
		Padding:         1,
	},

	"grid": {
		LineTop:         Line{"╒", "═", "╤", "╕"},
		LineBelowHeader: Line{"╞", "═", "╪", "╡"},
		LineBetweenRows: Line{"│", "─", "┼", "│"},
		LineBottom:      Line{"└", "─", "┴", "┘"},
		HeaderRow:       Row{"│", "│", "│"},
		DataRow:         Row{"│", "│", "│"},
		Padding:         1,
	},
	"gridt": {
		LineTop:         Line{"+", "-", "+", "+"},
		LineBelowHeader: Line{"+", "=", "+", "+"},
		LineBetweenRows: Line{"+", "-", "+", "+"},
		LineBottom:      Line{"+", "-", "+", "+"},
		HeaderRow:       Row{"|", "|", "|"},
		DataRow:         Row{"|", "|", "|"},
		Padding:         1,
	},
	"bingo": {
		LineTop:         Line{"╒", "═", "╤", "╕"},
		LineBelowHeader: Line{"╞", "═", "╪", "╡"},
		LineBetweenRows: Line{"│", "─", "┼", "│"},
		LineBottom:      Line{"└", "─", "┴", "┘"},
		HeaderRow:       Row{"│", "│", "│"},
		DataRow:         Row{"│", "│", "│"},
		Padding:         1,
	},

	"markdown": {
		LineBelowHeader: Line{"|", "-", "|", "|"},
		HeaderRow:       Row{"| ", " | ", " |"},
		DataRow:         Row{"| ", " | ", " |"},
		Padding:         0,
	},
	"rst": {
		LineTop:         Line{"", "=", " ", ""},
		LineBelowHeader: Line{"", "=", " ", ""},
		LineBottom:      Line{"", "=", " ", ""},
		HeaderRow:       Row{"", "  ", ""},
		DataRow:         Row{"", "  ", ""},
		Padding:         1,
	},

	"simple-nohead": {
		LineTop:    Line{"", "-", "  ", ""},
		LineBottom: Line{"", "-", "  ", ""},
		HeaderRow:  Row{"", "  ", ""},
		DataRow:    Row{"", "  ", ""},
		Padding:    1,
	},
	"plain-nohead": {
		HeaderRow: Row{"", "  ", ""},
		DataRow:   Row{"", "  ", ""},
		Padding:   0,
	},
	"tab-nohead": {
		HeaderRow: Row{"", "\t", ""},
		DataRow:   Row{"", "\t", ""},
		Padding:   0,
	},
	"csv-nohead": {
		HeaderRow: Row{"", ",", ""},
		DataRow:   Row{"", ",", ""},
		Padding:   0,
	},
	"text-nohead": {
		HeaderRow: Row{"", " ", ""},
		DataRow:   Row{"", " ", ""},
		Padding:   0,
	},
	"mysql-nohead": {
		LineTop:    Line{"+", "-", "+", "+"},
		LineBottom: Line{"+", "-", "+", "+"},
		HeaderRow:  Row{"|", "|", "|"},
		DataRow:    Row{"|", "|", "|"},
		Padding:    1,
	},
	"mysqlg-nohead": {
		LineTop:    Line{"╒", "─", "╤", "╕"},
		LineBottom: Line{"└", "─", "┴", "┘"},
		HeaderRow:  Row{"│", "│", "│"},
		DataRow:    Row{"│", "│", "│"},
		Padding:    1,
	},
	"grid-nohead": {
		LineTop:         Line{"╒", "─", "╤", "╕"},
		LineBetweenRows: Line{"│", "─", "┼", "│"},
		LineBottom:      Line{"└", "─", "┴", "┘"},
		HeaderRow:       Row{"│", "│", "│"},
		DataRow:         Row{"│", "│", "│"},
		Padding:         1,
	},
	"gridt-nohead": {
		LineTop:         Line{"+", "-", "+", "+"},
		LineBetweenRows: Line{"+", "-", "+", "+"},
		LineBottom:      Line{"+", "-", "+", "+"},
		HeaderRow:       Row{"|", "|", "|"},
		DataRow:         Row{"|", "|", "|"},
		Padding:         1,
	},
	"markdown-nohead": {
		HeaderRow: Row{"| ", " | ", " |"},
		DataRow:   Row{"| ", " | ", " |"},
		Padding:   0,
	},
	"rst-nohead": {
		LineTop:    Line{"", "=", " ", ""},
		LineBottom: Line{"", "=", " ", ""},
		HeaderRow:  Row{"", "  ", ""},
		DataRow:    Row{"", "  ", ""},
		Padding:    1,
	},
}

TableFormats contains all available table format configurations. Users can define custom formats by adding entries to this map and calling Render.

Formats:

  • simple: Minimal ASCII table with dashes
  • plain: No borders, space-separated columns
  • tab: Tab-separated values (TSV)
  • text: Space-separated text (minimal padding)
  • csv: Comma-separated values
  • mysql: ASCII art grid styled like MySQL output
  • mysqlg: Unicode grid styled like MySQL with box drawing characters
  • grid: Full Unicode box drawing with lines between rows
  • gridt: Text-based grid with ASCII characters
  • markdown: Markdown table format
  • rst: reStructuredText table format
  • json: JSON array format
  • plus suffix "-nohead" variants that suppress headers

Functions

func ExcelOut added in v1.1.3

func ExcelOut(csvIn, sheetname, excelFile string) error

Take CSV formatted text (csvIn String) and print it out as an XLS file.

func PrintCol

func PrintCol(line, columns string, space bool) []string

func ShowFormats added in v1.1.3

func ShowFormats()

ShowFormats prints all available table formats to standard output.

Types

type CSVOut

type CSVOut struct {
	Text          string
	Render        string
	Columns       string
	RemEmptyLines bool
	NoHead        bool
	Align         string
	Wrap          bool
	Indent        string
	Delimeter     string
}

func NewCSVOut

func NewCSVOut() *CSVOut

func (*CSVOut) Table

func (csvout *CSVOut) Table() string

Table takes csv text and turns it into a table output

type HTMLConfig added in v1.2.10

type HTMLConfig struct {
	// TableClass is the CSS class(es) applied to the table element
	TableClass string
	// HeaderClass is the CSS class(es) applied to header cells
	HeaderClass string
	// RowClass is the CSS class(es) applied to data row <tr> elements
	RowClass string
	// CellClass is the CSS class(es) applied to data cells
	CellClass string
	// StripedRows applies alternating row colors when true
	StripedRows bool
	// Bordered adds borders to all cells when true
	Bordered bool
	// Condensed reduces padding for a more compact table
	Condensed bool
	// Hover highlights rows on hover
	Hover bool
	// ResponsiveWidth makes the table responsive to screen width
	ResponsiveWidth bool
	// CustomCSS contains custom CSS rules to include in the table
	CustomCSS string
	// BootstrapVersion specifies Bootstrap version (4, 5, or empty for no framework)
	BootstrapVersion string
	// UseBootstrapCDN determines whether to use CDN link (true) or embed CSS (false)
	// When false, Bootstrap CSS is embedded in the HTML for offline use
	UseBootstrapCDN bool
	// Title is an optional title displayed above the table
	Title string
}

HTMLConfig provides customizable options for HTML table rendering.

func DefaultHTMLConfig added in v1.2.10

func DefaultHTMLConfig() HTMLConfig

DefaultHTMLConfig returns a sensible default HTML configuration using Bootstrap 5.

By default, Bootstrap CSS is loaded from a CDN (Content Delivery Network) for smaller file sizes (~2KB). This assumes your users have internet access, which is reasonable for most modern web applications.

Configuration defaults:

  • Framework: Bootstrap 5
  • CSS Source: CDN links (jsdelivr)
  • File Size: ~2KB (CSS loaded externally)
  • Striped Rows: Enabled
  • Hover Effects: Enabled
  • Borders: Enabled
  • Theme: Primary header color

If users encounter rendering issues due to lack of internet, you can enable offline mode using SetHTMLOfflineMode() or OfflineHTMLConfig() to embed the CSS directly.

Example with default CDN mode:

table := gotabulate.Create(data)
table.SetHeaders([]string{"Name", "Value"})
html := table.Render("html")  // Small file, uses CDN

Example switching to offline mode:

table := gotabulate.Create(data)
table.SetHeaders([]string{"Name", "Value"})
table.SetHTMLOfflineMode()  // If needed for offline use
html := table.Render("html")  // Large file, self-contained

func MinimalHTMLConfig added in v1.2.10

func MinimalHTMLConfig() HTMLConfig

MinimalHTMLConfig returns a minimal HTML configuration with no framework dependencies. This is completely self-contained and works offline without any external resources. Useful if you don't want to depend on Bootstrap or CDN.

func OfflineHTMLConfig added in v1.2.10

func OfflineHTMLConfig() HTMLConfig

OfflineHTMLConfig returns an HTML configuration with fully embedded Bootstrap CSS.

This configuration embeds the complete Bootstrap 5 CSS directly in the HTML file, making it completely self-contained and usable without internet access. The resulting file is larger (~100KB) but requires no external resources.

Use this function or SetHTMLOfflineMode when generating HTML on systems that don't have internet access, such as backend servers, data processing systems, or air-gapped environments.

The HTML produced with this configuration can be:

  • Emailed as an attachment and opened anywhere
  • Saved to a file and opened later
  • Served by internal web applications
  • Archived for long-term storage
  • Used in offline or disconnected environments

Example:

config := gotabulate.OfflineHTMLConfig()
config.Title = "Offline Report"
table.SetHTMLConfig(config)
html := table.Render("html")

type Line

type Line struct {
	// contains filtered or unexported fields
}

Line represents a horizontal line element in a table.

type Row

type Row struct {
	// contains filtered or unexported fields
}

Row represents a row element in a table.

type TableFormat

type TableFormat struct {
	LineTop         Line
	LineBelowHeader Line
	LineBetweenRows Line
	LineBottom      Line
	HeaderRow       Row
	DataRow         Row
	Padding         int
	HeaderHide      bool
	FitScreen       bool
}

TableFormat defines the structure and styling of table output.

type Tabulate

type Tabulate struct {
	Data          []*TabulateRow
	Headers       []string
	FloatFormat   byte
	TableFormat   TableFormat
	Align         string
	EmptyVar      string
	HideLines     []string
	MaxSize       int
	WrapStrings   bool
	RemEmptyLines bool
	NoHeader      bool
	Index         bool
	HTMLConfig    HTMLConfig
}

Tabulate represents a data table with formatting options.

func Create

func Create(data interface{}) *Tabulate

Create creates a new Tabulate object from various data types. Accepts:

  • 2D String Array ([][]string)
  • 2D Int Array ([][]int)
  • 2D Int32 Array ([][]int32)
  • 2D Int64 Array ([][]int64)
  • 2D Bool Array ([][]bool)
  • 2D Float64 Array ([][]float64)
  • 2D Interface Array ([][]interface{})
  • 1D String Array ([]string)
  • 1D Interface Array ([]interface{})
  • Map[string][]interface{}
  • Map[string][]string

func (*Tabulate) Render

func (t *Tabulate) Render(format ...interface{}) string

Render formats the data table using the specified format. If no format is provided, uses the TableFormat set in the Tabulate struct. For HTML format, uses the HTMLConfig for customization.

func (*Tabulate) SetAlign

func (t *Tabulate) SetAlign(align string)

Set Align Type, Available options: left, right, center

func (*Tabulate) SetEmptyString

func (t *Tabulate) SetEmptyString(empty string)

Set how an empty cell will be represented

func (*Tabulate) SetFloatFormat

func (t *Tabulate) SetFloatFormat(format byte) *Tabulate

Set Float Formatting will be used in strconv.FormatFloat(element, format, -1, 64)

func (*Tabulate) SetHTMLBootstrap added in v1.2.10

func (t *Tabulate) SetHTMLBootstrap(version string)

SetHTMLBootstrap sets the Bootstrap version (4, 5, or empty for none).

func (*Tabulate) SetHTMLConfig added in v1.2.10

func (t *Tabulate) SetHTMLConfig(config HTMLConfig)

SetHTMLConfig sets a custom HTML configuration for table rendering.

func (*Tabulate) SetHTMLCustomCSS added in v1.2.10

func (t *Tabulate) SetHTMLCustomCSS(css string)

SetHTMLCustomCSS adds custom CSS to the HTML output.

func (*Tabulate) SetHTMLMinimal added in v1.2.10

func (t *Tabulate) SetHTMLMinimal()

SetHTMLMinimal uses minimal CSS styling without Bootstrap.

func (*Tabulate) SetHTMLOfflineMode added in v1.2.10

func (t *Tabulate) SetHTMLOfflineMode()

SetHTMLOfflineMode enables offline mode with fully embedded Bootstrap CSS.

By default, HTML generation uses CDN links for smaller file sizes (~2KB). Call SetHTMLOfflineMode to embed the complete Bootstrap 5 CSS directly in the HTML file for use on systems without internet access.

The resulting HTML file will be self-contained and larger (~100KB), but can be opened and viewed in any browser regardless of internet connectivity.

This is useful for:

  • Generating reports on backend servers without internet access
  • Creating portable HTML documents for email or file sharing
  • Archiving HTML reports that must work indefinitely
  • Serving tables in offline or air-gapped environments

Example:

table := gotabulate.Create(data)
table.SetHeaders([]string{"Name", "Value"})
table.SetHTMLOfflineMode()
html := table.Render("html")

func (*Tabulate) SetHTMLStyle added in v1.2.10

func (t *Tabulate) SetHTMLStyle(tableClass string)

SetHTMLStyle is a convenience method to set the HTML table class for styling.

func (*Tabulate) SetHTMLTitle added in v1.2.10

func (t *Tabulate) SetHTMLTitle(title string)

SetHTMLTitle sets an optional title for the HTML table.

func (*Tabulate) SetHTMLUseCDN added in v1.2.10

func (t *Tabulate) SetHTMLUseCDN(useCDN bool)

SetHTMLUseCDN configures whether Bootstrap CSS is loaded from CDN or embedded.

By default (true), Bootstrap is loaded from a CDN for smaller file sizes (~2KB). When set to false, the complete Bootstrap 5 CSS is embedded in the HTML (~100KB), making the file completely self-contained and usable without internet.

Parameters:

  • useCDN: true to use CDN (default, smaller files, requires internet)
  • useCDN: false to embed CSS (larger files, works offline)

See SetHTMLOfflineMode for a convenience method to enable offline mode.

func (*Tabulate) SetHeaders

func (t *Tabulate) SetHeaders(headers []string) *Tabulate

Set Headers of the table If Headers count is less than the data row count, the headers will be padded to the right

func (*Tabulate) SetHideLines

func (t *Tabulate) SetHideLines(hide []string)

Set which lines to hide. Can be: top - Top line of the table, belowheader - Line below the header, bottom - Bottom line of the table

func (*Tabulate) SetIndex added in v1.1.3

func (t *Tabulate) SetIndex(index bool)

set Index to automatically add a column for line number

func (*Tabulate) SetMaxCellSize

func (t *Tabulate) SetMaxCellSize(max int)

Sets the maximum size of cell If WrapStrings is set to true, then the string inside the cell will be split up into multiple cell

func (*Tabulate) SetNoHeader

func (t *Tabulate) SetNoHeader()

func (*Tabulate) SetRemEmptyLines

func (t *Tabulate) SetRemEmptyLines(remEmptyLines bool)

func (*Tabulate) SetWrapStrings

func (t *Tabulate) SetWrapStrings(wrap bool)

type TabulateRow

type TabulateRow struct {
	Elements   []string
	Continuous bool
}

TabulateRow represents a normalized row in a table.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址