-
-
Notifications
You must be signed in to change notification settings - Fork 24
/
xlsx.go
47 lines (39 loc) · 1.29 KB
/
xlsx.go
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
36
37
38
39
40
41
42
43
44
45
46
47
// Copyright (c) 2017 Andrey Gayvoronsky <[email protected]>
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package xlsx
import (
"github.com/plandem/ooxml"
//init enums for marshal/unmarshal
_ "github.com/plandem/xlsx/format/conditional"
_ "github.com/plandem/xlsx/format/conditional/rule"
_ "github.com/plandem/xlsx/format/styles"
_ "github.com/plandem/xlsx/internal/ml"
_ "github.com/plandem/xlsx/internal/ml/primitives"
_ "github.com/plandem/xlsx/types"
_ "github.com/plandem/xlsx/types/comment"
_ "github.com/plandem/xlsx/types/hyperlink"
_ "github.com/plandem/xlsx/types/options/column"
_ "github.com/plandem/xlsx/types/options/row"
_ "github.com/plandem/xlsx/types/options/sheet"
)
//Open opens a XLSX file with name or io.Reader
func Open(f interface{}) (*Spreadsheet, error) {
doc, err := ooxml.Open(f, newSpreadsheet)
if err != nil {
return nil, err
}
if xlDoc, ok := doc.(*Spreadsheet); ok {
return xlDoc, nil
}
return nil, ooxml.ErrorUnknownPackage(Spreadsheet{})
}
//New creates and returns a new XLSX document
func New() *Spreadsheet {
if doc, err := newSpreadsheet(ooxml.NewPackage(nil)); err == nil {
if xlDoc, ok := doc.(*Spreadsheet); ok {
return xlDoc
}
}
panic("Could not create a new XLSX document.")
}