当前位置:网站首页>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语言相关源码的解读第十篇,我会不断努力,给大家带来更多类似的文章,恳请大家不吝赐教.
边栏推荐
- SQL SERVER 数据库,表的数据发生增删改,该表的索引会在ldf日志中记录吗?
- Nude speech - lying flat - brushing questions - big factory (several tips for Android interviews)
- Summary of ctfshow SSTI knowledge points
- Fiddler(八) - 抓取手机APP的流量-插件Fiddler Orchestra Beta安装&配置
- 幂函数 指数函数 对数函数
- iwemeta元宇宙:阿里首任COO:如何打造销售铁军
- 941 · Sliding Puzzles
- Using the color picker
- 如何远程调试对方的H5页面
- C# 获取PCI等设备的插槽位置信息
猜你喜欢
SCS【2】单细胞转录组 之 cellranger
第十六天&charles的基本操作
34. 谈谈为什么要拆分数据库?有哪些方法?
day16--抓包工具Charles的使用
人工神经网络模型的特点,人工神经网络模型定义
2022-08-01 Advanced Network Engineering (24) STP Advanced Knowledge
金融证券 初级 招股书 要求 黑话1刷数 黑话2底稿 黑话3董监高
AFNetworking概述和4.0的实践
时序动作定位 | ASM-Loc:弱监督时序动作定位的动作感知片段建模(CVPR 2022)
WooCommerce installation and rest api usage
随机推荐
winget package manager
VS2013-调试汇编代码-生成asm文件-结构体内存布局-函数参数压栈-调用约定
Rust学习:6.3_复合类型之元组
颜色选择器的使用
初使jest 单元测试
CV+Deep Learning - network architecture Pytorch recurrence series - classification (3: MobileNet, ShuffleNet)
winget包管理器
Relaxation class: the boss will martial arts, who also can not hold up against!The charm of six sigma training
If the data of the oracle business table is added, deleted, or modified, will the index of the table write redo and undo?
SQL建表问题,帮我看看好吗朋友们~大家人。!
ESP32 485风速
Solve the problem that the win10win7win8 system cannot find the specified module and cannot register the desert plug-in
SQL SERVER 数据库,表的数据发生增删改,该表的索引会在ldf日志中记录吗?
placeholder 1
Process management (dynamic)
PLSQL学习第二天
第2章 变量和基本类型读书笔记
人工神经网络工作原理,神经网络的工作原理
DGIOT支持工业设备租赁以及远程管控
Rust学习:6.4_复合类型之枚举