json2docs

package module
v1.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 26, 2023 License: MIT Imports: 10 Imported by: 0

README

json2docs

install
go get github.com/sanda0/json2docs
example
package main

import (
 "fmt"
 "log"

 "github.com/sanda0/json2docs"
)

func main() {
 formatJSON := []byte(`{
  "Header": [
   {"Line": 1, "Text": "Abc Company"},
   {"Line": 2, "Text": "123 Main Street"},
   {"Line": 3, "Text": "Special report"},
   {"Line": 4, "Text": "Reporting period January to December 2018"}
  ],
  "BodyHeader": [
   {"Index": 1, "Text": "Code", "Width": 10},
   {"Index": 2, "Text": "Name", "Width": 30},
   {"Index": 3, "Text": "Quantity", "Width": 10},
   {"Index": 4, "Text": "Price", "Width": 10},
   {"Index": 5, "Text": "Total", "Width": 10},
   {"Index": 6, "Text": "AVG", "Width": 10}
  ],
  "BodyFields": [
   {"Index": 1, "Field": "prodId", "Width": 10},
   {"Index": 2, "Field": "description", "Width": 30},
   {"Index": 3, "Field": "qty", "Width": 10},
   {"Index": 4, "Field": "price", "Width": 10},
   {"Index": 5, "Field": "amount", "Width": 10},
   {"Index": 6, "Field": "avg", "Width": 10}

  ],
  "Summary": [
   {"Index": 1, "Text": "", "Width": 10},
   {"Index": 2, "Text": "", "Width": 30},
   {"Index": 3, "Text": "", "Width": 10},
   {"Index": 4, "Text": "", "Width": 10},
   {"Index": 5, "Text": "150.00", "Width": 10},
   {"Index": 6, "Text": "10.00", "Width": 10}
  ]
 }`)

 dataJSON := []byte(`[
  {
   "prodId": "1",
   "description": "Product 1",
   "qty": 1,
   "price": 10.00,
   "amount": 10.00,
   "avg": 5.00
  },
  {
   "prodId": "2",
   "description": "Product 2",
   "qty": 1,
   "price": 20.00,
   "amount": 20.00,
   "avg": 5.00

  },
  {
   "prodId": "3",
   "description": "Product 3",
   "qty": 1,
   "price": 30.00,
   "amount": 30.00,
   "avg": 5.00

  },
  {
   "prodId": "4",
   "description": "Product 4",
   "qty": 1,
   "price": 40.00,
   "amount": 40.00,
   "avg": 5.00

  },
  {
   "prodId": "5",
   "description": "Product 5",
   "qty": 1,
   "price": 50.00,
   "amount": 50.00,
   "avg": 5.00

  },
  {
   "prodId": "3",
   "description": "Product 3",
   "qty": 1,
   "price": 30.00,
   "amount": 30.00,
   "avg": 5.00

  },
  {
   "prodId": "4",
   "description": "Product 4",
   "qty": 1,
   "price": 40.00,
   "amount": 40.00,
   "avg": 5.00

  },
  {
   "prodId": "5",
   
   "qty": 1,
   "price": 50.00,
   "amount": 50.00,
   "description": "Product 5",
   "avg": 5.00

  }
 ]`)

  excelFilename,err := json2docs.ExcelTabularGenerator(formatJSON, dataJSON, "filename")
 if err != nil {
  log.Fatal(err)
 }
 pdfFilename,err := json2docs.PdfTabularGenerator(formatJSON, dataJSON,"filename")
 if err != nil {
  log.Fatal(err)
 }
 htmlFilename,err := json2docs.HtmlTabularGenerator(formatJSON, dataJSON,"filename")
 if err != nil {
  log.Fatal(err)
 }
 fmt.Println("Excel file generated:", excelFilename)
 fmt.Println("pdf file generated:", pdfFilename)
 fmt.Println("html file generated:", htmlFilename)

 // /================================================================

}

Buy Me A Coffee

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExcelTabularGenerator

func ExcelTabularGenerator(format []byte, data []byte, filename string) (string, error)

func GetColumnLetter

func GetColumnLetter(index int) string

func HtmlTabularGenerator

func HtmlTabularGenerator(format []byte, data []byte, filename string) (string, error)

func IsDigit

func IsDigit(str string) bool

func PdfTabularGenerator

func PdfTabularGenerator(format []byte, data []byte, filename string) (string, error)

func RandStringBytes

func RandStringBytes(n int) string

Types

type BodyField

type BodyField struct {
	Index int    `json:"Index"`
	Field string `json:"Field"`
	Width int    `json:"Width"`
}

type BodyHeaderField

type BodyHeaderField struct {
	Index int
	Text  string
	Width int
}

type Format

type Format struct {
	Header     []HeaderField
	BodyHeader []BodyHeaderField
	BodyFields []BodyField
	Summary    []SummaryField
}

type HeaderField

type HeaderField struct {
	Line int
	Text string
}

type SummaryField

type SummaryField struct {
	Index int
	Text  string
	Width int
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL