https://github.com/devlights/goxcel
Goxcel is a library to operate MS Excel using go-ole library.
https://github.com/devlights/goxcel
excel go golang win32com windows
Last synced: 6 months ago
JSON representation
Goxcel is a library to operate MS Excel using go-ole library.
- Host: GitHub
- URL: https://github.com/devlights/goxcel
- Owner: devlights
- License: mit
- Created: 2020-02-05T10:43:58.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2024-09-04T09:26:10.000Z (over 1 year ago)
- Last Synced: 2025-02-28T02:35:04.111Z (11 months ago)
- Topics: excel, go, golang, win32com, windows
- Language: Go
- Homepage:
- Size: 187 KB
- Stars: 16
- Watchers: 3
- Forks: 4
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Goxcel
Goxcel is a library to operate Excel using [go-ole](https://github.com/go-ole/go-ole) package. Thanks [go-ole](https://github.com/go-ole/go-ole) package!
This library works only on Windows.
[](https://www.codefactor.io/repository/github/devlights/goxcel)

[](https://pkg.go.dev/github.com/devlights/goxcel)
## Install
```sh
go get github.com/devlights/goxcel@latest
```
## Usage
### Import statement
```go
package main
import (
"github.com/devlights/goxcel"
)
func init() {
log.SetFlags(0)
}
// main is entry point of this app.
func main() {
ret, xlsx := run()
if ret == 0 {
// Launch EXCEL
_ = exec.Command("cmd", "/C", xlsx).Run()
}
os.Exit(ret)
}
func run() (int, string) {
// 0. Initialize Goxcel
quit := goxcel.MustInitGoxcel()
defer quit()
// 1. Create new Goxcel instance.
excel, release := goxcel.MustNewGoxcel()
// must call goxcel release function when function exited
// otherwise excel process was remained.
defer release()
// optional settings
visible := false
excel.MustSilent(visible)
// 2. Get Workbooks instance.
wbs := excel.MustWorkbooks()
// 3. Add Workbook
wb, wbRelease := wbs.MustAdd()
// call workbook's release function
defer wbRelease()
// 4. Get Worksheet
ws := wb.MustSheets(1)
// 5. Get Cell
c := ws.MustCells(1, 1)
// 6. Set the value to cell
c.MustSetValue("こんにちはWorld")
p := filepath.Join(os.TempDir(), "helloworld.xlsx")
log.Printf("SAVE FILE: %s\n", p)
// 7. Save
wb.MustSaveAs(p)
// Workbook::SetSaved(true) and Workbook::Close() is automatically called when `defer wbReleaseFn()`.
// Excel::Quit() and Excel::Release() is automatically called when `defer release()`.
return 0, p
}
```
Also look at the "examples" directory :)