本文整理汇总了C#中ISheet.GetDataValidationHelper方法的典型用法代码示例。如果您正苦于以下问题:C# ISheet.GetDataValidationHelper方法的具体用法?C# ISheet.GetDataValidationHelper怎么用?C# ISheet.GetDataValidationHelper使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ISheet
的用法示例。
在下文中一共展示了ISheet.GetDataValidationHelper方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PutNamesWithValidations
private void PutNamesWithValidations(ISheet ws, ICellStyle cs1, ICellStyle cs2, ICellStyle cs3, params string[][] names)
{
var rn0 = ws.PhysicalNumberOfRows;
var rn = rn0;
for (var i = 0; i < names.Length; ++i)
{
var rnc = rn++;
var r = ws.CreateRow(rnc);
if (1 < names[i].Length)
{
r.RowStyle = cs3;
var vh = ws.GetDataValidationHelper();
var vl = names[i].Skip(1).ToList();
vl.Sort();
var vd = vh.CreateValidation(
vh.CreateExplicitListConstraint(vl.ToArray()),
new CellRangeAddressList(rnc, rnc, 1, _excelVer.LastColumnIndex)
);
vd.ShowErrorBox = false;
vd.ShowPromptBox = true;
ws.AddValidationData(vd);
}
var c = r.CreateCell(0);
c.SetCellValue(names[i][0]);
if (0 == i)
{
c.CellStyle = cs1;
r.RowStyle = cs1;
}
else
{
c.CellStyle = cs2;
}
}
if (1 < names.Length) ws.GroupRow(rn0 + 1, rn - 1);
//ws.SetRowGroupCollapsed(rn0 + 1, true);
ws.AddMergedRegion(new CellRangeAddress(rn0, rn0, 0, _excelVer.LastColumnIndex));
}
示例2: buildTemplateSheet
private static void buildTemplateSheet(IWorkbook workbook, ISheet sheet, ISheet sheetDS, List<WFActivityField> fields, ref int dsStartIndex, int sheetIndex)
{
if (fields != null)
{
IRow rowColumn = sheet.CreateRow(0);
for (int i = 0; i < fields.Count; i++)
{
ICell cell = rowColumn.CreateCell(i);
string colName = String.IsNullOrWhiteSpace(fields[i].DisplayName) ? fields[i].FieldName : fields[i].DisplayName;
cell.SetCellValue(colName);
ICellStyle cellStyle = workbook.CreateCellStyle();
if (fields[i].IsRequired)
{
cellStyle.FillForegroundColor = IndexedColors.Yellow.Index;
}
else
{
cellStyle.FillForegroundColor = IndexedColors.Grey25Percent.Index;
}
cellStyle.FillPattern = FillPattern.SolidForeground;
cell.CellStyle = cellStyle;
sheet.AutoSizeColumn(i);
switch (fields[i].DataType)
{
case FieldInfo.DATATYPE_LIST:
case FieldInfo.DATATYPE_LIST_SQL:
string lstFormulaName = fields[i].FieldName + "fn";
int dsEndIndex = BuildDataSource(fields[i], sheetDS, dsStartIndex);
if (dsEndIndex > dsStartIndex)
{
IName name = sheet.Workbook.CreateName();
name.RefersToFormula = String.Format("'DataSource'!$A${0}:$A${1}", dsStartIndex + 1, dsEndIndex);
name.NameName = lstFormulaName;
name.SheetIndex = sheetIndex;
CellRangeAddressList addressList = new CellRangeAddressList(1, 1, i, i);
IDataValidationHelper dvHelper = sheet.GetDataValidationHelper();
IDataValidationConstraint dvConstraint = dvHelper.CreateFormulaListConstraint(lstFormulaName);
IDataValidation validation = dvHelper.CreateValidation(dvConstraint, addressList);
sheet.AddValidationData(validation);
dsStartIndex = dsEndIndex;
}
break;
}
}
}
}