Golang export Excel (Excel format)

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed.

Previously written in an export CVS format, if only simple export can fully meet the needs. On time if you want to have complex needs, such as style customization, multiple sheet and so on, it will not be completed. Later found someone has implemented Golang direct Excel to Excel operations, here to share a bit.
Address: https://github.com/tealeg/xlsx
Specific types of operations can be seen directly inside the sample or directly view the code, the usage is very simple. Here is a simple test example:

Package Mainimport ("FMT" "github.com/tealeg/xlsx") func test1 () {var file *xlsx. Filevar sheet *xlsx. Sheetvar row *xlsx. Rowvar cell *xlsx. Cellvar Err ErrorFile = xlsx. NewFile () sheet = file. Addsheet ("Sheet1") row = sheet. AddRow () cell = row. Addcell () cell. Value = "000101" cell = row. Addcell () cell. Value = "Chinese" err = file. Save ("myxlsxfile.xlsx") if err! = Nil {fmt. Printf (Err. Error ())}}func test2 () {var file *xlsx. Filevar sheet *xlsx. Sheetvar row *xlsx. Rowvar cell *xlsx. Cellvar Err ErrorFile, _ = xlsx. OpenFile ("myxlsxfile.xlsx") sheet = file. sheet["Sheet1"]row = Sheet. AddRow () cell = row. Addcell () cell. Value = "000101" cell = row. Addcell () cell. Value = "Chinese 1" err = file. Save ("myxlsxfile1.xlsx") if err! = Nil {fmt. Printf (Err. Error ())}}func main () {test1 () test2 ()}

  

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.