Documentation
¶
Index ¶
- Constants
- Variables
- func DisableDownloadHeaders(h http.Header)
- func EnableDownloadHeaders(h http.Header)
- func ReadMarkdownTableDetailed(r io.Reader) (Table, []MarkdownAlign, error)
- func ReadXLSToMaps(r io.Reader) ([]map[string]string, error)
- func TrimTrailingFinalNewline(b []byte) []byte
- func WriteAttachment(w http.ResponseWriter, fileName, contentType string, body io.Reader, ...) error
- func WriteCSV(w io.Writer, tab Table, delimiter, enclosure string, encodingFrom string, ...) error
- func WriteMarkdownTable(w io.Writer, tab Table) error
- func WriteMarkdownTableWith(w io.Writer, tab Table, opts MarkdownMarshalOpts) error
- func WriteXLS(w io.Writer, tab Table, detectHead bool) error
- func WriteXLSX(w io.Writer, tab Table, detectHead bool) error
- type MarkdownAlign
- type MarkdownMarshalOpts
- type Table
Constants ¶
const ( TypeCSV = "csv" TypeXLS = "xls" TypeXLSX = "xlsx" )
Format identifiers for helpers and documentation.
const ( XLSIntType = 0x203 XLSStringType = 0x204 )
BIFF legacy cell record types (binary .xls subset).
const ( ContentTypeCSV = "text/csv;charset=UTF-16LE" ContentTypeXLS = "application/vnd.ms-excel" ContentTypeXLSX = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" )
MIME-style content types for tabular downloads.
const Version = "1.0.0"
Version is the release version of this module (semantic versioning). Keep it in sync with the git tag when publishing (e.g. tag v1.0.0 → Version "1.0.0").
Variables ¶
var ( // ErrOLEWorkbook means the input is an OLE compound document (.xls as produced by Excel 97). // [ReadXLS] only supports the linear BIFF stream from [WriteXLS]; use another tool or convert to .xlsx. ErrOLEWorkbook = errors.New("xls: OLE compound workbook not supported (linear BIFF stream only)") // ErrTruncatedXLS means the stream ended inside a BIFF record. ErrTruncatedXLS = errors.New("xls: truncated record") )
Functions ¶
func DisableDownloadHeaders ¶
DisableDownloadHeaders removes cache headers added by EnableDownloadHeaders.
func EnableDownloadHeaders ¶
EnableDownloadHeaders sets Cache-Control, Pragma, and Expires for attachment responses.
func ReadMarkdownTableDetailed ¶ added in v1.0.0
func ReadMarkdownTableDetailed(r io.Reader) (Table, []MarkdownAlign, error)
ReadMarkdownTableDetailed is like ReadMarkdownTable but also returns column alignment from the divider row (for round-tripping with WriteMarkdownTableWith).
func ReadXLSToMaps ¶ added in v1.0.0
ReadXLSToMaps reads r like ReadXLS with a header row and returns one map per data row. Duplicate header names: later columns overwrite earlier keys in each map.
func TrimTrailingFinalNewline ¶
TrimTrailingFinalNewline removes one trailing UTF-16LE newline (after BOM) from b if present.
func WriteAttachment ¶
func WriteAttachment(w http.ResponseWriter, fileName, contentType string, body io.Reader, size int64, enableDownload bool) error
WriteAttachment sets Content-Type, Content-Disposition, optional Content-Length, optional download cache headers, then copies body into w.
If size >= 0, Content-Length is set to size. If size < 0, Content-Length is omitted (chunked transfer).
func WriteCSV ¶ added in v1.0.0
func WriteCSV(w io.Writer, tab Table, delimiter, enclosure string, encodingFrom string, detectHead bool) error
WriteCSV writes UTF-16LE CSV with a BOM and a leading sep= line. Cell text must be UTF-8; encodingFrom is reserved (only UTF-8 is supported today).
func WriteMarkdownTable ¶ added in v1.0.0
WriteMarkdownTable writes a GitHub-flavored markdown pipe table to w. The header row uses Table.Columns (after [normalizeTable] if columns were empty).
func WriteMarkdownTableWith ¶ added in v1.0.0
func WriteMarkdownTableWith(w io.Writer, tab Table, opts MarkdownMarshalOpts) error
WriteMarkdownTableWith writes a markdown pipe table to w with optional column alignment.
Types ¶
type MarkdownAlign ¶ added in v1.0.0
type MarkdownAlign int
MarkdownAlign is column alignment in a GitHub-style pipe table divider row.
const ( AlignLeft MarkdownAlign = iota AlignCenter AlignRight )
type MarkdownMarshalOpts ¶ added in v1.0.0
type MarkdownMarshalOpts struct {
// Align is per-column alignment (shorter slice defaults remaining columns to left).
Align []MarkdownAlign
}
MarkdownMarshalOpts controls markdown table output from WriteMarkdownTableWith.
type Table ¶
Table is column-ordered tabular data. Columns defines order and names; each Rows[i] may be shorter than len(Columns) (missing cells are empty). If Columns is nil or empty, synthetic names "0","1",… are derived from the widest row.
func ReadMarkdownTable ¶ added in v1.0.0
ReadMarkdownTable parses the first GitHub-style pipe table from r (header + divider + body rows). Prose before the first header+divider pair is skipped.
func ReadXLS ¶ added in v1.0.0
ReadXLS reads a legacy .xls linear BIFF stream from r. It is not a full OLE workbook parser; inputs starting with the OLE signature return ErrOLEWorkbook.
When firstRowAsHeader is true, row 0 becomes Table.Columns and following rows Table.Rows. When false, columns are named "0","1",… (widest row) and every grid row is in Table.Rows.