excelizeam

package module
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Jan 23, 2024 License: MIT Imports: 10 Imported by: 0

README

excelizeam

Wrapper to facilitate use of excelize.StreamWriter in qax-os/excelize

Motivation

excelize.StreamWriter in qax-os/excelize has been found to be able to write large amounts of data at high speed while reducing memory usage, and should be used aggressively, but its use is severely limited, and Excel itself will be damaged if the order of writes is incorrect.

Therefore, a Wrapper was created to automatically meet the restrictions.

When using SyncMethod such as SetCellValue(), there is no advantage in speed, but by using Async function such as SetCellValueAsync(), it is possible to achieve almost the same speed as excelize.StreamWriter.

qax-os/excelizeexcelize.StreamWriter は大量のデータをメモリ使用量を抑えつつ高速に書き込むことが出来る事が示されており積極的に利用したいが、利用する際の制限が厳しく書き込みの順番を間違えるとExcel自体が破損してしまうため、そのままでは使い所が難しい。

そのため制限を自動的に満たすためのWrapperを作成した。

SetCellValue() のようなSyncMethodを使用する場合は速度面でのメリットを享受出来ないが、 SetCellValueAsync() のようなAsync関数を利用することで excelize.StreamWriter とほぼ同様の速度を出すことが可能になる。

BenchmarkExcelizeam
BenchmarkExcelizeam/Excelize
BenchmarkExcelizeam/Excelize-12                  	       9	 124964492 ns/op
BenchmarkExcelizeam/Excelize_Async
BenchmarkExcelizeam/Excelize_Async-12   	               6	 208647106 ns/op
BenchmarkExcelizeam/Excelize_StreamWriter
BenchmarkExcelizeam/Excelize_StreamWriter-12         	      12	  89386412 ns/op
BenchmarkExcelizeam/Excelizeam_Sync
BenchmarkExcelizeam/Excelizeam_Sync-12               	       5	 232665514 ns/op
BenchmarkExcelizeam/Excelizeam_Async
BenchmarkExcelizeam/Excelizeam_Async-12              	      13	  86562598 ns/op

Usage

install your project
go get github.com/tomtwinkle/excelizeam@v0.3.4

TODO

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrOverrideCellValue = errors.New("override cell value")
	ErrOverrideCellStyle = errors.New("override cell style")
)

Functions

This section is empty.

Types

type BorderItem

type BorderItem struct {
	Style excelizestyle.BorderStyle
	Color excelizestyle.BorderColor
}

type BorderRange

type BorderRange struct {
	Top    *BorderItem
	Bottom *BorderItem
	Left   *BorderItem
	Right  *BorderItem
	Inside *BorderItem
}

type Cell

type Cell struct {
	StyleID int
	Value   interface{}
}

type DefaultBorders

type DefaultBorders struct {
	StyleID int

	Top    excelize.Border
	Bottom excelize.Border
	Left   excelize.Border
	Right  excelize.Border
}

type Excelizeam

type Excelizeam interface {

	// SetDefaultBorderStyle Set default cell border
	// For example, use when you want to paint the cell background white
	SetDefaultBorderStyle(style excelizestyle.BorderStyle, color excelizestyle.BorderColor) error

	SetPageMargins(options *excelize.PageLayoutMarginsOptions) error
	SetColWidth(colIndex int, width float64) error
	SetColWidthRange(colIndexMin, colIndexMax int, width float64) error
	MergeCell(startColIndex, startRowIndex, endColIndex, endRowIndex int) error

	// SetCellValue Set value and style to cell
	SetCellValue(colIndex, rowIndex int, value interface{}, style *excelize.Style, overrideValue, overrideStyle bool) error
	// SetCellValueAsync Set value and style to cell asynchronously
	SetCellValueAsync(colIndex, rowIndex int, value interface{}, style *excelize.Style, overrideStyle bool)

	// SetStyleCell Set style to cell
	SetStyleCell(colIndex, rowIndex int, style excelize.Style, override bool) error
	// SetStyleCellAsync Set style to cell asynchronously
	SetStyleCellAsync(colIndex, rowIndex int, style excelize.Style, override bool)

	// SetStyleCellRange Set style to cell with range
	SetStyleCellRange(startColIndex, startRowIndex, endColIndex, endRowIndex int, style excelize.Style, override bool) error
	// SetStyleCellRangeAsync Set style to cell with range asynchronously
	SetStyleCellRangeAsync(startColIndex, startRowIndex, endColIndex, endRowIndex int, style excelize.Style, override bool)

	// SetBorderRange Set border around cell range
	SetBorderRange(startColIndex, startRowIndex, endColIndex, endRowIndex int, borderRange BorderRange, override bool) error
	// SetBorderRangeAsync Set border around cell range asynchronously
	SetBorderRangeAsync(startColIndex, startRowIndex, endColIndex, endRowIndex int, borderRange BorderRange, override bool)

	// Wait
	// Wait for all running asynchronous operations to finish
	Wait() error

	// Write StreamWriter
	Write(w io.Writer) error

	// File Get the original excelize.File
	File() (*excelize.File, error)

	// CSVRecords Make csv records
	CSVRecords() ([][]string, error)
}

func New

func New(sheetName string) (Excelizeam, error)

type StoredStyle

type StoredStyle struct {
	StyleID int
	Style   *excelize.Style
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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