当前位置:网站首页>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语言相关源码的解读第十篇,我会不断努力,给大家带来更多类似的文章,恳请大家不吝赐教.
边栏推荐
- 金融证券 初级 招股书 要求 黑话1刷数 黑话2底稿 黑话3董监高
- If the data of the oracle business table is added, deleted, or modified, will the index of the table write redo and undo?
- BUUCTF Notes (web)
- 浅谈C语言实现冒泡排序
- 每日一题,数组字符串的匹配问题
- 关于数据中心的设计方案,数据中心网络规划设计
- Summary of ctfshow SSTI knowledge points
- Fiddler(八) - 抓取手机APP的流量-插件Fiddler Orchestra Beta安装&配置
- u-boot ERROR: Failed to allocate 0x5c6f bytes below 0x17ffffff.Failed using fdt_high value
- 神经网络样本太少怎么办,神经网络训练样本太少
猜你喜欢

ESP32 485风速

CV+Deep Learning——网络架构Pytorch复现系列——classification(三:MobileNet,ShuffleNet)

WooCommerce 安装和 rest api 使用

关于数据中心的设计方案,数据中心网络规划设计

MySQL索引事务

navicat for mysql 连接时报错:1251-Client does not support authentication protocol requested by server

SCS【2】单细胞转录组 之 cellranger

每日一题,数组字符串的匹配问题

pytest之parametrize参数化

2022-08-01 Advanced Network Engineering (23) Advanced VLAN Technology - VLAN Aggregation, MUX VLAN
随机推荐
CV-人脸识别-2018:ArcFace
卷积神经网络卷积层公式,卷积神经网络运算公式
人工神经网络工作原理,神经网络的工作原理
探索神经网络架构教程视频,设计神经网络的步骤
图像处理用什么神经网络,神经网络提取图片特征
u-boot ERROR: Failed to allocate 0x5c6f bytes below 0x17ffffff.Failed using fdt_high value
进程管理(动态的)
张驰课堂:老板会武术,谁也挡不住!六西格玛培训的魅力
2022-08-01 网工进阶(二十三) VLAN高级技术-VLAN聚合、MUX VLAN
【转】探秘钉钉的即时消息服务DTIM
.NET-8.我的思想笔记
人工神经网络模型的特点,人工神经网络模型定义
raid5的写性能,是不的比raid10快一些?
时序动作定位 | ACGNet:弱监督时序动作定位的动作补充图网络(AAAI 2022)
delta method 介绍
90.(cesium之家)cesium高度监听事件
DGIOT支持工业设备租赁以及远程管控
PLSQL学习第三天
34. 谈谈为什么要拆分数据库?有哪些方法?
.NET-7.WPF learning experience summary