Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

xlsx-template

Package Overview
Dependencies
Maintainers
2
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

xlsx-template - npm Package Compare versions

Comparing version 1.3.0 to 1.3.1

100

lib/index.d.ts

@@ -18,24 +18,68 @@ import * as etree from "elementtree";

export default class Workbook
namespace XlsxTemplate {
}
interface OutputByType {
base64: string;
uint8array: Uint8Array;
arraybuffer: ArrayBuffer;
blob: Blob;
nodebuffer: Buffer;
}
export type GenerateOptions = keyof OutputByType;
interface RangeSplit
{
start: string;
end: string;
}
protected readonly sharedStrings: string[];
interface ReferenceAddress
{
table?: string;
colAbsolute?: boolean;
col : string;
rowAbsolute?: boolean;
row : number;
}
class XlsxTemplate
{
public readonly sharedStrings: string[];
protected readonly workbook: etree.ElementTree;
protected readonly archive: JSZip;
public readonly archive: JSZip | null;
protected readonly workbookPath: string;
protected readonly calcChainPath?: string;
public readonly sharedStringsLookup: { [string]: number };
constructor(data? : Buffer, option? : object);
public deleteSheet(sheetName : string) : this;
public copySheet(sheetName : string, copyName : string) : this;
public copySheet(sheetName : string, copyName : string, binary? : boolean) : this;
public loadTemplate(data : Buffer) : void;
public substitute(sheetName : string | number, substitutions : Object) : void;
public generate<T extends Buffer | Uint8Array | Blob | string | ArrayBuffer>(options? : GenerateOptions) : T;
public generate<T extends GenerateOptions>(options : T) : OutputByType[T];
public generate() : any;
public replaceString(oldString : string, newString : string) : number; // returns idx
public stringIndex(s : string) : number; // returns idx
public writeSharedStrings() : void;
public splitRef(ref : string) : ReferenceAddress;
public joinRef(ref : ReferenceAddress) : string;
public addSharedString(s : string) : any; // I think s is a string? Not sure what its return "idx" is though, I think it's a number? Is "idx" short for "index"?
public substituteScalar(cell : any, string: string, placeholder: TemplatePlaceholder, substitution: any): string;
public charToNum(str : string) : number;
public numToChar(num : number) : string;
public nextCol(ref : string) : string;
public nextRow(ref : string) : string;
public stringify(value : Date | number | boolean | string) : string;
public isWithin(ref : string, startRef : string, endRef : string) : boolean;
public isRange(ref : string) : boolean;
public splitRange(range : string) : RangeSplit;
public joinRange(range : RangeSplit) : string;
public extractPlaceholders(templateString : string) : TemplatePlaceholder[];
// need typing properly
protected _rebuild() : void;
protected writeSharedStrings() : void;
protected addSharedString(s : any) : any; // I think s is a string? Not sure what its return "idx" is though, I think it's a number? Is "idx" short for "index"?
protected stringIndex(s : any) : any; // returns idx
protected replaceString(oldString : string, newString : string) : any; // returns idx
protected loadSheets(prefix : any, workbook : etree.ElementTree, workbookRels : any) : any[];

@@ -51,16 +95,6 @@ protected loadSheet(sheet : any) : { filename : any, name : any, id : any, root : any }; // this could definitely return a "Sheet" interface/class

protected substituteTableColumnHeaders(tables : any, substitutions : any) : void;
protected extractPlaceholders(string : any) : any[];
protected splitRef(ref : any) : { table : any, colAbsolute : any, col : any, rowAbsolute : any, row : any }
protected joinRef(ref : any) : string;
protected nextCol(ref : any) : string;
protected nextRow(ref : any) : string
protected charToNum(str : string) : number;
protected numToChar(num : number) : string;
protected isRange(ref : any) : boolean;
protected isWithin(ref : any, startRef : any, endRef : any) : boolean;
protected stringify(value : any) : string;
protected insertCellValue(cell : any, substitution : any) : string;
protected substituteScalar(cell : any, string: string, placeholder: TemplatePlaceholder, substitution: any);
protected substituteArray(cells : any[], cell : any, substitution : any);
protected substituteTable(row : any, newTableRows : any, cells : any[], cell : any, namedTables : any, substitution : any, key : any) : any;
protected substituteTable(row : any, newTableRows : any, cells : any[], cell : any, namedTables : any, substitution : any, key : any, placeholder : TemplatePlaceholder, drawing : etree.ElementTree) : any;
protected substituteImage(cell : any, string : string, placeholder: TemplatePlaceholder, substitution : any, drawing : etree.ElementTree) : boolean
protected cloneElement(element : any, deep? : any) : any;

@@ -71,11 +105,23 @@ protected replaceChildren(parent : any, children : any) : void;

protected updateRowSpan(row : any, cellsInserted : any) : any;
protected splitRange(range : string) : any;
protected joinRange(range : any) : string
protected pushRight(workbook : etree.ElementTree, sheet : any, currentCell : any, numCols : any) : any;
protected pushDown(workbook : etree.ElementTree, sheets : any, tables : any, currentRow : any, numRows : any) : any;
//Insert for insert_image
protected getWidthCell(numCol : int, sheet : etree.ElementTree) : float;
protected getWidthMergeCell(mergeCell : etree.ElementTree, sheet : etree.ElementTree) : Float32Array
protected getHeightCell(numRow : int, sheet : etree.ElementTree) : float;
protected getHeightMergeCell(mergeCell : etree.ElementTree, sheet : etree.ElementTree) : Float32Array
protected getNbRowOfMergeCell(mergeCell : etree.ElementTree) : Int16Array;
protected pixels(pixels : float) : Int16Array;
protected columnWidthToEMUs(width : float) : Int16Array;
protected rowHeightToEMUs(height : float) : Int16Array;
protected findMaxFileId(fileNameRegex : string, idRegex : string) : Int16Array;
protected cellInMergeCells(cell : etree.ElementTree, mergeCell : etree.ElementTree) : boolean;
protected isUrl(str : string) : boolean;
protected toArrayBuffer(buffer : Buffer) : ArrayBuffer;
protected imageToBuffer(imageObj : any) : Buffer;
protected findMaxId(element : etree.ElementTree, tag : string, attr : string, idRegex : string) : int;
}
export interface GenerateOptions
{
type : "uint8array" | "arraybuffer" | "blob" | "nodebuffer" | "base64";
}
export as namespace XlsxTemplate;
export = XlsxTemplate;
{
"name": "xlsx-template",
"version": "1.3.0",
"version": "1.3.1",
"description": "Generate .xlsx (Excel) files from templates built in Excel",

@@ -36,13 +36,39 @@ "main": "./lib/index",

],
"jest": {
"collectCoverage": true,
"coverageDirectory": "../coverage",
"coverageReporters": [
"text",
"cobertura"
],
"transform": {
".(js|ts|tsx)": "ts-jest"
},
"testRegex": "(/__tests__/.*|-(test|spec))\\.(ts|tsx|js)$",
"moduleFileExtensions": [
"ts",
"tsx",
"js"
],
"testTimeout": 500,
"moduleNameMapper": {
"^app/(.*)": "<rootDir>/lib/$1",
"^tests/(.*)": "<rootDir>/tests/$1"
}
},
"dependencies": {
"elementtree": "0.1.6",
"image-size": "^0.3.5",
"jszip": "^2.6.1"
},
"devDependencies": {
"buster": "0.7.18",
"grunt": "~1.0.1",
"grunt-buster": "~0.4.2"
"@types/jest": "^27.4.0",
"@types/jszip": "0.0.27",
"@types/node": "^14.0.27",
"jest": "^27.5.1",
"ts-jest": "^27.1.3",
"typescript": "^3.9.7"
},
"scripts": {
"test": "buster-test"
"test": "jest"
},

