Documentation
¶
Overview ¶
Package csv implements a CSV export filter for go-fastreport. It extracts tabular text data from prepared pages, grouping objects by their Y coordinate (row) and sorting each row left-to-right by X. One CSV row is written per band row; non-text objects are skipped.
Index ¶
- type Exporter
- func (e *Exporter) Export(pages *preview.PreparedPages, w io.Writer) error
- func (e *Exporter) ExportBand(b *preview.PreparedBand) error
- func (e *Exporter) ExportPageBegin(_ *preview.PreparedPage) error
- func (e *Exporter) ExportPageEnd(_ *preview.PreparedPage) error
- func (e *Exporter) FileExtension() string
- func (e *Exporter) Finish() error
- func (e *Exporter) Name() string
- func (e *Exporter) Start() error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Exporter ¶
type Exporter struct {
export.ExportBase
// Separator is the CSV field delimiter (default ',').
Separator rune
// Quote is the CSV quoting character (default '"').
Quote rune
// HeaderRow controls whether a header row with band and object names
// is emitted before data rows (default true).
HeaderRow bool
// contains filtered or unexported fields
}
Exporter produces CSV output from a PreparedPages collection.
Each band row in the prepared pages becomes one CSV row. Objects within a band are grouped by their Y coordinate and then sorted left-to-right by X coordinate to produce column order. Only text-bearing objects (ObjectTypeText, ObjectTypeHtml, ObjectTypeRTF, ObjectTypeCheckBox) are emitted; all other object types are skipped.
func NewExporter ¶
func NewExporter() *Exporter
NewExporter creates an Exporter with sensible defaults.
func (*Exporter) ExportBand ¶
func (e *Exporter) ExportBand(b *preview.PreparedBand) error
ExportBand converts a single band into one or more CSV rows.
Strategy:
- Collect all text objects from the band.
- Group them by Y coordinate (with a small epsilon tolerance so objects that differ by less than 1 pixel are treated as the same row).
- Within each Y-group sort by X (left-to-right).
- Emit one CSV row per Y-group.
func (*Exporter) ExportPageBegin ¶
func (e *Exporter) ExportPageBegin(_ *preview.PreparedPage) error
ExportPageBegin is a no-op for CSV (pages are transparent to the format).
func (*Exporter) ExportPageEnd ¶
func (e *Exporter) ExportPageEnd(_ *preview.PreparedPage) error
ExportPageEnd is a no-op for CSV.
func (*Exporter) FileExtension ¶
FileExtension returns the recommended file extension.
func (*Exporter) Finish ¶
Finish flushes the CSV writer. When HeaderRow is true, it first writes the header then all accumulated rows.