当前位置:网站首页>Go exceed API source code reading (III) -- openreader ()
Go exceed API source code reading (III) -- openreader ()
2022-07-19 13:49:00 【ReganYue】
Go-Excelize API Source code reading ( 3、 ... and )——OpenReader()
Open source star picking program (WeOpen Star) By Tengyuan society 2022 A new project launched in , Designed to provide growth incentives for open source people , Provide growth support for open source projects , Help developers better understand open source , Cross the gap faster , Participate in the specific contribution and practice of open source .
Whether you are open source Mengxin , Or veterans who want to participate more deeply in open source contributions , Follow “ Open source star picking program ” Start your open source journey , From a learning note 、 To the submission of a piece of code , Keep tapping your potential , Eventually grow into an open source community “ Blazing Star ”.
We will be with you , Explore more possibilities !
Project address : WeOpen-Star:https://github.com/weopenprojects/WeOpen-Star
One 、Go-Excelize brief introduction
Excelize yes Go Language written for operation Office Excel Document base library , be based on ECMA-376,ISO/IEC 29500 international standard . You can use it to read 、 Written by Microsoft Excel 2007 Spreadsheet documents created by and above . Support XLAM / XLSM / XLSX / XLTM / XLTX And so on , Highly compatible with styles 、 picture ( surface )、 PivotTable 、 Slicer and other complex components of the document , And provide streaming reading and writing API, For workbooks that contain large amounts of data . It can be applied to various report platforms 、 Cloud computing 、 Edge computing and other systems . Required to use this class library Go The language is 1.15 Or later .
Two 、OpenReader()
func OpenReader(r io.Reader, opt ...Options) (*File, error)OpenReader The function of is from io.Reader Read data stream .
func OpenReader(r io.Reader, opt ...Options) (*File, error) {
b, err := ioutil.ReadAll(r)
if err != nil {
return nil, err
}
f := newFile()
f.options = parseOptions(opt...)
if f.options.UnzipSizeLimit == 0 {
f.options.UnzipSizeLimit = UnzipSizeLimit
if f.options.UnzipXMLSizeLimit > f.options.UnzipSizeLimit {
f.options.UnzipSizeLimit = f.options.UnzipXMLSizeLimit
}
}
if f.options.UnzipXMLSizeLimit == 0 {
f.options.UnzipXMLSizeLimit = StreamChunkSize
if f.options.UnzipSizeLimit < f.options.UnzipXMLSizeLimit {
f.options.UnzipXMLSizeLimit = f.options.UnzipSizeLimit
}
}
if f.options.UnzipXMLSizeLimit > f.options.UnzipSizeLimit {
return nil, ErrOptionsUnzipSizeLimit
}
if bytes.Contains(b, oleIdentifier) {
if b, err = Decrypt(b, f.options); err != nil {
return nil, ErrWorkbookFileFormat
}
}
zr, err := zip.NewReader(bytes.NewReader(b), int64(len(b)))
if err != nil {
if len(f.options.Password) > 0 {
return nil, ErrWorkbookPassword
}
return nil, err
}
file, sheetCount, err := f.ReadZipReader(zr)
if err != nil {
return nil, err
}
f.SheetCount = sheetCount
for k, v := range file {
f.Pkg.Store(k, v)
}
f.CalcChain = f.calcChainReader()
f.sheetMap = f.getSheetMap()
f.Styles = f.stylesReader()
f.Theme = f.themeReader()
return f, nil
}
ioutil.ReadAll First from io.Reader Read the whole data stream ,newFile() Create a Excel Workbooks .
f.options.UnzipSizeLimit: UnzipSizeLimit Specifies the decompression size limit when opening the spreadsheet , In bytes , This value should be greater than or equal to UnzipXMLSizeLimit, The default size limit is 16GB.
f.options.UnzipXMLSizeLimit:UnzipXMLSizeLimit Specify memory limits for decompressing worksheets and shared string tables , The unit is byte , When the file size exceeds this value , On the worksheet XML Will be extracted into the temporary directory of the system , This value should be less than or equal to UnzipSizeLimit, The default value is 16MB.
UnzipSizeLimit = 1000 << 24
StreamChunkSize = 1 << 24
Then judge whether the read data stream contains oleIdentifier = []byte{0xd0, 0xcf, 0x11, 0xe0, 0xa1, 0xb1, 0x1a, 0xe1} This is a OLE Program identifier , See Microsoft documentation for details :https://docs.microsoft.com/zh-cn/office/vba/outlook/concepts/getting-started/ole-programmatic-identifiers-outlook
zip.NewReader Return a return from bytes.NewReader(b) Read the new reader , It is assigned a given byte size int64(len(b)).
f.ReadZipReader(zr) in ReadZipReader Extract the spreadsheet with the given options . The given options are mainly passwords :
type Options struct {
MaxCalcIterations uint
Password string
RawCellValue bool
UnzipSizeLimit int64
UnzipXMLSizeLimit int64
}
Later and new file API almost NewFile(), to f Member assignment of structure .
3、 ... and 、 Conclusion
This is Lao Yue , This is a Go Interpretation of language related source code part III , I'll keep trying , Bring you more similar articles , Please give me your advice .
边栏推荐
- 【码蹄集新手村 600 题】科学计数法的实现方式,输出指数形式
- STL string replication comparison
- TKE(K8S)部署mysql使用CFS存储
- 洛谷P3512 [POI2010]PIL-Pilots 题解
- Transphorm的表面贴装封装产品系列增加行业标准TO-263 (D2PAK)封装产品,扩大SuperGaN平台的优势
- 力扣第 302 场周赛
- ONVIF Protocol Related: 4.1.3 WS - username token Method get capture d'écran URL
- S32K148_ Can drive (bare metal development)
- Onvif protocol related: 4.1.1 WS username token method to obtain wsusernametokenbean
- 鸿蒙设备开发快速入门之Helloword与LED——华为云14天鸿蒙设备开发实战学习笔记 第二篇
猜你喜欢

