以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.net/bbs/index.asp)
--  专家坐堂  (http://foxtable.net/bbs/list.asp?boardid=2)
----  excel无法加密  (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=161341)

--  作者:rjh4078
--  发布时间:2021/3/13 21:05:00
--  excel无法加密
Dim lj As String=Functions.Execute("获取模板文件")
If lj<>"" Then
    Dim Book As New XLS.Book(lj)
    Dim Ifo As new FileInfo(lj)
    Dim sr As String
    sr=Ifo.Name.Replace(Ifo.Extension,"")
    lj=lj.Replace(sr,rwh)
    Dim fl As String =lj.Replace("Attachments","Reports")
    book.AddDataTable("gd","cderp","Sel ect * from {gd} a where gdno=\'" & rwh & "\'" )
    book.AddDataTable("gddd","cderp","Se lect * from {gddd} a  inner join " & _
    "(Sel ect gdno,加工type,QC要求,送货方式,包装方式,首件确认,制单人,审核人,gdtype from gd) b on a.gdno=b.gdno" & _
    " inner join  (sel ect 分支机构,khno as kh from cuinfo ) c on  c.kh=a.khno" & _
    " where a.gdno=\'" & rwh & "\'" )
    book.AddDataTable("gdysdetails","cderp","sel ect * from gdysdetails a left join (sel ect gdno,prid,材料count as 用料数 from gd用料明细) b on a.prid=b.prid and a.gdno=b.gdno " & _
    "  left join (sel ect guid,count as CTPcount from gdgx where gx=\'CTP\') d on  a.prid=d.guid  where  a.gdno=\'" & rwh & "\'")
    book.AddDataTable("gdgx","cderp","Sel ect * from {gdgx} a where gdno=\'" & rwh & "\'" )
    
    book.AddRelation("gd","gdno","gddd","gdno")
    book.AddRelation("gd","gdno","gdysdetails","gdno")
    book.AddRelation("gd","gdno","gdgx","gdno")
    
    Book.Build() \'生成细节区
    Book.Save(fl)
    
  Dim App As New MSExcel.Application
Dim Wb As MSExcel.WorkBook = App.WorkBooks.Open(fl)
Dim Ws As MSExcel.WorkSheet = Wb.WorkSheets(1)
Ws.Protect(Password:=Format(Date.now,"yyMMdd"))
Wb.Save
App.Visible = True

将报表生成好,单独使用加密代码也是无法加密:现象都是部分单元格加密,部分没加密,office版本是 office365.

Dim App As New MSExcel.Application
Dim Wb As MSExcel.WorkBook = App.WorkBooks.Open(ProjectPath & "reports\\订单.xlsx")
Dim Ws As MSExcel.WorkSheet = Wb.WorkSheets(1)
Ws.Protect(Password:="foxtabletest")

Wb.Save

App.Visible = True


[此贴子已经被作者于2021/3/13 21:19:34编辑过]

--  作者:有点蓝
--  发布时间:2021/3/14 20:20:00
--  
没有office365,安装的是office2013,测试没有问题。看明天用公司电脑试试