adding image not working.
See original GitHub issueHi, I am using exceljs in a html environment. I wanted to use addImage. But as soon as i do that i get an exception.
i used the following code:
// add image to workbook by filename
var imageId1 = workbook.addImage({
filename: 'img/logo.jpeg',
extension: 'jpeg',
});
i am using the following require.js definitions ` //Set the path to jQuery to local path requirejs.config({ paths: { jquery: ‘js/jquery’, Excel: “js/exceljs_2017_07_16”, //Excel: “js/exceljs”, fs: “js/filesaver.min”, // enables download of files within javascript - is used from exceljs jszip: “js/jszip.min”, // jszip is used to generate zip files - is used from exceljs lodash: “js/lodash”, // jszip is used to generate zip files - is used from exceljs es6shim: “js/es6-shim” // jszip is used to generate zip files - is used from exceljs } });
require([‘Excel’, ‘fs’, ‘jszip’, ‘lodash’, ‘es6shim’, ‘jquery’ ], function (Excel, fileSaver) {
…
}
i get the message that fs.readFile is not a function
TypeError: fs.readFile is not a function
at http://localhost:8080/exceljsTest/js/exceljs_2017_07_16.js:10749:8
at lib$es6$promise$$internal$$initializePromise (http://localhost:8080/exceljsTest/js/exceljs_2017_07_16.js:14955:9)
at Promish.lib$es6$promise$promise$$Promise [as constructor] (http://localhost:8080/exceljsTest/js/exceljs_2017_07_16.js:15246:9)
at new Promish (http://localhost:8080/exceljsTest/js/exceljs_2017_07_16.js:35957:108)
at fsReadFileAsync (http://localhost:8080/exceljsTest/js/exceljs_2017_07_16.js:10748:10)
at http://localhost:8080/exceljsTest/js/exceljs_2017_07_16.js:11086:18
at Array.map (native)
at 85.module.exports.addMedia (http://localhost:8080/exceljsTest/js/exceljs_2017_07_16.js:11082:47)
at http://localhost:8080/exceljsTest/js/exceljs_2017_07_16.js:11311:21
at lib$es6$promise$$internal$$tryCatch (http://localhost:8080/exceljsTest/js/exceljs_2017_07_16.js:14908:16)
`
The following code inside of exceljs (line 10749) is used (with a reference to fs.
function fsReadFileAsync(filename, options) { return new PromishLib.Promish(function (resolve, reject) { fs.readFile(filename, options, function (error, data) { if (error) { reject(error); } else { resolve(data); } }); }); }
What is the way to attach fs = What library do i have to include ? i am sure i can’t include node.js 😃 Thanks and best regards Manfred
Issue Analytics
- State:
- Created 6 years ago
- Comments:15 (1 by maintainers)
Top GitHub Comments
@Mafi78 : There are two interfaces of this library, stream mode and doc mode. Doc mode:
var workbook = new Excel.Workbook();
Stream mode:var workBook = new Excel.stream.xlsx.WorkbookWriter({useSharedStrings: true, useStyles: true, stream: res});
Stream mode is used when you have massive data, always recommended by author while doc mode blows up when you have more than 33K rows *100 cols. Your fixes is for doc mode.In stream mode, addImage function is missing from both workbook-writer and worksheet-writer. Infact, the author has not implemented addImage functionality for stream mode.
The simplest replicator is:
Throws exception on workBook.addImage and currentWorksheet.addImage.
You should use “path” library from NodeJS for adding image to workbook:
import * as path from ‘path’;
const IMAGE_PATH = path.resolve(‘public/image.jpg’); // path of our image … const logo = workbook.addImage({ filename: IMAGE_PATH, extension: ‘jpg’, }); … workSheet.addImage(logo, ‘A1:B5’); // set image in range of columns
This working for me