如何使用spreadsheetgear在excel中添加下拉列表?

发布于 2024-12-28 00:45:49 字数 45 浏览 1 评论 0原文

我想在 Excel 工作表的一列中添加下拉列表。如何使用电子表格添加它???

I want to add drop down list in one of column of Excel sheet. How to add it using spreadsheetgear????

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

深海夜未眠 2025-01-04 00:45:49

如果您尝试将单元格数据验证下拉列表添加到列中,则可以使用 SpreadsheetGear.IValidation 接口(可从 IRange.Validation 属性获取)来执行此操作。我在下面提供了一些示例代码,演示了如何构建两列数据验证。 B 列从同一张纸上的一系列单元格中提取其下拉项; C 列从静态值列表中提取其下拉项。

// Create workbook and a local variable to Cells
IWorkbook workbook = Factory.GetWorkbook();
IRange cells = workbook.ActiveWorksheet.Cells;
// Build up some data to use in our validation list
cells["A1:A5"].Value = "=ROUND(RAND()*100, 0)";
// Create cell validation on Column B using values from other cells
cells["B:B"].Validation.Add(SpreadsheetGear.ValidationType.List, ValidationAlertStyle.Information, ValidationOperator.Default, "=$A$1:$A$5", "");
// Create cell validation on Column C using a static list
cells["C:C"].Validation.Add(SpreadsheetGear.ValidationType.List, ValidationAlertStyle.Information, ValidationOperator.Default, "a,b,c", "");

注意:我在 SpreadsheetGear 工作,为我们产品的客户和评估者提供技术帮助。如果您还有其他问题,请随时通过[电子邮件受保护]与我们联系。

If you are trying to add a cell Data Validation dropdown list to a column, you can do this using the SpreadsheetGear.IValidation interface, available from the IRange.Validation property. I’ve provided some sample code below that demonstrates building two columns of data validation. Column B pulls its dropdown items from a range of cells on the same sheet; Column C pulls its dropdown items from a static list of values.

// Create workbook and a local variable to Cells
IWorkbook workbook = Factory.GetWorkbook();
IRange cells = workbook.ActiveWorksheet.Cells;
// Build up some data to use in our validation list
cells["A1:A5"].Value = "=ROUND(RAND()*100, 0)";
// Create cell validation on Column B using values from other cells
cells["B:B"].Validation.Add(SpreadsheetGear.ValidationType.List, ValidationAlertStyle.Information, ValidationOperator.Default, "=$A$1:$A$5", "");
// Create cell validation on Column C using a static list
cells["C:C"].Validation.Add(SpreadsheetGear.ValidationType.List, ValidationAlertStyle.Information, ValidationOperator.Default, "a,b,c", "");

Note: I work at SpreadsheetGear and provide technical assistance for customers and evaluators of our product. Feel free to contact us at [email protected] if you have additional questions.

夕色琉璃 2025-01-04 00:45:49

您可以使用单元格验证。它的工作方式与 Excel 中的操作方式类似。

private void CreateList(SpreadsheetGear.IRange cell, string list)
{
  cell.Validation.Add(
        SpreadsheetGear.ValidationType.List,
        SpreadsheetGear.ValidationAlertStyle.Warning,
        SpreadsheetGear.ValidationOperator.Default,
        list, null);
}

在 Windows 窗体程序中,您可以这样称呼它:

workbookView1.GetLock();
try
{
  SpreadsheetGear.IRange cell =workbookView1.ActiveWorksheet.Cells["A1"];
  CreateList(cell, "Alabama,Alaska,Arizona,Arkansas,California,Colorado,Connecticut,Delaware,Florida");
}
finally
{
  workbookView1.ReleaseLock();
}

You can use cell Validation. It works similarly to how you do it in Excel.

private void CreateList(SpreadsheetGear.IRange cell, string list)
{
  cell.Validation.Add(
        SpreadsheetGear.ValidationType.List,
        SpreadsheetGear.ValidationAlertStyle.Warning,
        SpreadsheetGear.ValidationOperator.Default,
        list, null);
}

In a windows forms program, you would call it something like this:

workbookView1.GetLock();
try
{
  SpreadsheetGear.IRange cell =workbookView1.ActiveWorksheet.Cells["A1"];
  CreateList(cell, "Alabama,Alaska,Arizona,Arkansas,California,Colorado,Connecticut,Delaware,Florida");
}
finally
{
  workbookView1.ReleaseLock();
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文