eexcel

package module
v0.0.0-...-f16a000 Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2021 License: MIT Imports: 6 Imported by: 0

README

go-eexcel

go-eexcel implements encoding and decoding of XLSX like encoding/json

Usage

func ExampleMarshal() {
	type st struct {
		Name   string `eexcel:"name"`
		Number int    `eexcel:"number"`
	}

	input := st{
		Name:   "go-eexcel",
		Number: 123456,
	}
	b, _ := Marshal(input)

	if false {
		// Save to file
		ioutil.WriteFile("out.xlsx", b, 0666)
	}

	xlsx, _ := excelize.OpenReader(bytes.NewReader(b))
	rows := xlsx.GetRows(DefaultSheetName)

	for _, row := range rows {
		fmt.Printf("%s\n", strings.Join(row, "	"))
	}

	// Output:
	// key	value
	// name	go-eexcel
	// number	123456
}
func ExampleUnmarshal() {
	type testStruct struct {
		A string `eexcel:"AAA"`
		B int    `eexcel:"BBB"`
	}
	output := testStruct{}

	b, _ := ioutil.ReadFile("testdata/test.xlsx")
	Unmarshal(b, &output)

	fmt.Printf("A : %q\n", output.A)
	fmt.Printf("B : %d\n", output.B)

	// Output:
	// A : "aaa"
	// B : 222
}

License

MIT

Author

sago35 - sago35@gmail.com

Documentation

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	DefaultSheetName = "defines"
)

Functions

func Marshal

func Marshal(v interface{}) ([]byte, error)
Example
type st struct {
	Name   string `eexcel:"name"`
	Number int    `eexcel:"number"`
}

input := st{
	Name:   "go-eexcel",
	Number: 123456,
}
b, _ := Marshal(input)

if false {
	// Save to file
	ioutil.WriteFile("out.xlsx", b, 0666)
}

xlsx, _ := excelize.OpenReader(bytes.NewReader(b))
rows := xlsx.GetRows(DefaultSheetName)

for _, row := range rows {
	fmt.Printf("%s\n", strings.Join(row, "	"))
}
Output:
key	value
name	go-eexcel
number	123456

func Unmarshal

func Unmarshal(data []byte, v interface{}) error
Example
type testStruct struct {
	A string `eexcel:"AAA"`
	B int    `eexcel:"BBB"`
}
output := testStruct{}

b, _ := ioutil.ReadFile("testdata/test.xlsx")
Unmarshal(b, &output)

fmt.Printf("A : %q\n", output.A)
fmt.Printf("B : %d\n", output.B)
Output:
A : "aaa"
B : 222

Types

This section is empty.

Jump to

Keyboard shortcuts

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