以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  [求助]打开excel异常  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=196047)

--  作者:lgj716330
--  发布时间:2025/3/25 15:08:00
--  [求助]打开excel异常

Dim s1 As String = DataTables("汇总表").GetComboListString("事业部")

s1 = s1.Replace("|", ",")

Dim s2 As String = DataTables("汇总表").GetComboListString("区经")

s2 = s2.Replace("|", ",")

Dim s3 As String = DataTables("汇总表").GetComboListString("核算方式")

s3 = s3.Replace("|", ",")

 

Dim App As New MSExcel.Application

App.Visible = True

Dim Wb As MSExcel.Workbook = App.WorkBooks.Open(fl)

For i As Integer = 1 To Book.Sheets.Count

    Dim Ws1 As MSExcel.WorkSheet = Wb.WorkSheets(i)

    With Ws1.Range("C1").Validation

        .Delete

        .Add(Type:=MSExcel.XlDVType.xlValidateList, AlertStyle:=MSExcel.XlDVAlertStyle.xlValidAlertStop, Operator:=MSExcel.XlFormatConditionOperator.xlBetween, Formula1:=s1)

    End With

    With Ws1.Range("E1").Validation

        .Delete

        .Add(Type:=MSExcel.XlDVType.xlValidateList, AlertStyle:=MSExcel.XlDVAlertStyle.xlValidAlertStop, Operator:=MSExcel.XlFormatConditionOperator.xlBetween, Formula1:=s2)

    End With

Next


上述提示以下错误,不知哪里问题


此主题相关图片如下:微信图片_20250325150748.png
按此在新窗口浏览图片


--  作者:有点蓝
--  发布时间:2025/3/25 15:15:00
--  
试试

    With Ws1.Range("C1").Validation

        .Delete

        .Add(MSExcel.XlDVType.xlValidateList, MSExcel.XlDVAlertStyle.xlValidAlertStop, MSExcel.XlFormatConditionOperator.xlNotBetween, s1)

    End With

        Ws1.Range("C1").Validation.IgnoreBlank = True

    With Ws1.Range("E1").Validation

        .Delete

        .Add(MSExcel.XlDVType.xlValidateList, MSExcel.XlDVAlertStyle.xlValidAlertStop, MSExcel.XlFormatConditionOperator.xlNotBetween, s2)

    End With

Ws1.Range("E1").Validation.IgnoreBlank = True


--  作者:lgj716330
--  发布时间:2025/3/25 18:35:00
--  
还是不行,不过奇怪的是,我原先弄的项目是没问题的,这个代码也是从原先项目中复制过来的,在新项目中就是有问题
--  作者:有点蓝
--  发布时间:2025/3/25 19:46:00
--  
那就不知道什么问题了,上传实例测试一下
--  作者:lgj716330
--  发布时间:2025/3/25 20:03:00
--  
晕,原来是下面档案数据没加载进来造成的
Dim s1 As String = DataTables("档案").GetComboListString("事业部")
s1 = s1.Replace("|", ",")