Installation

npm version
1npm install excel-build

Usage

FileBuilder

1import { FileBuilder } from 'excel-build';
2
3const excelFile = new FileBuilder('FILE_NAME');
4
5excelFile.addSheet(sheet1).addSheet(sheet2).download();

API

MethodDescriptionTypeParameterReturns
addSheetAdd a sheet to the Excel file.functionSheetBuilderFileBuilder
downloadDownload the Excel file you created.function-void

SheetBuilder

1import { SheetBuilder } from 'excel-build';
2
3const data = [
4 ['1', 'soohyun', 'sasha1107@naver.com', '01012345678', 'FE'],
5 ['2', 'sasha', 'sasha981107@gmail.com', '01087654321', 'BE'],
6];
7
8const sheet1 = new SheetBuilder('sheet_1');
9const sheet2 = new SheetBuilder('sheet_2')
10 .appendThead(['id', 'name', 'email', 'phone', 'department'])
11 .appendTbody(data)
12 .mergeCell([0, 3], [4, 3]);

API

MethodDescriptionTypeParameterReturns
appendTheadAdds a header row to the table.function(theadArr: string[], option: any)SheetBuilder
appendRowAdds a row to the table.function(tRowArr: string|number|boolean|Date[], option: any)SheetBuilder
addTBodyAdds a row in array to the table.function(tbodyArr: string|number|boolean|Date[][], option: any)SheetBuilder
appendCustomRowAdd custom style rows to the table.function(row: string|number|boolean|Date[], option: any)SheetBuilder
mergeCellMerge the cells with the starting cell [x0, y0] and the ending cell [x1, y1] as factors.function(start: [number, number], end: [number, number])SheetBuilder
getWorkSheetReturns the sheet you created.function-SheetBuilder
getSheetNameReturns the name of the sheet you created. function-string
setColumnWidthSet the width for a specific column on the sheet.function(columnNumber: number, width: number)SheetBuilder

CellBuilder

1const data = ['1', 'soohyun', 'sasha1107@naver.com', '01012345678', 'FE'];
2
3sheet1.appendCustomRow(
4 data.map((item) =>
5 new CellBuilder(item)
6 .setFontSize(20)
7 .setFontColor('#FFFFFF')
8 .setBackgroundColor('#555555')
9 .setFontItalic()
10 .build()
11 )
12);

API

MethodDescriptionTypeParameterReturns
setAlignMentVerticalSets the vertical alignment of cells.functioncenter | top | bottomCellBuilder
setAlignMentHorizontalSets the horizontal alignment of cells.functioncenter | left | rightCellBuilder
setAlignMentWrapTextAllow text wrapping.function-CellBuilder
setAlignMentTextRotation180 is rotated down 180 degrees, 255 is special, aligned verticallyfunction0 to 180, or 255CellBuilder
setBorderSets the border style for cells.functionnull | BorderStyleTypeCellBuilder
setBackgroundColorSets the background color of the cell.functionstring(ex.#000000)CellBuilder
setFontColorSet the color of the font.functionstring(ex.#000000)CellBuilder
setFontSizeSet the font size.functionnumberCellBuilder
setFontBoldSet the font in bold.function-CellBuilder
setFontItalicSet the font to italic.function-CellBuilder
setFontStrikeSet strikethrough in the font.function-CellBuilder
setFontUnderlineUnderline the font.function-CellBuilder
buildBuild a cell.function-CellBuilder