介绍一个PB直接读 .xlsx 的方法

.xlsx 实际上是ZIP格式文件,完全可以当作 ZIP 文件来处理。

然后直接用 uo_zip 解压它为指定文件,或者直接当作 blob 读出来,都可以。

在各PB群里,找到我的 PB_Json_httpclient_crypto_ftp_xxxxxx.rar 包,里面有个 uo_zip 对象。

1. 打开它:zip.open("c:\temp\Book1.xlsx",false,"")

2.zip 事件 ue_open 里读列表

//取出ZIP文件里的列表
long index[]
string strName[]
long fileSize[]
long fileSizeComp[]
string crc[]
string strDateTime[]
boolean encrypted[]
long ll_count,i
long ll_filecount,ll_dircount
string ls_text
ll_count = zip.GetEntryList(ref index[],ref strName[],ref fileSize[],ref fileSizeComp[],ref crc[],ref strDateTime[],ref encrypted[])
if ll_count = 0 then
    blob data
    data = blob("欢迎使用uo_zip对象.大自在2020/5/1")
    zip.add("hello",data)
end if
ls_text = "序号  大小      压缩大小   CRC码    修改时间             加密~t文件名~r~n"
for i = 1 to ll_count
    ls_text += zip.FormatNumber("%-6d",index[i])// + "~t"
    ls_text += zip.FormatNumber("%-10d",fileSize[i])// + "~t"
    ls_text += zip.FormatNumber("%-10d",fileSizeComp[i])// + "~t"
    ls_text += string(CRC[i]) + " "
    ls_text += string(strDateTime[i]) + " "
    ls_text += string(Encrypted[i]) + "~t"
    ls_text += string(strName[i])
    if right(strName[i],1) = "/" then
        ll_dircount ++
    else
        ll_filecount++
    end if
    ls_text += "~r~n"
next
mle_1.text = ls_text + "~t~t~t~t~t~t~t" + string(ll_filecount) + "个文件 , " + string(ll_dircount) + "个目录~r~n"

3.剩下 的,你可以以 blob 方式把相关文件读出来

blob data1,data2
data1 = zip.readBlob(1) //按索引号读
data2 = zip.readBlob("hello") //按名称读

或者解压出来

long ll_count
ll_count = zip.extract("d:\temp\myzip",1) //按索引号解压
mle_2.text =  mle_2.text + "已解压 " + string(ll_count) + " 个文件" + "~r~n"
 

long ll_count
ll_count = zip.extract("d:\temp\myzip","hello") //按名称解压
mle_2.text =  mle_2.text + "已解压 " + string(ll_count) + " 个文件" + "~r~n"
 

特别提醒 :

所有的图片附件,都是为作单独文件保存在 xl\media 目录下。

猜你喜欢

转载自blog.csdn.net/lxbin2003/article/details/106899165