Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/aswjh/excel
read and write excel files in go/golang
https://github.com/aswjh/excel
excel go golang ole
Last synced: 3 months ago
JSON representation
read and write excel files in go/golang
- Host: GitHub
- URL: https://github.com/aswjh/excel
- Owner: aswjh
- License: bsd-2-clause
- Created: 2014-09-21T06:52:32.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2019-03-02T03:15:59.000Z (over 5 years ago)
- Last Synced: 2024-07-16T14:02:54.563Z (4 months ago)
- Topics: excel, go, golang, ole
- Language: Go
- Homepage:
- Size: 57.6 KB
- Stars: 84
- Watchers: 3
- Forks: 25
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# excel for golang
read and write excel files in golang.
go语言读写excel文件.
# dependency
[github.com/go-ole/go-ole][ole]
# install
go get github.com/aswjh/excel
# example
``` go
package mainimport (
"runtime"
"fmt"
"time"
"github.com/aswjh/excel"
)func main() {
runtime.GOMAXPROCS(1)
option := excel.Option{"Visible": true, "DisplayAlerts": true, "ScreenUpdating": true}
xl, _ := excel.New(option) //xl, _ := excel.Open("test_excel.xls", option)
defer xl.Quit()sheet, _ := xl.Sheet(1) //xl.Sheet("sheet1")
defer sheet.Release()
sheet.Cells(1, 1, "hello")
sheet.PutCell(1, 2, 2006)
sheet.MustCells(1, 3, 3.14159)cell := sheet.Cell(5, 6)
defer cell.Release()
cell.Put("go")
cell.Put("font", map[string]interface{}{"name": "Arial", "size": 26, "bold": true})
cell.Put("interior", "colorindex", 6)sheet.PutRange("a3:c3", []string {"@1", "@2", "@3"})
rg := sheet.Range("d3:f3")
defer rg.Release()
rg.Put([]string {"~4", "~5", "~6"})urc := sheet.MustGet("UsedRange", "Rows", "Count").(int32)
println("str:"+sheet.MustCells(1, 2), sheet.MustGetCell(1, 2).(float64), cell.MustGet().(string), urc)cnt := 0
sheet.ReadRow("A", 1, "F", 9, func(row []interface{}) (rc int) { //"A", 1 or 1, 9 or 1 or nothing
cnt ++
fmt.Println(cnt, row)
return //-1: break
})time.Sleep(2000000000)
//Sort
cells := excel.GetIDispatch(sheet, "Cells")
cells.CallMethod("UnMerge")
sort := excel.GetIDispatch(sheet, "Sort")
sortfields := excel.GetIDispatch(sort, "SortFields")
sortfields.CallMethod("Clear")
sortfields.CallMethod("Add", sheet.Range("f:f").IDispatch, 0, 2)
sort.CallMethod("SetRange", cells)
sort.PutProperty("Header", 1)
sort.CallMethod("Apply")//Chart
shapes := excel.GetIDispatch(sheet, "Shapes")
_chart, _ := shapes.CallMethod("AddChart", 65)
chart := _chart.ToIDispatch()
chart.CallMethod("SetSourceData", sheet.Range("a1:c3").IDispatch)//AutoFilter
cells.CallMethod("AutoFilter")
excel.Release(sortfields, sort, cells, chart, shapes)time.Sleep(3000000000)
xl.SaveAs("test_excel.xls") //xl.SaveAs("test_excel", "html")
}```
# license
The [BSD 3-Clause license][bsd]
[ole]: http://github.com/go-ole/go-ole
[bsd]: http://opensource.org/licenses/BSD-3-Clause