以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.net/bbs/index.asp)
--  专家坐堂  (http://foxtable.net/bbs/list.asp?boardid=2)
----  [求助] 批量锁行  (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=144754)

--  作者:sanny
--  发布时间:2019/12/28 20:06:00
--  [求助] 批量锁行

老师,你好,

麻烦帮忙看一下以下代码,最后一句不够准确,当运行完成,只锁住当前一行记录。想要锁住打印出来的所有记录。麻烦了。

 


Dim Book As New XLS.Book(ProjectPath & "Attachments\\trading shipping mark.xlsx")
Dim fl As String = ProjectPath & "trading\\"&Tables("packinglist_t").current("shippingNo")&"\\Box\\"& "ShippingNo_"& Tables("packinglist_t").current("shippingNo") & "  BoxNo_" &Tables("packinglist_t").current("boxno") & ".xlsx" 
 

Dim Result As DialogResult

Dim Proc As New Process \'打开工作簿

Dim r1 As Row = Nothing
Dim cn1 As Integer = 0
Dim cn2 As Double = 0
Dim cn3 As Double = 0

For i As Integer = 0 To Tables("packinglist_t").Rows.Count - 1

    Dim r As Row = Tables("packinglist_t").Rows(i)
    If r("boxno") = r.Table.current("boxno") AndAlso (r1 Is Nothing OrElse r("ShippingNo") & r("BoxNo") <> r1("ShippingNo") & r1("BoxNo"))
        cn1 += 1
        cn2 += r("Volume_CBM")
        cn3 += r("Gross_weight")

        r1 = r
    End If
Next


vars("总箱数") = cn1
vars("总立方") = cn2
vars("总毛重") = cn3

Dim Sheet As XLS.Sheet = Book.Sheets(0)

If Tables("packinglist_t").current("boxno") = Nothing
    sheet(5,14).value = "<BoxNo is null and (customer <> \'CWA\' or customer is null)>"   \'客户不是CWA才打印
Else
    sheet(5,14).value = "<BoxNo=\'" & Tables("packinglist_t").current("boxno") & "\' and (customer <> \'CWA\' or customer is null)>"   \'客户不是CWA才打印
End If


Book.Build() \'生成细节区

sheet = Book.Sheets(0)

If FileSys.FileExists(ProjectPath & "trading\\"&Tables("packinglist_t").current("shippingNo")&"\\Box\\"& "ShippingNo_"& Tables("packinglist_t").current("shippingNo") & "  BoxNo_" &Tables("packinglist_t").current("boxno") & ".xlsx")  Then
    Result = Messagebox.Show(Tables("packinglist_t").current("shippingNo") & "  BoxNo_" &Tables("packinglist_t").current("boxno") & ".xlsx"&" 文件已经存在,是否要覆盖?","提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
    If Result = DialogResult.Yes Then
       
         Book.Save(fl) \'保存工作簿
        Proc.File = fl
        Proc.Start()

      End If
Else
Book.Save(fl) \'保存工作簿
Proc.File = fl
Proc.Start()

End If

Tables("Packinglist_t").current.locked = True


--  作者:wei0769
--  发布时间:2019/12/29 13:35:00
--  

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

--  作者:susanhe
--  发布时间:2019/12/29 18:28:00
--  

 

[此贴子已经被作者于2019/12/29 18:34:06编辑过]

--  作者:sanny
--  发布时间:2019/12/29 18:36:00
--  

如图,我有合并单元格的。这些打印在一起后要一起锁定。
图片点击可在新窗口打开查看此主题相关图片如下:捕获.jpg
图片点击可在新窗口打开查看

以下代码是正确的,不过要全部选定后,会锁定。我想只要任意点选其中一条就可以全部锁定。

 

With Tables("Packinglist")
For i As Integer = .Topposition To .bottomposition

.Rows(i).locked = True
Next
End With


[此贴子已经被作者于2019/12/29 18:36:40编辑过]

--  作者:有点蓝
--  发布时间:2019/12/29 20:09:00
--  

……

vars("总箱数") = cn1
vars("总立方") = cn2
vars("总毛重") = cn3

Dim Sheet As XLS.Sheet = Book.Sheets(0)

dim filter as string = ""

If Tables("packinglist_t").current("boxno") = Nothing
    filter  = "<BoxNo is null and (customer <> \'CWA\' or customer is null)>"   \'客户不是CWA才打印
Else
    filter  = "<BoxNo=\'" & Tables("packinglist_t").current("boxno") & "\' and (customer <> \'CWA\' or customer is null)>"   \'客户不是CWA才打印
End If

sheet(5,14).value = filter 

……

Book.Save(fl) \'保存工作簿
Proc.File = fl
Proc.Start()

End If

DataTables("packinglist_t").ReplaceFor("_locked",true,filter)


--  作者:sanny
--  发布时间:2019/12/29 20:27:00
--  
老师,出现了这个错误了。
图片点击可在新窗口打开查看此主题相关图片如下:捕获.jpg
图片点击可在新窗口打开查看

--  作者:有点蓝
--  发布时间:2019/12/29 20:34:00
--  

dim filter as string = ""

If Tables("packinglist_t").current("boxno") = Nothing
    filter  = "BoxNo is null and (customer <> \'CWA\' or customer is null)"   \'客户不是CWA才打印
Else
    filter  = "BoxNo=\'" & Tables("packinglist_t").current("boxno") & "\' and (customer <> \'CWA\' or customer is null)"   \'客户不是CWA才打印
End If

sheet(5,14).value = "<" & filter & ">"