Entire column data validation in exceljs for fixed length alphanumeric digits only - exceljs

I want to add validation in the entire column using excelJS in my LWC component. Below are my validation requirements:-
Text length entered in that column must be exactly 19 digits.
Text can be only alphanumeric.
I am not able to find the correct formulae for that to be inserted inside dataValidation. Please help me if anybody has anything. Thanks in advance.
const worksheet = workbook.addWorksheet('Sheet1');
worksheet.dataValidation.add(this.metadatRecords.Column_Range__c, {
type: 'custom',
allowBlank: false,
formulae: ['?'] // I need this to validate above requirements
error : "Please enter correct value",
errorStyle: 'error'
});

Related

Format cell in google sheet to number WITHOUT changing it

I have a kinda big google sheet. Around 20k rows. One of the cells in these rows contains always a 17 digit number. I automatically adding new rows via the google API with the nodeJS package (https://www.npmjs.com/package/google-spreadsheet).
Here is my problem, everything works fine if the last two digits in the number arent two zeros. If its 12345678912345678 then the "automatically" formating works fine. It shows it as it is and I can read it with the NodeJS package as it is.
But if its 12345678912345600 then its gets automatically converted to 1,23456E+16.
Now I want to convert it back to "normal". Thought kinda easy, just use format "text" and it should be displayed correctly. I dont care if its a number or a text, I can handle that on my side of the script. But formating it to text change the value of the cell to 1,23456E+16. Not what I want.
Okay, then convert it to a number, no problem. The normal default number formats doesnt fit (Since I dont want any . or , or decimal or anything, just the plain number. Custom number format it is. So I select custom number format and even the first example is what I want. So I select the format 0. Its just display the number without anything. Works exactly as I want.
Okay, lets do it for all of the 20k rows. I have roughly 1k rows with a double zero at the end. So I select the complete column, custom number format 0 and done?
Nope... Next problem. If you convert a number with more than 15 digits, every digit after the 15th digit get converted to 0. So I change all my other rows.
I could go and select all the affected one thousand rows by hand and just convert these rows, but yeah... one thousand rows...
Isnt there any way to convert these numbers just to display the number? Without changing it?
Try updating the format NUMBER to # to display the plain number:
A sample script:
const changeFormatNumber = async () => {
const auth = await getOAuthClient()
const sheet = google.sheets({ version: 'v4', auth })
const prop = await sheet.spreadsheets.batchUpdate({
spreadsheetId: '<SPREADSHEET_ID>',
requestBody: {
requests: [
{
repeatCell: {
fields: 'userEnteredFormat.numberFormat',
range: {
startRowIndex: 0,
startColumnIndex: 0,
endColumnIndex: 1,
endRowIndex: 100
},
cell: {
"userEnteredFormat": {
"numberFormat": {
"type": "NUMBER",
"pattern": "#"
}
}
}
},
}
]
}
})
console.log(prop)
}
Before:
After:
Documentation
Basic Formatting
Cell Data

Match function fails intermittently

In Google sheets, we are using a function which compares a column (B2:B62) of users who have submitted to a named range "staff". It return those who have not submitted in row J. This function doesn't work intermittently for sometimes 4-5 random users at a time, even though the spelling (and case) is correct. I have tried adjusting font and column data type, which have not worked. When I copy the form entered value and paste it in the named range "staff", the function works... Here is the code:
function Viewmissingsubmissions() {
var spreadsheet = SpreadsheetApp.getActive();
spreadsheet.getRange('J2').activate();
spreadsheet.getCurrentCell().setFormula('=filter(staff,isna(match(staff,B2:B62,0)))');
spreadsheet.getRange('J3').activate();
};
And here is the form at https://docs.google.com/forms/d/e/1FAIpQLSeAtzkp97LN-zKraccfremHJVetwp9s29RAOTAimHXSwqwMDQ/viewform
Thanks in advance for any insights!
Sincerely;
Bob Donaldson
Step by Step Child and Family center

Google sheets: How do I return a text value based on a column matching an entire range?

I need help returning a text value "WIP" based on column A matching an entire range.
The range has digits which users will input that match column A but cells will have more than 1 digit which will be seperated by a comma.
I'm not clear on how to do this so i'm stuck somewhere with:
Sumproduct, isnumber, and match yet i'm struggling how to yield a result.
Could you please help?
Thanks a lot!
Spreadsheet link: https://docs.google.com/spreadsheets/d/1XcIql3ZMymqipZsGUyBk3_ze6LMzjQtHTF-ylGDIT_A/edit#gid=0
Output highlighted in yellow
You can try:
=ArrayFormula(IF(Isnumber(MATCH(A9:A38,FLATTEN(SPLIT(FLATTEN(IF(LEN(G8:M18),G8:M18,)),",")),0)),"WIP",))

Google spreadsheet text length validation

I am working on Google spreadsheet. I am trying to make a validation rule on the text length.
For example the text length must be equal to 12 characters which includes number, on dash and one capital character.
Example:
123-56C89112
I tried to search in google groups but no result! can you help in this please
You can use Data > Validation > Custom Formula is
=REGEXMATCH(B3, "^(?=.{12}$)(?=(^[^A-Z]*[A-Z]{1}[^A-Z]*$))(?=(^[^-]*[-]{1}[^-]*$)).*")
I'm not an expert on Regex so this may be a bit over the top, but it appears to work:
^(?=.{12}$)(?=(^[^A-Z]*[A-Z]{1}[^A-Z]*$))(?=(^[^-]*[-]{1}[^-]*$)).*
Debuggex Demo
This allows any string with exactly 12 characters, 1 upper case letter and 1 dash.
EDIT: The (Lookahead) Regex doesn't seem to work in Spreadsheets (see comment)
EDIT2: Using a custom function like the following seems to work, but only if you use warnings (instead of rejections) for some reason (bug?)
function test(myString) {
return myString.match("^(?=.{12}$)(?=(^[^A-Z]*[A-Z]{1}[^A-Z]*$))(?=(^[^-]*[-]{1}[^-]*$)).*")!=null;
}

One maxlength for multiple text fields

Hi say I have two text fields. I want to have just one maxlength for both of them. Wherein, for example 300 is the maxlength. And that is for both text fields. Is it possible to have 1 maxlength for multiple fields?
Edit:
You will need to use jquery/javascript and client side validation. As a starting point
Something like
$('#text_field_1, #text_field_2').blur(function(){
if($('#text_field_1').val() + $('#text_field_2').val() > 300){
alert("Text Field max length has been reached");
}
});
Building on that example you'll want to have a listener on form submission $().submit that will return false, show an error message, and stop submitting the form if the max length is greater that allowed.

Resources