exceljs icon indicating copy to clipboard operation
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.

Open jakehockey10 opened this issue 3 years ago • 8 comments

🐛 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: image

I get the following errors and cannot build because the interface requires all properties to be present.

image

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>

jakehockey10 avatar Jun 16 '21 16:06 jakehockey10

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})
});

jakehockey10 avatar Jun 16 '21 16:06 jakehockey10

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';

jakehockey10 avatar Jun 16 '21 16:06 jakehockey10

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.

mjiskinng avatar Jul 24 '21 10:07 mjiskinng

So far? To not write this code.

I was really hoping I'd get a response. But I have no solution to this

jakehockey10 avatar Jul 24 '21 14:07 jakehockey10

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 }
});

rob4226 avatar Aug 18 '21 06:08 rob4226

Is there any updates??? I got the same error. WX20230320-111111@2x

But I try as Anchor, it seems worked.

WX20230320-140417@2x

Emiya0306 avatar Mar 20 '23 06:03 Emiya0306

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.

sjobergjim avatar Jan 25 '24 11:01 sjobergjim

still no solution after 3 years?

Ks89 avatar Feb 23 '24 16:02 Ks89