使用 ClosedXML 设置单元格的文本长度
Set Text Length of Cell using ClosedXML
我想知道如何使用 ClosedXML 设置 Excel 工作表中单元格的文本长度。我怀疑 XLTextLengthCriteria 可能会有帮助。我阅读了 ClosedXML 的文档,但没有找到具体答案。任何帮助将不胜感激。
为了验证,您可以像这样设置文本长度:
worksheet.Cell(1,1).SetDataValidation().TextLength.EqualOrLessThan(10);
要获得完整的专栏,请使用:
worksheet.Column(1).AsRange().SetDataValidation().TextLength.EqualOrLessThan(10);
检查这个解决方案
注意 ErrorStyle 和 ErrorTitle 是可选的
worksheet.Range("A1", "A1").SetDataValidation().TextLength.EqualOrGreaterThan(5);
worksheet.Range("A1", "A1").SetDataValidation().ErrorStyle = ClosedXML.Excel.XLErrorStyle.Stop;
//XLErrorStyle.Stop will prevent adding data,
//XLErrorStyle.Information will show hint,
//XLErrorStyle.Warning will let user choose to continue or not
worksheet.Range("A1", "A1").SetDataValidation().ErrorTitle = "Text Length should be greater than 4 charachters";
我想知道如何使用 ClosedXML 设置 Excel 工作表中单元格的文本长度。我怀疑 XLTextLengthCriteria 可能会有帮助。我阅读了 ClosedXML 的文档,但没有找到具体答案。任何帮助将不胜感激。
为了验证,您可以像这样设置文本长度:
worksheet.Cell(1,1).SetDataValidation().TextLength.EqualOrLessThan(10);
要获得完整的专栏,请使用:
worksheet.Column(1).AsRange().SetDataValidation().TextLength.EqualOrLessThan(10);
检查这个解决方案
注意 ErrorStyle 和 ErrorTitle 是可选的
worksheet.Range("A1", "A1").SetDataValidation().TextLength.EqualOrGreaterThan(5);
worksheet.Range("A1", "A1").SetDataValidation().ErrorStyle = ClosedXML.Excel.XLErrorStyle.Stop;
//XLErrorStyle.Stop will prevent adding data,
//XLErrorStyle.Information will show hint,
//XLErrorStyle.Warning will let user choose to continue or not
worksheet.Range("A1", "A1").SetDataValidation().ErrorTitle = "Text Length should be greater than 4 charachters";