2012-01-20 30 views

回答

6

如果您嘗試將單元格數據驗證下拉列表添加到列中,可以使用可從IRange.Validation屬性獲取的SpreadsheetGear.IValidation接口執行此操作。我在下面提供了一些示例代碼,演示瞭如何構建兩列數據驗證。 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併爲客戶提供我們的產品的評估技術援助。如果您有其他問題,請隨時通過[email protected]與我們聯繫。

+0

感謝名單安德森,對於再次保存時間me.once感謝名單了很多提供的信息 – kumar

2

您可以使用單元驗證。它的工作方式與您在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(); 
} 
相關問題