以文本方式查看主题

-  Foxtable(狐表)  (http://www.foxtable.com/bbs/index.asp)
--  专家坐堂  (http://www.foxtable.com/bbs/list.asp?boardid=2)
----  [求助]打开excel异常  (http://www.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("|", ",")

--  作者:lgj716330
--  发布时间:2025/4/13 12:39:00
--  
Dim s1 As String = DataTables("店铺利润汇总二").GetComboListString("事业部")
s1 = s1.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)
    If s1.Length > 0 Then
        With Ws1.Range("S1").Validation
            .Delete
            .Add(Type:=MSExcel.XlDVType.xlValidateList, AlertStyle:=MSExcel.XlDVAlertStyle.xlValidAlertStop, Operator:=MSExcel.XlFormatConditionOperator.xlBetween, Formula1:=s1)
        End With
    End If
next

在excel模板中插入序列,在项目中打开没有任何问题,但另存为本地文件的时候,打开就会出现异常,然后序列就会被清除,这会是什么原因呢

--  作者:有点蓝
--  发布时间:2025/4/13 20:17:00
--  
我也不知道哦
--  作者:lgj716330
--  发布时间:2025/4/21 21:28:00
--  
点击按钮打开excel文件时,很长时间后跳出以下问题,如何解决

图片点击可在新窗口打开查看此主题相关图片如下:微信图片_20250421212557.jpg
图片点击可在新窗口打开查看


--  作者:有点蓝
--  发布时间:2025/4/21 22:02:00
--  
提示读写数据库的问题。是不是放到了异步函数里使用的?
--  作者:lgj716330
--  发布时间:2025/4/22 8:37:00
--  
我是生成数据和打开excel分开两个按钮执行的,只是打开excel的时候有问题,打开excel的代码就下面这么简单

Dim Book As New XLS.Book(ProjectPath & "Attachments\\A3.xlsx")
Dim fl As String = ProjectPath & "Reports\\A3.xlsx"
Book.Build() 
Book.Save(fl)

Dim Proc As New Process
Proc.File = fl
Proc.Start()