当前位置:网站首页>Go-Excelize API source code reading (8) - GroupSheets(sheets []string), UngroupSheets()
Go-Excelize API source code reading (8) - GroupSheets(sheets []string), UngroupSheets()
2022-08-01 09:32:00 【ReganYue】
Go-Excelize API源码阅读(八)——UngroupSheets()
开源摘星计划(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 或更高版本.
二、GroupSheets(sheets []string)
func (f *File) GroupSheets(sheets []string) error
该APIIs the function of work according to the given table name for grouping work table,A given job will consist of a default in the table table.
func (f *File) GroupSheets(sheets []string) error {
// check an active worksheet in group worksheets
var inActiveSheet bool
activeSheet := f.GetActiveSheetIndex()
sheetMap := f.GetSheetList()
for idx, sheetName := range sheetMap {
for _, s := range sheets {
if s == sheetName && idx == activeSheet {
inActiveSheet = true
}
}
}
if !inActiveSheet {
return ErrGroupSheets
}
// check worksheet exists
var wss []*xlsxWorksheet
for _, sheet := range sheets {
worksheet, err := f.workSheetReader(sheet)
if err != nil {
return err
}
wss = append(wss, worksheet)
}
for _, ws := range wss {
sheetViews := ws.SheetViews.SheetView
if len(sheetViews) > 0 {
for idx := range sheetViews {
ws.SheetViews.SheetView[idx].TabSelected = true
}
continue
}
}
return nil
}
整个APIImplementation is divided into two steps:
1.Find an active in group work table worksheet
activeSheetIs the job of the active table index.sheetMap := f.GetSheetList()
GetSheetList 提供了一个函数,Used to get workbook worksheet、Chart worksheet and dialog work table name list.
func (f *File) GetSheetList() (list []string) {
wb := f.workbookReader()
if wb != nil {
for _, sheet := range wb.Sheets.Sheet {
list = append(list, sheet.Name)
}
}
return
}
for idx, sheetName := range sheetMap {
for _, s := range sheets {
if s == sheetName && idx == activeSheet {
inActiveSheet = true
}
}
}
This code is to look forsheets里面是不是有s与idx等于activeSheet的sheetName相等.
2.Check the schedule whether there is a
var wss []*xlsxWorksheet
for _, sheet := range sheets {
worksheet, err := f.workSheetReader(sheet)
if err != nil {
return err
}
wss = append(wss, worksheet)
}
for _, ws := range wss {
sheetViews := ws.SheetViews.SheetView
if len(sheetViews) > 0 {
for idx := range sheetViews {
ws.SheetViews.SheetView[idx].TabSelected = true
}
continue
}
}
xlsxWorksheet Direct mapping work table elements in the namespace http://schemas.openxmlformats.org/spreadsheetml/2006/main.
A new structure,然后遍历sheets,读取每一个sheet,加入wss.
然后遍历这些wss,获取wss中每一个sheet的视图.
遍历视图,Each view ofTabSelected置为true.
三、UngroupSheets()
该APIFunction is to cancel the worksheet packet.
func (f *File) UngroupSheets() error
func (f *File) UngroupSheets() error {
activeSheet := f.GetActiveSheetIndex()
for index, sheet := range f.GetSheetList() {
if activeSheet == index {
continue
}
ws, _ := f.workSheetReader(sheet)
sheetViews := ws.SheetViews.SheetView
if len(sheetViews) > 0 {
for idx := range sheetViews {
ws.SheetViews.SheetView[idx].TabSelected = false
}
}
}
return nil
}
Get active work table indexactiveSheet.
Then traverse the file work table,Deal only with the active worksheet.
Traverse to the active worksheet indexes,Read the worksheet,The each viewTabSelected置为false.
三、结语
这里是老岳,这是GoThe interpretation of language related to source the eighth article,我会不断努力,给大家带来更多类似的文章,恳请大家不吝赐教.
边栏推荐
- WLAN networking experiment of AC and thin AP
- 企业微信群:机器人定时提醒功能数据库配置化
- 高级驾驶辅助系统ADAS简介
- How programmers learn open source projects, this article tells you
- 在GBase 8c数据库后台,使用什么样的命令来对gtm、dn节点进行主备切换的操作
- Pod environment variables and initContainer
- leetcode 42. 接雨水
- 热修复技术可谓是百花齐放
- leetcode 42. Catch the rain
- Pod环境变量和initContainer
猜你喜欢

三子棋(C语言实现)

网络基础学习

HoloView 在 jyputer lab/notebook 不显示总结

【STM32】入门(二):跑马灯-GPIO端口输出控制

How programmers learn open source projects, this article tells you

Idea common plugins

Meeting OA (Upcoming Meetings & All Meetings)

Analysis of High Availability Solution Based on MySql, Redis, Mq, ES

Redis中间件(从搭建到弃坑)

Redis middleware (from building to refuse pit)
随机推荐
Pod环境变量和initContainer
Parsing MySQL Databases: "SQL Optimization" vs. "Index Optimization"
node 格式化时间的传统做法与高级做法(moment)
sqlserver 对比两张表的差异
走进音视频的世界——mp3封装格式
【STM32】入门(一):环境搭建、编译、下载、运行
[Dataset] Dataset summary of various insulators, bird's nests and anti-vibration hammers
Redis学习
18张图,直观理解神经网络、流形和拓扑
sqlserver怎么查询一张表中同人员的交叉日期
STM32个人笔记-看门狗
TiDB的真实数据库数据是存在kv和还是pd上?
scrapy爬虫框架的使用
leetcode-6133: maximum number of groupings
Get the Token from the revised version of Qubutu Bed
Explain / Desc 执行计划分析
sql server, FULL mode, dbcc shrinkfile(2,1) can not shrink the transaction log, or the original size, why?
【无标题】
C语言中编译时出现警告C4013(C语言不加函数原型产生的潜在错误)
【Unity3D】相机