【考研词汇训练营】Day 6 —— eventually,state,create,productivity,stimulate

asterisk: rejected because extension not found in context ‘from-ipphone‘

Onvif protocol related: 3.1.1 digest access authorization

【码蹄集新手村 600 题】科学计数法的实现方式,输出指数形式

健康防猝指南3:健康保健

Onvif protocol related: 2.1.2 get screenshot URL in none mode

【7.15】代码源 -【整齐的数组2】【三进制循环】【树上逆序对】【蜗蜗的数列】

onvif协议相关:2.1.2 none方式获取截图url

onvif协议相关:4.1.3 WS-Username token方式获取截图url
![Codeforce:a. doremy's IQ [reverse greed]](/img/3d/065f9f1cbd857d324b6ed074d1afbf.png)
Codeforce:a. doremy's IQ [reverse greed]
随机推荐
【考研词汇训练营】Day 5 —— alarmist,cooperate,point,benefit,industrial,revolution,mechanize
[code hoof set novice village 600 question] calculate the number of digits of an integer
STL string replication comparison
Forget about postman. Apifox is better
onvif协议相关:常用类说明
【ACWing】2521. 数颜色
NO.2汇编初步
codeforce:G. Good Key, Bad Key【贪心】
Onvif protocol related: 2.1.1 get token in none mode
STM32F1与STM32CubeIDE编程实例-MPU-6050 六轴(陀螺仪 + 加速度计)驱动
[code hoof set novice village question 600] formatted input and output, using 0 to replace the completed space
国内外十大erp软件系统排名!
语音通信网络的原理
Onvif protocol related: 2.1.2 get screenshot URL in none mode
About XML file (VII) - XML DTD
onvif协议相关:3.1.4 Digest方式获取流地址
No.3汇编进阶
NO.4位、字节、信息存储
Onvif protocol related: 3.1.3 get screenshot URL in digest mode
2. Sum of three numbers