export

package
v0.0.0-...-83b8ea0 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package export is part of the go-fastreport library, a pure Go port of FastReport .NET.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ByteToHex

func ByteToHex(b byte) string

ByteToHex converts a single byte to a two-character uppercase hex string. Matches C# ExportUtils.ByteToHex.

func ExcelCellRef

func ExcelCellRef(col, row int) string

ExcelCellRef returns an Excel cell reference like "A1" for the given zero-based column and 1-based row.

func ExcelColName

func ExcelColName(col int) string

ExcelColName converts a zero-based column index to an Excel column letter(s). 0→"A", 25→"Z", 26→"AA", etc.

func FloatToString

func FloatToString(value float64, digits int) string

FloatToString rounds value to digits decimal places and formats it with a dot decimal separator (invariant culture), matching C# ExportUtils.FloatToString.

func FormatFloat

func FormatFloat(v float64, decimals int, stripZeros bool) string

FormatFloat formats v with the given number of decimal places, stripping trailing zeros when stripZeros is true.

func GetColorFromFill

func GetColorFromFill(fill style.Fill) color.RGBA

GetColorFromFill extracts a representative colour from fill. Matches C# ExportUtils.GetColorFromFill.

func GetPageHeight

func GetPageHeight(page ReportPageDims) float32

GetPageHeight returns the printable height of page in millimetres. When IsUnlimitedHeight() is true the page has no fixed height; PaperHeight holds the accumulated content height set by the engine. Matches C# ExportUtils.GetPageHeight.

func GetPageWidth

func GetPageWidth(page ReportPageDims) float32

GetPageWidth returns the printable width of page in millimetres. Matches C# ExportUtils.GetPageWidth (UnlimitedWidth is not exposed in the Go port).

func GetRFCDate

func GetRFCDate(datetime time.Time) string

GetRFCDate formats datetime as an RFC 2822 / HTTP date string, replacing the "GMT" suffix with the local UTC offset when non-zero. Matches C# ExportUtils.GetRFCDate.

func HTMLColor

func HTMLColor(c color.RGBA) string

HTMLColor returns a CSS colour string for c. When alpha < 255 it returns an rgba() value; otherwise rgb(). Matches C# ExportUtils.HTMLColor.

func HTMLColorToRGB

func HTMLColorToRGB(s string) (r, g, b uint8, ok bool)

