XLSX updating

1,204 views
Skip to first unread message

Geoff Teale

unread,
Apr 10, 2012, 1:43:58 AM4/10/12
to golan...@googlegroups.com
Hi,

Now Go 1 is finally with us I have decided to resume work on my little Go projects.  To that end I just spent a happy couple of hours bringing XLSX, a little package for reading Microsoft Excel files up to scratch for Go 1.  

Just looking on github I noticed there are forks that people are working on - one in particular trying to make it possible to write XLSX files  - I can't contact those people via github, but if they are on this list I just want to say please feel free to submit pull requests, I am very happy to receive any input. 

Great work on Go 1 everyone!

Regards,
Geoff Teale

gauravk

unread,
Apr 10, 2012, 9:51:25 AM4/10/12
to golan...@googlegroups.com
Great news.
Would you like to share the 'go get <url>' for your project?

Thanks

Geoffrey Teale

unread,
Apr 10, 2012, 9:59:39 AM4/10/12
to gauravk, golang-nuts
On 10 April 2012 15:51, gauravk <gaurav...@gmail.com> wrote:
Great news.
Would you like to share the 'go get <url>' for your project?



My pleasure!  


--
Geoff Teale 

gauravk

unread,
Apr 10, 2012, 10:41:21 AM4/10/12
to golan...@googlegroups.com, gauravk
Thanks, I will try this package.

Hill

unread,
Apr 11, 2012, 9:54:27 AM4/11/12
to golang-nuts
Hi Teale,
Thanks for writing these code, i learned a lot of things from it.
From the README, i saw you didn't have a plan to support write the
excel,
so i forked one branch from your lib, and was trying to make it write
 something to the excel.
Currently it can open a exist workbook and write data to the exist
sheet.
but can't create new workbook, or add new sheet to a workbook.
I refactor or even rewirte  some parts of the code, seems it's a big
change.
I don't know you need the change or not.

Geoffrey Teale

unread,
Apr 11, 2012, 10:16:28 AM4/11/12
to Hill, golang-nuts


On 11 April 2012 15:54, Hill <zhub...@gmail.com> wrote:
Hi Teale,

Hi!

You can call me Geoff.
 
Thanks for writing these code, i learned a lot of things from it.

Glad to have helped.
 
From the README, i saw you didn't have a plan to support write the
excel,
so i forked one branch from your lib, and was trying to make it write
 something to the excel.
Currently it can open a exist workbook and write data to the exist
sheet.
but can't create new workbook, or add new sheet to a workbook.
I refactor or even rewirte  some parts of the code, seems it's a big
change.
I don't know you need the change or not.

I would be very interested in having it and moving forward to a writeable version in general.  This project is not a high priority for me, but anything that moves it forwards is interesting to me. 

Regards,
Geoff Teale

sdeg...@8thlight.com

unread,
Apr 11, 2012, 12:15:19 PM4/11/12
to golan...@googlegroups.com
One thing I noticed is that, when looking at the API via http://gopkgdoc.appspot.com/pkg/github.com/tealeg/xlsx#XLSXSelection it appears that several types beginning with XLSX are exported but it looks like they're actually needed for the implementation and don't need to be exported. I'm guessing this happened because of trying to be correct with the case of XLSX, but if they're basically private then it makes more sense to make the prefix a lower-cased 'xlsx'. Compare the previous gopkgdoc page with http://gopkgdoc.appspot.com/pkg/github.com/sdegutis/xlsx to see the difference it makes on the client (me). So I've done the leg-work of making these changes to my fork of your project, and have sent you a pull-request on github.

-Steven

bronze man

unread,
Apr 1, 2014, 7:57:12 AM4/1/14
to golan...@googlegroups.com
I found a easy way to write a csv file that Microsoft Excel can read.
  1. package main
  2. import (
  3.     "os"
  4.     "encoding/csv")
  5. func main() {
  6.     f, err := os.Create("haha2.xls")
  7.     if err != nil {
  8.         panic(err)
  9.     }
  10.     defer f.Close()

  11.     f.WriteString("\xEF\xBB\xBF") // 写入UTF-8 BOM

  12.     w := csv.NewWriter(f)
  13.     w.Write([]string{"编号","姓名","年龄"})
  14.     w.Write([]string{"1","张三","23"})
  15.     w.Write([]string{"2","李四","24"})
  16.     w.Write([]string{"3","王五","25"})
  17.     w.Write([]string{"4","赵六","26"})
  18.     w.Flush()
  19. }

Konstantin Khomoutov

unread,
Apr 1, 2014, 8:09:50 AM4/1/14
to bronze man, golan...@googlegroups.com
On Tue, 1 Apr 2014 04:57:12 -0700 (PDT)
bronze man <bronz...@gmail.com> wrote:

> I found a easy way to write a csv file that Microsoft Excel can read.
>
> 1. package main
> 2. import (
> 3. "os"
> 4. "encoding/csv")
> 5. func main() {
> 6. f, err := os.Create("haha2.xls")
[...]

Why give it the ".xls" extension then? It has been used for obsolete
(pre-"OpenXML", binary) documents Excel were writing.
Surely MSO products try to second-guess and detect the type of file
contents using the contents but why rely on this?

Geoffrey Teale

unread,
Apr 1, 2014, 8:12:13 AM4/1/14
to bronze man, golang-nuts
Sure, writing CSV from Go is trivial, and works for many simple cases.   Full XLSX output would be more involved.


--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

bronze man

unread,
Apr 2, 2014, 1:26:40 AM4/2/14
to golan...@googlegroups.com
I just write a Xlsx writer in several hours. Turn out it is not so difficult if you just want to see data in excel.

I do not understand or read xlsx file format specification,it is too complex for my need.I just unzip wps's xlsx file, copy some content into my code,dynamically generated some content with xml,and zip them into a xlsx file.


On Tuesday, April 10, 2012 1:43:58 PM UTC+8, Geoff Teale wrote:
Reply all
Reply to author
Forward
0 new messages