@eyeseetea/xlsx-populate
Advanced tools
Comparing version 4.1.0 to 4.2.0
@@ -201,2 +201,18 @@ "use strict"; | ||
/** | ||
* Set or clear the comment on the cell. | ||
* @param {{}|undefined} opts - Options or undefined (remove comment). | ||
* @param {string} [opts.text] - The comment text to set. | ||
* @param {string} [opts.width] - Comment box width. | ||
* @param {string} [opts.height] - Comment box height. | ||
* @returns {Cell} The cell. | ||
*/ | ||
comment() { | ||
return new ArgHandler('Cell.comment') | ||
.case('*', options => { | ||
this.sheet().comment(this.address(), options); | ||
return this; | ||
}) | ||
.handle(arguments); | ||
} | ||
@@ -203,0 +219,0 @@ /** |
@@ -48,4 +48,4 @@ "use strict"; | ||
attributes: { | ||
ContentType: contentType, | ||
Extension: extension | ||
Extension: extension, | ||
ContentType: contentType | ||
} | ||
@@ -52,0 +52,0 @@ }; |
@@ -63,2 +63,13 @@ "use strict"; | ||
addDxStyle() { | ||
const fontNode = { name: "font", attributes: {}, children: [] }; | ||
const fillNode = { name: "fill", attributes: {}, children: [] }; | ||
const borderNode = { name: "border", attributes: {}, children: [] }; | ||
const dxfNode = { name: "dxf", attributes: {}, children: [fontNode, fillNode, borderNode] }; | ||
this._dxfsNode.children.push(dxfNode); | ||
const id = this._dxfsNode.children.length - 1; | ||
return new Style(this, id, null, fontNode, fillNode, borderNode); | ||
} | ||
/** | ||
@@ -210,3 +221,9 @@ * Create a style. | ||
this._cellXfsNode = xmlq.findChild(this._node, "cellXfs"); | ||
this._dxfsNode = xmlq.findChild(this._node, "dxfs"); | ||
if (!this._dxfsNode) { | ||
this._dxfsNode = { name: "dxfs", attributes: {}, children: [] }; | ||
xmlq.insertAfter(this._node, this._dxfsNode, this._cellXfs); | ||
} | ||
if (!this._numFmtsNode) { | ||
@@ -229,2 +246,3 @@ this._numFmtsNode = { | ||
delete this._cellXfsNode.attributes.count; | ||
delete this._dxfsNode.attributes.count; | ||
} | ||
@@ -231,0 +249,0 @@ } |
@@ -131,2 +131,4 @@ // Type definitions for XLSX-Populate | ||
horizontalPageBreaks(): PageBreaks; | ||
comment(address: string, comment: Comment | undefined): Sheet; | ||
conditionalFormatting(address: string, conditionalFormatting: ConditionalFormatting | undefined): Sheet; | ||
hyperlink(address: string): string | undefined; | ||
@@ -214,2 +216,3 @@ hyperlink(address: string, hyperlink: string, internal?: boolean): Sheet; | ||
formula(formula: string): Cell; | ||
comment(comment: Comment | undefined): Cell; | ||
hyperlink(): string | undefined; | ||
@@ -397,2 +400,15 @@ hyperlink(hyperlink: string | Cell | undefined): Cell; | ||
class Comment { | ||
text: string; | ||
width: string; | ||
height: string; | ||
} | ||
class ConditionalFormatting { | ||
type: string; | ||
formula: string; | ||
priority: number; | ||
style: Style; | ||
} | ||
class FormulaError { | ||
@@ -399,0 +415,0 @@ error(): string; |
@@ -332,2 +332,43 @@ "use strict"; | ||
this._zip.file(drawingRelsPath, xmlBuilder.build(sheet._drawingRelationships), zipFileOpts); | ||
const commentKeys = Object.keys(sheet._comments) | ||
if (commentKeys.length > 0) { | ||
const commentsPath = `xl/comments${i + 1}.xml` | ||
this._zip.file(commentsPath, xmlBuilder.build({ | ||
name: 'comments', | ||
attributes: { | ||
'xmlns': 'http://schemas.openxmlformats.org/spreadsheetml/2006/main', | ||
}, | ||
children: [ | ||
{ | ||
name: 'authors', | ||
children: [ | ||
{ name: 'author', children: ['xlsx-populate'] } | ||
] | ||
}, | ||
{ | ||
name: 'commentList', | ||
children: commentKeys.map(ref => ({ | ||
name: 'comment', | ||
attributes: { ref: ref, authorId: "0" }, | ||
children: [ | ||
{ | ||
name: 'text', | ||
children: [ | ||
{ name: 't', children: [sheet._comments[ref].text] } | ||
] | ||
} | ||
] | ||
})), | ||
} | ||
], | ||
}), zipFileOpts); | ||
const comments = Object.values(sheet._comments) | ||
this._zip.file(`xl/drawings/vmlDrawing${i + 1}.vml`, getVmlDrawingXml(i+1, comments)); | ||
this._contentTypes.add(`/${commentsPath}`, "application/vnd.openxmlformats-officedocument.spreadsheetml.comments+xml"); | ||
this._contentTypes.addDefault("vml", "application/vnd.openxmlformats-officedocument.vmlDrawing"); | ||
} | ||
}); | ||
@@ -891,2 +932,36 @@ | ||
function getVmlDrawingXml(sheetIndex, comments) { | ||
const shapesXml = comments.map((comment, idx) => ` | ||
<v:shape id="_x0000_s${idx + 1025}" type="#_x0000_t202" style="position:absolute; margin-left:59.25pt;margin-top:1.5pt;width:${comment.width};height:${comment.height};z-index:1; visibility:hidden" fillcolor="#ffffe1" o:insetmode="auto"> | ||
<v:fill color2="#ffffe1"/> | ||
<v:shadow color="black" obscured="t"/> | ||
<v:path o:connecttype="none"/> | ||
<v:textbox style="mso-direction-alt:auto"> | ||
<div style="text-align:left"/> | ||
</v:textbox> | ||
<x:ClientData ObjectType="Note"> | ||
<x:MoveWithCells/> | ||
<x:SizeWithCells/> | ||
<x:AutoFill>False</x:AutoFill> | ||
<x:Row>${comment.row - 1}</x:Row> | ||
<x:Column>${comment.column - 1}</x:Column> | ||
</x:ClientData> | ||
</v:shape>`) | ||
const vmlDrawing = ` | ||
<xml xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel"> | ||
<o:shapelayout v:ext="edit"> | ||
<o:idmap v:ext="edit" data="${sheetIndex}"/> | ||
</o:shapelayout> | ||
<v:shapetype id="_x0000_t202" coordsize="21600,21600" o:spt="202" path="m,l,21600r21600,l21600,xe"> | ||
<v:stroke joinstyle="miter"/> | ||
<v:path gradientshapeok="t" o:connecttype="rect"/> | ||
</v:shapetype> | ||
${_.join(shapesXml, '')} | ||
</xml> | ||
`; | ||
return vmlDrawing; | ||
} | ||
module.exports = Workbook; | ||
@@ -893,0 +968,0 @@ |
{ | ||
"name": "@eyeseetea/xlsx-populate", | ||
"version": "4.1.0", | ||
"version": "4.2.0", | ||
"private": false, | ||
@@ -5,0 +5,0 @@ "description": "Excel XLSX parser/generator written in JavaScript with Node.js and browser support, jQuery/d3-style method chaining, and a focus on keeping existing workbook features and styles in tact.", |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
16908817
89
64494
3748
4