Skip to content

Commit

Permalink
Upstream feature: ass ISheet.RemoveValidationData method and implemen…
Browse files Browse the repository at this point in the history
…t it in HSSF, XSSF and SXSSF Sheets
  • Loading branch information
Artem Koloskov committed Feb 9, 2024
1 parent 73daa01 commit 8e4b633
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 2 deletions.
14 changes: 14 additions & 0 deletions main/HSSF/UserModel/HSSFSheet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,20 @@ public void AddValidationData(IDataValidation dataValidation)
dvt.AddDataValidation(dvRecord);
}

public void RemoveValidationData(IDataValidation dataValidation)
{
if (dataValidation == null)
{
throw new ArgumentException("objValidation must not be null");
}

HSSFDataValidation hssfDataValidation = (HSSFDataValidation)dataValidation;
DataValidityTable dvt = _sheet.GetOrCreateDataValidityTable();

DVRecord dvRecord = hssfDataValidation.CreateDVRecord(this);
dvt.RemoveDataValidation(dvRecord);
}

/// <summary>
/// Get the visibility state for a given column.F:\Gloria\�о�\�ļ���ʽ\NPOI\src\NPOI\HSSF\Util\HSSFDataValidation.cs
/// </summary>
Expand Down
8 changes: 7 additions & 1 deletion main/SS/UserModel/Sheet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -840,6 +840,12 @@ bool Autobreaks
/// <param name="dataValidation">The data validation object settings</param>
void AddValidationData(IDataValidation dataValidation);

/// <summary>
/// Removes a data validation object
/// </summary>
/// <param name="dataValidation">The data validation object settings</param>
void RemoveValidationData(IDataValidation dataValidation);

/// <summary>
/// Enable filtering for a range of cells
/// </summary>
Expand Down Expand Up @@ -947,4 +953,4 @@ bool Autobreaks

void CopyTo(IWorkbook dest, string name, bool copyStyle, bool keepFormulas);
}
}
}
7 changes: 6 additions & 1 deletion ooxml/XSSF/Streaming/SXSSFSheet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -495,11 +495,16 @@ public void ValidateMergedRegions() {
_sh.ValidateMergedRegions();
}


public void AddValidationData(IDataValidation dataValidation)
{
_sh.AddValidationData(dataValidation);
}

public void RemoveValidationData(IDataValidation dataValidation)
{
_sh.RemoveValidationData(dataValidation);
}

/**
* Adjusts the column width to fit the contents.
*
Expand Down
24 changes: 24 additions & 0 deletions ooxml/XSSF/UserModel/XSSFSheet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3326,7 +3326,31 @@ public void AddValidationData(IDataValidation dataValidation)
CT_DataValidation newval = dataValidations.AddNewDataValidation();
newval.Set(xssfDataValidation.GetCTDataValidation());
dataValidations.count = (uint)currentCount + 1;
}

public void RemoveValidationData(IDataValidation dataValidation)
{
XSSFDataValidation xssfDataValidation = (XSSFDataValidation)dataValidation;
CT_DataValidations dataValidations = worksheet.dataValidations;

if (dataValidations is null)
{
return;
}

int currentCount = dataValidations.sizeOfDataValidationArray();

for (int i = 0; i < currentCount; i++)
{
CT_DataValidation ctDataValidation = dataValidations.dataValidation[i];

if (ctDataValidation.Equals(xssfDataValidation.GetCTDataValidation()))
{
dataValidations.dataValidation.RemoveAt(i);
dataValidations.count = (uint)currentCount - 1;
return;
}
}
}

public IAutoFilter SetAutoFilter(CellRangeAddress range)
Expand Down

0 comments on commit 8e4b633

Please sign in to comment.