HTMLColorToRGB parses a CSS hex colour string (#RGB or #RRGGBB) and returns the r, g, b components. Returns (0,0,0) and false on parse error.

func HTMLString

func HTMLString(s string) string

HTMLString escapes s for safe inclusion in HTML text content. It replaces &, <, >, " and non-breaking space (0xa0).

func HtmlURL

func HtmlURL(value string) string

HtmlURL percent-encodes characters in value that are not safe in HTML URLs. Matches C# ExportUtils.HtmlURL (non-DOTNET_4 branch).

func InchesToPixels

func InchesToPixels(in float32) float32

InchesToPixels converts inches to pixels (96 dpi).

func MMToPixels

func MMToPixels(mm float32) float32

MMToPixels converts millimetres to pixels (at 96 dpi).

func ParsePageNumbers

func ParsePageNumbers(s string, totalPages int) ([]int, error)

ParsePageNumbers parses a page range string like "1,3-5,12" and returns the corresponding zero-based page indices (sorted, de-duplicated). totalPages is the total number of pages (used to resolve trailing "-" ranges). An empty string returns (nil, nil) — the caller should treat this as "all pages".

func PixelsToInches

func PixelsToInches(px float32) float32

PixelsToInches converts pixels (96 dpi) to inches.

func PixelsToMM

func PixelsToMM(px float32) float32

PixelsToMM converts pixels (at 96 dpi) to millimetres.

func PixelsToPoints

func PixelsToPoints(px float32) float32

PixelsToPoints converts pixels (96 dpi) to PostScript points (72 dpi).

func PointsToPixels

func PointsToPixels(pt float32) float32

PointsToPixels converts PostScript points to pixels (96 dpi).

func QuotedPrintable

func QuotedPrintable(values []byte) string

QuotedPrintable encodes values using Quoted-Printable (RFC 2045). Lines are soft-wrapped at 73 characters with "=\r\n". Matches C# ExportUtils.QuotedPrintable.

func RGBToHTMLColor

func RGBToHTMLColor(r, g, b uint8) string

RGBToHTMLColor returns a CSS hex colour string like "#RRGGBB".

func ReverseString

func ReverseString(str string) string

ReverseString returns str with its characters in reverse order. Matches C# ExportUtils.ReverseString.

func Round

func Round(v float64, places int) float64

Round rounds v to the given number of decimal places.

func XMLString

func XMLString(s string) string

XMLString escapes s for safe inclusion in XML text content. It escapes &, <, > and the control characters CR/LF/TAB.

Types

type ExportBase

type ExportBase struct {
	// PageRange controls which pages are included.
	PageRange PageRange

	// PageNumbers is a comma/range string like "1,3-5,12".
	// Used when PageRange == PageRangeCustom. Empty means all pages.
	PageNumbers string

	// CurPage is the 1-based page number to export when PageRange == PageRangeCurrent.
	CurPage int

	// Zoom is a scaling factor applied to the exported content (default 1.0).
	// Matches C# ExportBase.Zoom.
	Zoom float32

	// OnProgress is an optional callback invoked once per page during export.
	// It receives the current 1-based page number and the total page count.
	// This is the Go equivalent of C# ReportSettings.OnProgress (called from
	// ExportBase.Export for each page when ShowProgress is true).
	// C# ref: FastReport.Base/Export/ExportBase.cs, Export() method.
	OnProgress func(page, total int)

	// HasMultipleFiles indicates that this exporter produces multiple output files
	// (e.g. one per page). Mirrors C# ExportBase.HasMultipleFiles (line 149).
	HasMultipleFiles bool

	// ShiftNonExportable indicates that non-exportable bands should shift
	// subsequent bands up. Mirrors C# ExportBase.ShiftNonExportable (line 159).
	ShiftNonExportable bool
	// contains filtered or unexported fields
}

ExportBase is the base for all export filters. Concrete exporters embed ExportBase and override the hook methods.

Usage:

type MyExport struct { export.ExportBase }
func (m *MyExport) ExportBand(band *preview.PreparedBand) { ... }
func (m *MyExport) Export(pages *preview.PreparedPages, w io.Writer) error {
    return m.ExportBase.Export(pages, w, m)
}

func NewExportBase

func NewExportBase() ExportBase

NewExportBase creates an ExportBase with sensible defaults.

func (*ExportBase) AddGeneratedFile

func (e *ExportBase) AddGeneratedFile(path string)

AddGeneratedFile appends path to the generated files list.

func (*ExportBase) CreateTempFile

func (e *ExportBase) CreateTempFile() (*os.File, error)

CreateTempFile creates a new temporary file in the OS temp directory under a "TempExport" subdirectory. The file is tracked and deleted by DeleteTempFiles. Matches C# ExportBase.CreateTempFile.

func (*ExportBase) DeleteTempFiles

func (e *ExportBase) DeleteTempFiles()

DeleteTempFiles closes and removes all temporary files created via CreateTempFile. Matches C# ExportBase.DeleteTempFiles.

func (*ExportBase) Deserialize

func (e *ExportBase) Deserialize(r report.Reader)

Deserialize reads ExportBase settings from r. Mirrors C# ExportBase.Deserialize (ExportBase.cs).

func (*ExportBase) Export

func (e *ExportBase) Export(pages *preview.PreparedPages, w io.Writer, exp Exporter) error

Export drives the export lifecycle. pages is the PreparedPages produced by the report engine. w is the output writer (available to the concrete exporter via its own field). exp is the concrete exporter — typically the struct that embeds ExportBase.

func (*ExportBase) ExportAndZip

func (e *ExportBase) ExportAndZip(pages *preview.PreparedPages, fileName string, exp Exporter, w io.Writer) error

ExportAndZip exports pages to a temporary file, packages the file into a ZIP archive, and writes the archive to w. fileName is used as the entry name inside the ZIP (e.g. "report.html").

This mirrors the C# ExportBase.ExportAndZip(Report, Stream) pattern:

  1. Create a temp directory.
  2. Export to a file inside the temp dir using ExportToFile.
  3. Zip the file into a ZIP archive.
  4. Write the archive to w.
  5. Clean up the temp dir.

C# reference: ExportBase.cs ExportAndZip lines 598-614.

func (*ExportBase) ExportToFile

func (e *ExportBase) ExportToFile(pages *preview.PreparedPages, path string, exp Exporter) error

ExportToFile exports pages using exp, writing the output to the given file path. The file is created (or truncated) before calling Export, and closed on return. This mirrors the C# ExportBase.Export(Report, string fileName) convenience overload.

C# reference: ExportBase.cs Export(Report, string fileName) lines 577-585.

func (*ExportBase) GeneratedFiles

func (e *ExportBase) GeneratedFiles() []string

GeneratedFiles returns the list of output file paths produced by this export. Matches C# ExportBase.GeneratedFiles.

func (*ExportBase) Pages

func (e *ExportBase) Pages() []int

Pages returns the resolved zero-based page indices (populated after Export).

func (*ExportBase) Serialize

func (e *ExportBase) Serialize(w report.Writer)

Serialize writes non-default ExportBase settings to w. Mirrors C# ExportBase.Serialize (ExportBase.cs line 378).

type ExportFormat

type ExportFormat string

ExportFormat identifies a known output format by name (case-insensitive). Examples: "PDF", "HTML", "Image".

const (
	ExportFormatPDF   ExportFormat = "PDF"
	ExportFormatHTML  ExportFormat = "HTML"
	ExportFormatImage ExportFormat = "Image"
)

type Exporter

type Exporter interface {
	// Start is called once before any pages are exported.
	Start() error
	// ExportPageBegin is called at the start of each page.
	ExportPageBegin(page *preview.PreparedPage) error
	// ExportBand is called for each band on the page.
	ExportBand(band *preview.PreparedBand) error
	// ExportPageEnd is called at the end of each page.
	ExportPageEnd(page *preview.PreparedPage) error
	// Finish is called once after all pages are exported.
	Finish() error
}

Exporter is the interface that concrete export filters implement. ExportBase.Export calls these hooks in order for each page/band.

type ExportsOptions

type ExportsOptions struct {
	// AllowedExports lists the export formats the user is allowed to choose.
	// An empty slice means all formats are allowed.
	AllowedExports []ExportFormat

	// HideExports lists export formats that should be hidden from the UI even
	// if they are technically available.
	HideExports []ExportFormat

	// DefaultFormat is the pre-selected format when the user opens the export dialog.
	DefaultFormat ExportFormat

	// ShowProgress controls whether a progress indicator is shown during export.
	ShowProgress bool

	// OpenAfterExport controls whether the exported file is opened automatically.
	OpenAfterExport bool
}

ExportsOptions holds report-level export configuration. It is the Go equivalent of FastReport.Utils.ExportsOptions.

AllowedExports and HideExports control which formats appear in the UI; DefaultFormat selects the pre-selected format in a dialog. These fields are advisory for host applications that present an export UI — the programmatic export API does not enforce them.

func NewExportsOptions

func NewExportsOptions() *ExportsOptions

NewExportsOptions returns ExportsOptions with sensible defaults.

func (*ExportsOptions) Deserialize

func (o *ExportsOptions) Deserialize(r report.Reader)

Deserialize reads ExportsOptions properties.

func (*ExportsOptions) IsAllowed

func (o *ExportsOptions) IsAllowed(format ExportFormat) bool

IsAllowed returns true if format is in the AllowedExports list (or the list is empty).

func (*ExportsOptions) IsHidden

func (o *ExportsOptions) IsHidden(format ExportFormat) bool

IsHidden returns true if format is in the HideExports list.

func (*ExportsOptions) Serialize

func (o *ExportsOptions) Serialize(w report.Writer)

Serialize writes ExportsOptions properties that differ from defaults.

type NoopExporter

type NoopExporter struct{}

NoopExporter is an Exporter with empty hook implementations. Embed it in concrete exporters to avoid implementing unused hooks.

func (NoopExporter) ExportBand

func (NoopExporter) ExportBand(*preview.PreparedBand) error

func (NoopExporter) ExportPageBegin

func (NoopExporter) ExportPageBegin(*preview.PreparedPage) error

func (NoopExporter) ExportPageEnd

func (NoopExporter) ExportPageEnd(*preview.PreparedPage) error

func (NoopExporter) Finish

func (NoopExporter) Finish() error

func (NoopExporter) Start

func (NoopExporter) Start() error

type PageRange

type PageRange int

PageRange controls which pages are exported.

const (
	// PageRangeAll exports all pages (default).
	PageRangeAll PageRange = iota
	// PageRangeCurrent exports only the current page (set via CurPage).
	PageRangeCurrent
	// PageRangeCustom exports the pages specified by PageNumbers.
	PageRangeCustom
)

type ReportPageDims

type ReportPageDims interface {
	GetPaperWidth() float32
	GetPaperHeight() float32
	IsUnlimitedHeight() bool
}

ReportPageDims is a minimal interface that both *reportpkg.ReportPage and any test stub must satisfy. It avoids an import cycle between export and reportpkg.

Directories

Path Synopsis
Package csv implements a CSV export filter for go-fastreport.
Package csv implements a CSV export filter for go-fastreport.
Package html is part of the go-fastreport library, a pure Go port of FastReport .NET.
Package html is part of the go-fastreport library, a pure Go port of FastReport .NET.
Package image provides PNG image export for go-fastreport.
Package image provides PNG image export for go-fastreport.
pdf
Package pdf is part of the go-fastreport library, a pure Go port of FastReport .NET.
Package pdf is part of the go-fastreport library, a pure Go port of FastReport .NET.
core
Package core is part of the go-fastreport library, a pure Go port of FastReport .NET.
Package core is part of the go-fastreport library, a pure Go port of FastReport .NET.
Package rtf implements an RTF export filter for go-fastreport.
Package rtf implements an RTF export filter for go-fastreport.
Package svg implements an SVG export filter for go-fastreport.
Package svg implements an SVG export filter for go-fastreport.
Package xlsx implements an Excel XLSX export filter for go-fastreport.
Package xlsx implements an Excel XLSX export filter for go-fastreport.

Jump to

Keyboard shortcuts

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