当前位置:网站首页>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 .
边栏推荐
- Start from here by counting the information of the broadcast room
- 565. Array nesting
- FreeRTOS-空闲任务和阻塞延时的实现
- [code hoof set novice village question 600] formatted input and output, using 0 to replace the completed space
- 【码蹄集新手村 600 题】如何使整数逆序
- Framework construction of business card management
- 【7.13】代码源 -【饿饿 饭饭】【路径计数2】【函数求和】
- chrome插件用于信息收集
- Onvif protocol related: 3.1.1 digest access authorization
- "Podcast with relish" 392 original soup, original food: midsummer night, mashed horse, kebab, and pull board
猜你喜欢

No.2 compilation preliminary

【码蹄集新手村 600 题】格式化的输入输出,使用 0 来代替补全的空格

Onvif protocol related: 4.1.2 WS username token method to obtain token

2. Sum of three numbers

ImportError: DLL load failed while importing win32api: 找不到指定的程序。

Health prevention guide 3: health care

Onvif protocol related: 3.1.4 get the stream address in digest mode

onvif协议相关:3.1.1 Digest方式获取Authorization

【Acwing】第60场周赛 题解

命令行的一些常用操作命令及常见错误的解决办法
随机推荐
Deep learning from getting started to giving up the 100 day challenge
深度学习从入门到放弃100天挑战
Flutter 使用 AnimatedSwitcher 做场景切换
[code hoof set novice village question 600] format specifier of float and double
Codeforce:g. good key, bad key [greed]
Health prevention guide 3: health care
Onvif protocol related: 2.1.1 get token in none mode
AcWing 136. 邻值查找
Onvif protocol related: 3.1.4 get the stream address in digest mode
弹性负载均衡将访问流量自动分发到多台云服务器,扩展应用系统对外的服务能力,提高应用程序安全性。
Codeforce:a. difference operations [mathematical thinking]
CBS类型PVC回收策略
"Technology podcast month" day 10: meta podcast: talk about Podcasting
Transphorm的表面贴装封装产品系列增加行业标准TO-263 (D2PAK)封装产品,扩大SuperGaN平台的优势
ModuleNotFoundError: No module named ‘_distutils_hack‘
Onvif protocol related: 3.1.2 get the token list in digest mode
onvif协议相关:3.1.1 Digest方式获取Authorization
onvif协议相关:4.1.4 WS-Username token方式获取流地址
这些年我开源的几个小项目
【7.8】Educational Codeforces Round 131 (Rated for Div. 2)