exceljs
exceljs copied to clipboard
[BUG] Type '{ col: number; row: number; }' is missing the following properties from type 'Anchor': nativeCol, nativeColOff, nativeRow, nativeRowOff, and 3 more.
🐛 Bug Report
Lib version: 4.2.1
Steps To Reproduce
worksheet.addImage(imageId, {
tl: { col: 0, row: 31 },
br: { col: 15, row: 31 },
});
The expected behaviour:
In TypeScript projects (like my Angular project) will not run if I use the example syntax shown in the README:
I get the following errors and cannot build because the interface requires all properties to be present.
Possible solution (optional, but very helpful):
// You could make those properties optional by putting a `?` before the semicolon defining the properties type to be optional.
export interface Anchor {
nativeCol?: number;
nativeColOff?: number;
nativeRow?: number;
nativeRowOff?: number;
....
}
// Or you could use a Partial of Anchor in the method declaration for `addImage`:
Partial<Anchor>
You can get around this by doing the following, but I couldn't find an example of this in the documentation:
worksheet.addImage(imageId, {
tl: new Anchor({ col: 0, row: 31 }),
br: new Anchor({ col: 15, row: 31})
});
I should clarify. This is not a solution. This let's my project transpile. However, I get an error: exceljs__WEBPACK_IMPORTED_MODULE_0__.Anchor is not a constructor
.
This is what my import statement looks like:
import { Anchor, Row, Workbook, Worksheet } from 'exceljs';
Hi @jakehockey10 what is the solution to this problem. Please i am going crazy with this image stretch issue.. Nothing is working. Thanks in advance if your solution can make my life easier.
So far? To not write this code.
I was really hoping I'd get a response. But I have no solution to this
Any updates??
I just overrode the errors and it seems to work fine so it must be an issue with the TS type definitions in this lib.
worksheet.addImage(imageId1, {
// @ts-expect-error Issue with ExcelJs types.
tl: { col: 8, row: 0.2 },
// @ts-expect-error Issue with ExcelJs types.
br: { col: 8.8, row: 4.2 }
});
Is there any updates??? I got the same error.
But I try as Anchor
, it seems worked.
Just encountered the same thing.
Minimal reproducible example:
import ExcelJS from "exceljs";
const createExcel = (image: string) => {
const workbook = new ExcelJS.Workbook();
const worksheet = workbook.addWorksheet("sheet1");
const imageId = workbook.addImage({
base64: image,
extension: "png",
});
worksheet.addImage(imageId, {
tl: { col: 0, row: 5 }, // type error here
br: { col: 0, row: 15 }, // type error here
});
};
The error:
Type '{ col: number; row: number; }' is missing the following properties from
type 'Anchor': nativeCol, nativeColOff, nativeRow, nativeRowOff, and 3 more.ts(2740)
The exports work without errors on my end with similar to above implementations though.
still no solution after 3 years?