Giter Site home page Giter Site logo

csvformat's Introduction

csvformat

One thing that takes up a ton of time is getting the output to look right. With csvformat you can take any text string that is formatted in CSV and create a nice table format. Example:

func main() {
	csvstuff := getCsv() // This could be any function that returns a text string with CSV.
	csvout := csvformat.NewGrid()
	fmt.Println(csvout.Gridout(string(csvstuff)))
}

See minimal.go in the ex folder. Function getCsv() just does a simple http.Client to https://cdn.wsform.com/wp-content/uploads/2021/04/weekday.csv The main point is that you just need to format it in csv, and you don't have to do any additional formatting.

Output:

+--------------+-----------------+------------+--------------+
|     Name     |   Abbreviation  |   Numeric  |   Numeric-2  |
+==============+=================+============+==============+
|    Monday    |       Mon.      |      1     |      01      |
|    Tuesday   |       Tue.      |      2     |      02      |
|   Wednesday  |       Wed.      |      3     |      03      |
|   Thursday   |       Thu.      |      4     |      04      |
|    Friday    |       Fri.      |      5     |      05      |
|   Saturday   |       Sat.      |      6     |      06      |
|    Sunday    |       Sun.      |      7     |      07      |
+--------------+-----------------+------------+--------------+

Better Example:

func main() {
	csvtext := fmt.Sprintf("One,Two,Three\nFour,Five,Six\nSeven,Eight,Nine")
	csvgrid := csvformat.NewGrid()
	csvgrid.Headline = "First,Second,Third" // This is optional. If the CSV already contains a heading line. don't set this.
	csvgrid.Render = rendr                  // There are several different formats.
	out, err := csvgrid.Gridout(csvtext)
	if err != nil {
		fmt.Println("error:", err)
		os.Exit(1)
	}
	fmt.Println(out)
}

Output:

+----------+-----------+----------+
|   First  |   Second  |   Third  |
+==========+===========+==========+
|    One   |    Two    |   Three  |
|   Four   |    Five   |    Six   |
|   Seven  |   Eight   |   Nine   |
+----------+-----------+----------+

Output formats:

  • simple
  • plain
  • tab
  • text
  • html Todo: format as a bootstrap table.
  • mysql

csvformat's People

Contributors

rmasci avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.