Skip to content

Commit

Permalink
Merge pull request #1161 from habx/feature/APP-24270
Browse files Browse the repository at this point in the history
APP-24270: Try to fix invalid validation length
  • Loading branch information
habxtech authored Oct 15, 2021
2 parents 07d31ed + 028f1c0 commit 68c8019
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/imex/excel.utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type * as Excel from 'exceljs'
import { escape, snakeCase, capitalize } from 'lodash'

import { palette } from '@habx/ui-core'

Expand Down Expand Up @@ -106,6 +107,38 @@ export const applyValidationRulesAndStyle = <D extends {}>(
if (rowNumber > 1 && cell) {
if (dataValidation) {
cell.dataValidation = dataValidation
/*
* Manage large cell validation
* https://github.com/exceljs/exceljs/issues/667
*/
if (
dataValidation.type === 'list' &&
dataValidation.formulae.some((f) => f.length > 255)
) {
const worksheetName = capitalize(
snakeCase(escape(`${column.Header}`))
)
const validationValuesWorksheet = worksheet.workbook.addWorksheet(
worksheetName
)
dataValidation.formulae.forEach((f, listColumnIndex) => {
const list: string[] = f.replace(/"/g, '').split(',')
list.forEach((listEl, rowIndex) => {
validationValuesWorksheet.getCell(
rowIndex + 1,
listColumnIndex + 1
).value = listEl
})
const columnLetter = String.fromCharCode(
'A'.charCodeAt(0) + listColumnIndex
)
dataValidation.formulae[
listColumnIndex
] = `${worksheetName}!$${columnLetter}$1:$${columnLetter}$${
list.length + 1
}`
})
}
}
if (isIdentifer && !!cell.value) {
cell.protection = {
Expand Down

0 comments on commit 68c8019

Please sign in to comment.