softwaredeveloper
Microsoft.Office.Interop.Excel.Application excel=new Microsoft.Office.Interop.Excel.Application();

Microsoft.Office.Interop.Excel.Workbooks workbooks=excel.Workbooks;
Microsoft.Office.Interop.Excel.Workbook workbook=Workbooks.Add
(Microsoft.Office.Interop.Excel.XlWBATemplate.xlWBATWorksheet);
Microsoft.Office.Interop.Excel.WorkSheet workSheet=
(Microsoft.Office.Interop.Excel.Worksheet) workbook.Worksheets[1];
((Microsoft.Office.Interop.Excel.Range Range_Col=(Microsoft.Office.Interop.Excel.Range)   
worksheet.Columns.get_Item(1,Type.Missing);
//加载下拉列表内容
string Name=GetName(DataTable);//查出的DataTable

Range_Col.Validation.Add(Microsoft.Office.Interop.Excel.XlDVType.xlValidateList,Microsoft.Office.Interop.Excel.XlDVAlertStyle.xlValidAlertStop,
Microsoft.Office.Interop.Excel.XlFormatConditionOperator.xlBetween,Name,Type.Missing);//Name就是上面获取的列表

private string GetName(DataTable dt)
{
    var list=dt.AsEnumerable().Select(t=>t.Field<string>("Name")).ToList();
    return string.Join(",",list.ToArray());  
}
  

 

分类:

技术点:

相关文章:

  • 2021-12-04
  • 2021-12-22
  • 2021-08-18
  • 2021-10-20
  • 2022-12-23
  • 2021-05-17
  • 2022-12-23
  • 2021-07-17
猜你喜欢
  • 2021-09-17
  • 2022-12-23
  • 2021-10-25
  • 2022-02-01
  • 2022-12-23
  • 2021-12-03
相关资源
相似解决方案