1

以下のコードを使用して、セルでドロップダウンを取得できます

               Interop.Range validationAddressRange = ws.Worksheet.get_Range(startAddress, endAddress);
                validationAddressRange.Select();
                validationAddressRange.Cells.Validation.Delete();
                validationAddressRange.Cells.Validation.Add(Type: Interop.XlDVType.xlValidateList, 
                AlertStyle: Interop.XlDVAlertStyle.xlValidAlertStop, Formula1: formula);
                validationAddressRange.Cells.Validation.IgnoreBlank = true;
                validationAddressRange.Cells.Validation.InCellDropdown = true;
                validationAddressRange.Cells.Validation.ErrorMessage = "Invalid entry. Click 'Retry' to update the cell value, or 'Cancel' to undo the change made to the cell.";
                validationAddressRange.Cells.Validation.ErrorTitle = "Invalid Data Error";
                validationAddressRange.Cells.Validation.ShowError = true;
                ws.Worksheet.Cells[1,1].Select(); //selects the top-leftmost cell since excel doesn't furnish a de-select option.

通常の Windows フォーム コンボボックスと同じように、イベントを関連付けてオートコンプリート機能を使用する方法を知っている人はいますか?

4

1 に答える 1

2

ここで、これを解決しようとしました。わたしにはできる。

var list = new System.Collections.Generic.List<string>();
list.Add("RFP");
list.Add("2nd Review");
list.Add("RESHOOT");
var flatList = string.Join(", ", list.ToArray());

var cell = (Microsoft.Office.Interop.Excel.Range)oSheet.Cells.get_Range("B1");;
cell.Validation.Delete();
cell.Validation.Add( XlDVType.xlValidateList,
    XlDVAlertStyle.xlValidAlertInformation,
    XlFormatConditionOperator.xlBetween,
    flatList,
    Type.Missing);

ここでは、最初から最後まで、セルを残さずに連続してセルを埋める場合に機能します。真ん中のセルを埋める場合。効果がないでしょう。

于 2014-09-11T07:45:47.850 に答える