0

我想在创建 Excel 文件 (xlsx) 时使用 .NET EPPlus 库根据数据所在的不同工作表中的数据列表(未知计数)创建一个动态列表。我怎样才能做到这一点?

Manual workflow in Excel 2007:
1.) click on sheet2 (dropdowns worksheet)
2.) add some data from cell A2:A4
3.) click on sheet1 (data worksheet) > highlight cells in some column > Data (menu) > Data Validation > Data Validation > Allow: List, Source: ='sheet2'!$A$2:$A$4 > click 'OK'
4

1 回答 1

1

希望这会有所帮助。有关数据验证的更多详细示例,请从 codeplex 下载 EPPlus 示例应用程序并查看示例 11。

// add a validation and set values
        var validation = sheet.DataValidations.AddListValidation("A1");
        // Alternatively:
        // var validation = sheet.Cells["A1"].DataValidation.AddListDataValidation();
        validation.ShowErrorMessage = true;
        validation.ErrorStyle = ExcelDataValidationWarningStyle.warning;
        validation.ErrorTitle = "An invalid value was entered";
        validation.Error = "Select a value from the list";
        validation.Formula.ExcelFormula = "B2:B4";
于 2012-07-01T06:52:48.747 回答