@@ -49,0 +75,0 @@ "readme": "",

@@ -86,2 +86,44 @@ # XLSX Template

### Images
You can insert images with
| My image: | ${image:imageName} |
Given data
var template = { imageName: "helloImage.jpg"}
You can insert a list of images with
| My images | ${table:images.name:image} |
Given data
var template = { images: [{name : "helloImage1.jpg"}, {name : "helloImage2.jpg"}]}
Supported image format in given data :
- Base64 string
- Base64 Buffer
- Absolute path file
- relative path file (absolute is prior to relative in test)
- URL : TODO
You can pass imageRootPath option for setting the root folder for your images.
var option = {imageRootPath : "/path/to/your/image/dir"}
...
var t = new XlsxTemplate(data, option);
If the image Placeholders is in standard cell, image is insert normaly
If the image Placeholders is in merge cell, image feet (at the best) the size of the merge cell.
You can pass imageRatio option for adjust the ratio image (in percent and for standard cell - not applied on merge cell)
var option = {imageRatio : 75.4}
...
var t = new XlsxTemplate(data, option);
## Generating reports

@@ -165,2 +207,8 @@

### Version 1.3.1
* Added the imageRatio parameter like a percent ratio when insert images. (#121)
* Add new substitution for images. (#110)
* Fixing Defined Range Name with Sheet Name. (#150)
* Add binary option for copySheet : for header/footer in UTF-8 (#130)
### Version 1.3.0

@@ -167,0 +215,0 @@ * Added support for optional moving of the images together with table. (#109)

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc