1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
|
package xlsx
import "fmt"
func ExampleRow_ReadStruct() {
//example type
type structTest struct {
IntVal int `xlsx:"0"`
StringVal string `xlsx:"1"`
FloatVal float64 `xlsx:"2"`
IgnoredVal int `xlsx:"-"`
BoolVal bool `xlsx:"4"`
}
structVal := structTest{
IntVal: 16,
StringVal: "heyheyhey :)!",
FloatVal: 3.14159216,
IgnoredVal: 7,
BoolVal: true,
}
//create a new xlsx file and write a struct
//in a new row
f := NewFile()
sheet, _ := f.AddSheet("TestRead")
row := sheet.AddRow()
row.WriteStruct(&structVal, -1)
//read the struct from the same row
readStruct := &structTest{}
err := row.ReadStruct(readStruct)
if err != nil {
panic(err)
}
fmt.Println(readStruct)
}
|