Skip to content
This repository has been archived by the owner on Jul 22, 2022. It is now read-only.

Commit

Permalink
fix picture file extension issue where period was included in XML
Browse files Browse the repository at this point in the history
add image from buffer added to sample
  • Loading branch information
natergj committed Nov 12, 2017
1 parent d729007 commit 0962ba2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
23 changes: 19 additions & 4 deletions sample.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
const fs = require('fs');
const path = require('path');

require('source-map-support').install();
var xl = require('./distribution');

Expand Down Expand Up @@ -459,7 +462,7 @@ function generateWorkbook() {
* START final sheet
*****************************************/

var funSheet = wb.addWorksheet('fun', {
var imageSheet = wb.addWorksheet('images', {
pageSetup: {
orientation: 'landscape'
},
Expand All @@ -468,8 +471,8 @@ function generateWorkbook() {
}
});

funSheet.cell(1, 1).string('Release 1.0.0! Finally done.');
funSheet.addImage({
imageSheet.cell(1, 1).string('Images');
imageSheet.addImage({
path: './sampleFiles/thumbsUp.jpg',
type: 'picture',
position: {
Expand All @@ -478,7 +481,19 @@ function generateWorkbook() {
y: '10mm'
}
});

imageSheet.addImage({
image: fs.readFileSync(path.resolve(__dirname, './sampleFiles/thumbsUp.jpg')),
type: 'picture',
position: {
type: 'oneCellAnchor',
from: {
col: 1,
colOff: 0,
row: 32,
rowOff: 0
}
}
});

/*****************************************
* END final sheet
Expand Down
2 changes: 1 addition & 1 deletion source/lib/drawing/picture.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class Picture extends Drawing {

this._extension = this.image
? size.type
: path.extname(this.imagePath);
: path.extname(this.imagePath).substr(1);

this.contentType = mime.lookup(this._extension);

Expand Down

0 comments on commit 0962ba2

Please sign in to comment.