-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG] Typescript error from getColumn.eachCell #1120
Comments
you have could you try do like below?: ws.getColumn(1).eachCell((cell, rowNum) => {
cell.fill = headerFill;
}); |
Sorry, there was a typo when copying the code. I checked and my code is like what you posted, and the TS error still shows. I have edited my original post to fix my code snippet. |
Sorry, is this in latest version of your library? Cause I currently have the same problem. Here is the code where I get error: const setColumnWidthForSheet = (ws: Worksheet) => {
for (let i = 0; i < ws.columns.length; i++) {
const column = ws.columns[i];
let dataMax = 0;
if (!column) {
continue;
} else {
column.eachCell({ includeEmpty: true }, (cell) => {
let columnLength = 0;
if (cell.value instanceof Date) {
columnLength = cell.value
.toISOString()
.slice(0, 10)
.replace(/-/g, '.').length;
} else {
columnLength = String(cell.value).length;
}
if (columnLength > dataMax) {
dataMax = columnLength;
}
});
column.width = dataMax < 10 ? 15 : dataMax + 8;
}
}
}; Also, I am using version ^4.2.1 |
@MetaMmodern You can try to use |
Ok, thank you, I'm gonna try it later.
|
@nywleswoey Sorry, the thing you provided does not work in runtime. The types are somehow broken. |
@MetaMmodern column number starts from 1. From your above code you will try to access column 0. |
Oopsie, my bad😅 |
No problem, glad to have been of help to you. |
🐛 Bug Report
Typescript error when using
Worksheet.getColumn().eachCell
-TS2722: Cannot invoke an object which is possibly 'undefined'.
Lib version: 3.8.0
Steps To Reproduce
Code example
The expected behaviour:
There should be no error.
Possible solution (optional, but very helpful):
Is it possible to clearly define the functions and properties that are available from
getColumn
?The text was updated successfully, but these errors were encountered: