当前位置:网站首页>Go-Excelize API source code reading (11) - GetActiveSheetIndex()
Go-Excelize API source code reading (11) - GetActiveSheetIndex()
2022-08-10 07:44:00 【ReganYue】
Go-Excelize API源码阅读(十一)—— GetActiveSheetIndex()
开源摘星计划(WeOpen Star) 是由腾源会 2022 年推出的全新项目,旨在为开源人提供成长激励,为开源项目提供成长支持,助力开发者更好地了解开源,更快地跨越鸿沟,参与到开源的具体贡献与实践中.
不管你是开源萌新,还是希望更深度参与开源贡献的老兵,跟随“开源摘星计划”开启你的开源之旅,从一篇学习笔记、到一段代码的提交,不断挖掘自己的潜能,最终成长为开源社区的“闪亮之星”.
我们将同你一起,探索更多的可能性!
项目地址: WeOpen-Star:https://github.com/weopenprojects/WeOpen-Star
一、Go-Excelize简介
Excelize 是 Go 语言编写的用于操作 Office Excel 文档基础库,基于 ECMA-376,ISO/IEC 29500 国际标准.可以使用它来读取、写入由 Microsoft Excel 2007 及以上版本创建的电子表格文档.支持 XLAM / XLSM / XLSX / XLTM / XLTX 等多种文档格式,高度兼容带有样式、图片(表)、透视表、切片器等复杂组件的文档,并提供流式读写 API,用于处理包含大规模数据的工作簿.可应用于各类报表平台、云计算、边缘计算等系统.使用本类库要求使用的 Go 语言为 1.15 或更高版本.
二、GetActiveSheetIndex()
func (f *File) GetActiveSheetIndex() int
该APIThe role of is to get the index of the default worksheet,If no default sheet is found it will return 0.
废话少说,直接上源码:
// GetActiveSheetIndex provides a function to get active sheet index of the
// spreadsheet. If not found the active sheet will be return integer 0.
func (f *File) GetActiveSheetIndex() (index int) {
sheetID := f.getActiveSheetID()
wb := f.workbookReader()
if wb != nil {
for idx, sheet := range wb.Sheets.Sheet {
if sheet.SheetID == sheetID {
index = idx
return
}
}
}
return
}
看到这个sheetID := f.getActiveSheetID()
getActiveSheetID A function is provided to get the active sheet of the spreadsheet ID.
如果未找到活动工作表,将返回整数 0.
func (f *File) getActiveSheetID() int {
wb := f.workbookReader()
if wb != nil {
if wb.BookViews != nil && len(wb.BookViews.WorkBookView) > 0 {
activeTab := wb.BookViews.WorkBookView[0].ActiveTab
if len(wb.Sheets.Sheet) > activeTab && wb.Sheets.Sheet[activeTab].SheetID != 0 {
return wb.Sheets.Sheet[activeTab].SheetID
}
}
if len(wb.Sheets.Sheet) >= 1 {
return wb.Sheets.Sheet[0].SheetID
}
}
return 0
}
In fact, it is to read the table file,Then get the workbook view queue firstActiveTab.
ActiveTabI can't find it in Microsoft documentation,My guess is the sheet ordinal of the active view queue.
type xlsxWorkBookView struct {
Visibility string `xml:"visibility,attr,omitempty"`
Minimized bool `xml:"minimized,attr,omitempty"`
ShowHorizontalScroll *bool `xml:"showHorizontalScroll,attr"`
ShowVerticalScroll *bool `xml:"showVerticalScroll,attr"`
ShowSheetTabs *bool `xml:"showSheetTabs,attr"`
XWindow string `xml:"xWindow,attr,omitempty"`
YWindow string `xml:"yWindow,attr,omitempty"`
WindowWidth int `xml:"windowWidth,attr,omitempty"`
WindowHeight int `xml:"windowHeight,attr,omitempty"`
TabRatio int `xml:"tabRatio,attr,omitempty"`
FirstSheet int `xml:"firstSheet,attr,omitempty"`
ActiveTab int `xml:"activeTab,attr,omitempty"`
AutoFilterDateGrouping *bool `xml:"autoFilterDateGrouping,attr"`
}
if len(wb.Sheets.Sheet) > activeTab && wb.Sheets.Sheet[activeTab].SheetID != 0 {
return wb.Sheets.Sheet[activeTab].SheetID
}
The sequence number of the first worksheet in the active view queue cannot be greater than the number of worksheets,and its worksheetID不等于0.
如此,This returns the sheet of the first sheet of the active view queueID.
if len(wb.Sheets.Sheet) >= 1 {
return wb.Sheets.Sheet[0].SheetID
}
If the workbook view does not exist,Or the number of workbook views equals0,And the number of worksheets is greater than or equal to1,Then the return index is 0的工作表的ID.
wb := f.workbookReader()
if wb != nil {
for idx, sheet := range wb.Sheets.Sheet {
if sheet.SheetID == sheetID {
index = idx
return
}
}
}
读取工作簿,Then if the workbook is empty,就会导致sheetID := f.getActiveSheetID()Acquired worksheetID为0,所以会返回0.
如果不为空,Iterates over the worksheet,when worksheetID为getActiveSheetID()Get the active worksheetID时,Take its worksheet index,返回.
三、结语
这里是老岳,这是Go语言相关源码的解读第十篇,我会不断努力,给大家带来更多类似的文章,恳请大家不吝赐教.
边栏推荐
- NPU架构与算力分析
- winget包管理器
- Solve the problem that the win10win7win8 system cannot find the specified module and cannot register the desert plug-in
- 时序动作定位 | ACGNet:弱监督时序动作定位的动作补充图网络(AAAI 2022)
- The probability distribution and its application
- Bigder:42/100 showCase多少bug可以打回去
- 浏览器适配杂记
- 关于数据中心的设计方案,数据中心网络规划设计
- 【无标题】
- Introduction to C integer data storage
猜你喜欢
随机推荐
MySQL设置初始密码—注意版本mysql-8.0.30
AFNetworking概述和4.0的实践
ctfshow SSTI 知识点总结
If the data of the oracle business table is added, deleted, or modified, will the index of the table write redo and undo?
Synchronization lock synchronized traces the source
NPU architecture and force analysis
模糊查询除了like+ % 还能用什么方式
Process management (dynamic)
SCS【2】单细胞转录组 之 cellranger
进程管理(动态的)
机器人控制器编程实践指导书旧版-实践二 传感器(模拟量)
Based on STC8G2K64S4 single-chip microcomputer to display analog photosensitive analog value through OLED screen
【Rust指南】使用Cargo工具高效创建Rust项目 | 理解Rust特别的输入输出语句
u-boot ERROR: Failed to allocate 0x5c6f bytes below 0x17ffffff.Failed using fdt_high value
winget包管理器
简单业务类
机器人控制器编程实践指导书旧版-实践一 LED灯(数字量)
图像处理用什么神经网络,神经网络提取图片特征
如何远程调试对方的H5页面
Chapter 11 Database Design Specifications [2. Index and Tuning] [MySQL Advanced]









