Skip to content
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

Excel in-cell dropdown #1665

Open
hansie-the-quorum opened this issue Feb 9, 2024 · 4 comments
Open

Excel in-cell dropdown #1665

hansie-the-quorum opened this issue Feb 9, 2024 · 4 comments
Assignees

Comments

@hansie-the-quorum
Copy link

hansie-the-quorum commented Feb 9, 2024

I have this code below. The purpose of this code is to set very specific cell's to have drop down values. Not all cells in the column must have this dropdown and the data types differ for each cell.

This works fine and excel is created.

The issue here is that in Excel, for each cell that have a dropdown applied you need to:

  1. Select the cell
  2. Select the "Data" tab
  3. Select "Data Validation"
  4. Check the "in-cell dropdown" checkbox
    before the cell have a drop down option

This code was developed using several sources to try and resolve the issue, and all of the sources advise more or less the same code

if (data.ApplyLookup(x, rowIndex))
{
	string columnName = GetExcelColumnName(x + 1);
	
	DataValidation dataValidation = new DataValidation
	{
		Type = DataValidationValues.List,
		ShowDropDown = true,
		AllowBlank = true,
		SequenceOfReferences = new ListValue<StringValue> { InnerText = $"{columnName}{rowIndex}" }
	};
	
	string lookupString = $"\"{string.Join(",", data.LookupValues[x].Select(kv => kv.Value))}\"";
	dataValidation.Formula1 = new Formula1(lookupString);
	
	dataValidations.Append(dataValidation);
}
@mikeebowen
Copy link
Collaborator

Hi @hansie-the-quorum, Can you give some more detail about your issue? Does the code you posted not work or is the issue something else?

@hansie-the-quorum
Copy link
Author

hansie-the-quorum commented Feb 12, 2024 via email

@mikeebowen
Copy link
Collaborator

Hi @hansie-the-quorum, There appears to be an issue with ShowDropDown = true. As a workaround, remove that line and do not set the ShowDropDown value and it will work. This is not the expected behavior and requires further investigation, but this will resolve the issue.

if (data.ApplyLookup(x, rowIndex))
{
	string columnName = GetExcelColumnName(x + 1);
	
	DataValidation dataValidation = new DataValidation
	{
		Type = DataValidationValues.List,
		// ShowDropDown = true, // Do not set this property.
		AllowBlank = true,
		SequenceOfReferences = new ListValue<StringValue> { InnerText = $"{columnName}{rowIndex}" }
	};
	
	string lookupString = $"\"{string.Join(",", data.LookupValues[x].Select(kv => kv.Value))}\"";
	dataValidation.Formula1 = new Formula1(lookupString);
	
	dataValidations.Append(dataValidation);
}

@mikeebowen mikeebowen self-assigned this Feb 13, 2024
@hansie-the-quorum
Copy link
Author

hansie-the-quorum commented Feb 15, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants