dongxingguo1978 2014-08-25 22:43
浏览 54

在Go中编写现有的Excel文件

There's any way to write on an existing Excel file in Go?, i've tried with some libraries that are basically to create the excel file from blank but i need to write on an existing file.

Any help is appreciated, Thanks.

UPDATE Using the excel package @Marc recommended, i got this error:

panic: Ocurrió una excepción.

goroutine 16 [running]:
runtime.panic(0x4afb40, 0xc082000440)
    c:/go/src/pkg/runtime/panic.c:279 +0x11f
github.com/mattn/go-ole/oleutil.MustCallMethod(0x1cf688, 0x4eb870, 0x4, 0x2e3e38, 0x3, 0x3, 0xc082007080)
    C:/Go/path/src/github.com/mattn/go-ole/oleutil/oleutil.go:58 +0xdd
github.com/nivrrex/excel.(*Excel).Open(0x2e3f08, 0x4f3d70, 0x9, 0x0, 0x0, 0x0)
    C:/Go/path/src/github.com/nivrrex/excel/excel.go:65 +0x582
main.main()
    C:/Desarrollo/Projects/excel_writer_go/excel_writer.go:12 +0xa0

goroutine 19 [finalizer wait]:
runtime.park(0x414d40, 0x576c00, 0x575649)
    c:/go/src/pkg/runtime/proc.c:1369 +0xac
runtime.parkunlock(0x576c00, 0x575649)
    c:/go/src/pkg/runtime/proc.c:1385 +0x42
runfinq()
    c:/go/src/pkg/runtime/mgc0.c:2644 +0xdd
runtime.goexit()
    c:/go/src/pkg/runtime/proc.c:1445
exit status 2
[Finished in 4.4s with exit code 1]
[cmd: go build C:\Desarrollo\Projects\excel_writer_go\excel_writer.go & go run C:\Desarrollo\Projects\excel_writer_go\excel_writer.go]
[dir: C:\Desarrollo\Projects\excel_writer_go]
[path: C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Go\bin]

CODE This is the code i tried to use.

package main

import (
    "fmt"
    "github.com/nivrrex/excel"
)

func main() {

    e := &excel.Excel{Visible: false, Readonly: false, Saved: true}
    filePath := "test.xlsx"
    e.Open(filePath)

    //Print
    fmt.Println(e.Cells(1, 1))
    e.Sheet(1)
    e.CellsWrite("Hello", 2, 2)
    e.Save()
    e.Close()

}
  • 写回答

2条回答 默认 最新

  • ds0409 2014-08-25 23:20
    关注

    You should have a look at this package, which is built on top of the ole bindings for go that can be found here

    The CellsWrite function should do what you want:

    func (this *Excel) CellsWrite(value string, row int, column int) (err error)
    
    评论

报告相同问题?

悬赏问题

  • ¥20 java在应用程序里获取不到扬声器设备
  • ¥15 echarts动画效果的问题,请帮我添加一个动画。不要机器人回答。
  • ¥60 许可证msc licensing软件报错显示已有相同版本软件,但是下一步显示无法读取日志目录。
  • ¥15 Attention is all you need 的代码运行
  • ¥15 一个服务器已经有一个系统了如果用usb再装一个系统,原来的系统会被覆盖掉吗
  • ¥15 使用esm_msa1_t12_100M_UR50S蛋白质语言模型进行零样本预测时,终端显示出了sequence handled的进度条,但是并不出结果就自动终止回到命令提示行了是怎么回事:
  • ¥15 前置放大电路与功率放大电路相连放大倍数出现问题
  • ¥80 部署运行web自动化项目
  • ¥15 腾讯云如何建立同一个项目中物模型之间的联系
  • ¥30 VMware 云桌面水印如何添加