excel_mapper

package module
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2025 License: MIT Imports: 12 Imported by: 0

README

📊 excel_mapper

Go Reference

A reusable Go package to map, transform, and transfer data between Excel files — with support for direct column mappings, derived (computed) mappings, and raw formula-based transformations.
Mappings can also be stored and retrieved from MongoDB for reuse or sharing.


🚀 Features

  • Initialize and parse Excel files (.xlsx)
  • Direct column-to-column mappings
  • Derived mappings using custom transform functions
  • Raw calculations (formula-based)
  • MongoDB integration for persistent mapping storage
  • Extensible design for future storage backends

🧩 Installation

go get github.com/siddhantadhav/excel_mapper

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ColIndex

func ColIndex(name string, f *File) int

func CreateIndex

func CreateIndex(ctx context.Context, collection *mongo.Collection) error

func EvalFormula

func EvalFormula(formula string, sources []string, row []string, f *File) any

func FillFile

func FillFile(fileA, fileB *File, mappings []ColumnMapping) error

func ParseFloatSafe

func ParseFloatSafe(v string) float64

func SaveMapping

func SaveMapping(ctx context.Context, collection *mongo.Collection, document *MappingStorage) (*mongo.InsertOneResult, error)

Types

type ColumnMapping

type ColumnMapping struct {
	Target    string
	Source    []string
	Transform MappingFunc
	Formula   string
	Params    map[string]any
	Default   any
}

ColumnMapping represents a mapping rule

func (*ColumnMapping) ToDBMapping

func (m *ColumnMapping) ToDBMapping() DBColumnMapping

type DBColumnMapping

type DBColumnMapping struct {
	Target    string         `bson:"target" json:"target"`
	Source    []string       `bson:"source" json:"source"`
	Transform string         `bson:"transform" json:"transform"`
	Formula   string         `bson:"formula,omitempty" json:"formula,omitempty"`
	Params    map[string]any `bson:"params,omitempty" json:"params,omitempty"`
	Default   any            `bson:"default,omitempty" json:"default,omitempty"`
	Unique    bool           `bson:"unique,omitempty" json:"unique,omitempty"`
}

func (*DBColumnMapping) ToColumnMapping

func (dbMap *DBColumnMapping) ToColumnMapping() ColumnMapping

type File

type File struct {
	Path string
	Name string
	Col  []string
}

func InitFile

func InitFile(dir, name string) (*File, error)

type FileIndex

type FileIndex struct {
	ColMap map[string]int
	File   *File
}

func NewFileIndex

func NewFileIndex(f *File) *FileIndex

type MappingFunc

type MappingFunc func(row []string, fA *File) any

MappingFunc generates a value for a FileB column

func AverageColumns

func AverageColumns(cols ...string) MappingFunc

func ConcatColumns

func ConcatColumns(sep string, cols ...string) MappingFunc

func Count added in v1.2.0

func Count(sources ...string) MappingFunc

func SumColumns

func SumColumns(cols ...string) MappingFunc

func Unique added in v1.2.0

func Unique(sourceCol string) MappingFunc

type MappingStorage

type MappingStorage struct {
	UniqueId string            `bson:"unique_id" json:"unique_id"`
	Mappings []DBColumnMapping `bson:"mappings" json:"mappings"`
}

func LoadMapping

func LoadMapping(ctx context.Context, collection *mongo.Collection, uniqueId string) (*MappingStorage, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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