用下面的代码可以用,能在WorkSheets(1)的A1:A6里设置来自下拉框数据表省份列的内容。
Dim s As String = DataTables("下拉框数据").SQLGetComboListString("省份")
s = s.Replace("|",",")
Dim App As New MSExcel.Application
App.Visible = True
Dim Wb As MSExcel.Workbook = App.WorkBooks.Open("c:\test.xlsx")
Dim Ws As MSExcel.WorkSheet = Wb.WorkSheets(1)
With Ws.Range("A1:A6").Validation
.Delete
.Add(Type:=MSExcel.XlDVType.xlValidateList, AlertStyle:=MSExcel.XlDVAlertStyle.xlValidAlertStop, Operator:=MSExcel.XlFormatConditionOperator.xlBetween, Formula1:=s)
End With
也可以用下面这一段:
Dim s As String = DataTables("下拉框数据").SQLGetComboListString("省份")
s = s.Replace("|",",")
Dim App As New MSExcel.Application
App.Visible = True
Dim Wb As MSExcel.Workbook = App.WorkBooks.Add
Wb.WorkSheets(1).name = "hhh" ‘ 为工作表起名为hhh
Dim Ws As MSExcel.WorkSheet = Wb.WorkSheets(1)
With Ws.Range("A1:A6").Validation
.Delete
.Add(Type:=MSExcel.XlDVType.xlValidateList, AlertStyle:=MSExcel.XlDVAlertStyle.xlValidAlertStop, Operator:=MSExcel.XlFormatConditionOperator.xlBetween, Formula1:=s)
End With
Wb.SaveAs("d:\123.xlsx")
[此贴子已经被作者于2019/10/21 13:32:31编辑过]