Git Product home page Git Product logo

vxlsx's Introduction

vxlsx

Description

A vlang libxlsxwriter module

This is an effort port libxlsxwriter to vlang.

Please check doc for more API description.

Install

	v install --git https://github.com/kbkpbot/vxlsx.git

Note: Currently, vxlsx need minizip install on your system, make sure it is installed.

apt install libminizip-dev

Simple Usage

vxlsx provide a simple function interface.

module main

import vxlsx

struct Expense {
	item string
	cost int
}

fn main() {
	w := vxlsx.new_workbook('tutorial01.xlsx')
	s := w.add_worksheet('test')

	expenses := [Expense{'Rent', 1000}, Expense{'Gas', 100}, Expense{'Food', 300},
		Expense{'Gym', 50}]

	mut col := u16(0)

	for row in 0 .. 4 {
		s.write(row, col, expenses[row].item) // `write` can write multiple type of data
		s.write(row, col + 1, expenses[row].cost)
	}
	s.write(4, col, 'total')
	s.write(4, col + 1, '=SUM(B1:B4)') // `write` can write formula, which starts with '='
	w.close()
}

The write function can write multiple type of data. write can write formula too, which starts with =.

Write a struct

vxlsx provide a simple method write struct.

module main

import vxlsx

struct Expense {
	item string              @[row: 0; title: 'MyItems'] // use attr as directive
	cost vxlsx.All_Data_Type @[title: 'MyCost']
}

fn main() {
	w := vxlsx.new_workbook('tutorial02.xlsx')
	s := w.add_worksheet('test')

	expenses := [Expense{'Rent', 1000}, Expense{'Gas', 100}, Expense{'Food', 300},
		Expense{'Gym', 50}, Expense{'total', '=SUM(B2:B5)'}]
	s.write_struct(expenses) // `write_struc` use struct attr write the records
	w.close()
}

Struct Expense first field has attr, which direct how to write the field(s) to xlsx. Currently, only support 3 attrs:

  • row set the start row, and every record per col;
  • col set the start col, and every record per row; (Note: You can not use row and col both)
  • title write the title line to xlsx, and set the title for the field;

TODO

  • Many enum have not been ported;
  • Remove system minizip requirement;
  • Should port to other platformt;

vxlsx's People

Contributors

kbkpbot avatar

Watchers

 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.