当前位置:网站首页>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语言相关源码的解读第十篇,我会不断努力,给大家带来更多类似的文章,恳请大家不吝赐教.
边栏推荐
猜你喜欢
34. 谈谈为什么要拆分数据库?有哪些方法?
90.(cesium之家)cesium高度监听事件
pytest之parametrize参数化
DGIOT三千万电表集抄压测
Quickly enter the current date and time
ESP32 485风速
物联网时代下的网络整合推广外包精准化效果-深圳双赢世讯
本地生活商家如何通过短视频赛道,提升销量曝光量?
Solve the problem that the win10win7win8 system cannot find the specified module and cannot register the desert plug-in
ATH10 sensor reads temperature and humidity
随机推荐
个人博客系统
ctfshow SSTI 知识点总结
Based on STC8G2K64S4 single-chip microcomputer to display analog photosensitive analog value through OLED screen
iwemeta元宇宙:阿里首任COO:如何打造销售铁军
【Rust指南】使用Cargo工具高效创建Rust项目 | 理解Rust特别的输入输出语句
NPU架构与算力分析
Synchronization lock synchronized traces the source
自动化测试框架Pytest(一)——入门
May I ask why sqlserver cdc will report this error one day after the task is started, obviously cdc has been opened.
winget package manager
简单业务类
占位占位1
DGIOT 30 million meters set pressure reading
DGIOT三千万电表集抄压测
NPU architecture and force analysis
【转】探秘钉钉的即时消息服务DTIM
Rust learning: 6.1_Slices of composite types
关于数据库中的中文模糊检索探讨
C# 获取PCI等设备的插槽位置信息
人工神经网络模型的特点,人工神经网络模型定义