Skip to content

northbright/xls2csv-go

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

54 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

xls2csv-go

Package xls2csv is a Golang package which converts XLS file to CSV records. It's based on libxls.

Install xls2csv package

  • xls2csv requires libxls to be installed.
    • Install Dependencies

      • libiconv

        cd download
        wget https://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.18.tar.gz
        tar -xzvf libiconv-1.18.tar.gz
        cd libiconv-1.18
        ./configure
        make
        sudo make install
    • Install libxls

      wget https://github.com/libxls/libxls/releases/download/v1.6.3/libxls-1.6.3.tar.gz
      tar -xzvf libxls-1.6.3.tar.gz
      cd libxls-1.6.3
      ./configure
      make
      sudo make install
    • Add /usr/local/lib to lib search path(linux)

      echo "/usr/local/lib" | sudo tee /etc/ld.so.conf.d/usrlocallib.conf
      sudo ldconfig

Usage

package main

import (
    "fmt"

    "github.com/northbright/xls2csv-go/xls2csv"
)

func main() {
    var err error

    f := "my.xls"
    sheetId := 0
    records := [][]string{}

    // Call XLS2CSV() to convert XLS and get all records.
    if records, err = xls2csv.XLS2CSV(f, sheetId); err != nil {
        fmt.Printf("err: %v\n", err)
        return
    }

    fmt.Printf("records: %v\n", records)
}

Build and Test Your App

  • Install xls2csv package by running go mod tidy

    go mod tidy
    
  • Build

    CGO_CFLAGS=-I/usr/local/include CGO_LDFLAGS="-L/usr/local/lib -l xlsreader" go build
  • Test

    CGO_CFLAGS=-I/usr/local/include CGO_LDFLAGS="-L/usr/local/lib -l xlsreader" go test

Limitation

  • UTF-8 encoded XLS files only

Alternatives

  • GO-xls

    GO wrapper for libxls.

Documentation

License

About

Package xls2csv is a Golang package which converts XLS file to CSV records. It's based on libxls.

Resources

License

Stars

Watchers

Forks

Packages

No packages published