当前位置:网站首页>Go-Excelize API源码阅读(七)—— CopySheet(from, to int)
Go-Excelize API源码阅读(七)—— CopySheet(from, to int)
2022-08-11 11:00:00 【InfoQ】
Go-Excelize API源码阅读(七)—— CopySheet(from, to int)
一、Go-Excelize简介
二、CopySheet(from, to int)、
func (f *File) CopySheet(from, to int) error
sheet_index := f.NewSheet("Sheet2")
err := f.CopySheet(1, sheet_index)
func (f *File) CopySheet(from, to int) error {
if from < 0 || to < 0 || from == to || f.GetSheetName(from) == "" || f.GetSheetName(to) == "" {
return ErrSheetIdx
}
return f.copySheet(from, to)
}
copySheet
- 源工作表索引小于0或目标工作表索引小于0。
- 源工作表索引等于目标工作表索引。
- 源工作表不存在或者目标工作表不存在
copySheet
copySheet
unc (f *File) copySheet(from, to int) error {
fromSheet := f.GetSheetName(from)
sheet, err := f.workSheetReader(fromSheet)
if err != nil {
return err
}
worksheet := deepcopy.Copy(sheet).(*xlsxWorksheet)
toSheetID := strconv.Itoa(f.getSheetID(f.GetSheetName(to)))
sheetXMLPath := "xl/worksheets/sheet" + toSheetID + ".xml"
if len(worksheet.SheetViews.SheetView) > 0 {
worksheet.SheetViews.SheetView[0].TabSelected = false
}
worksheet.Drawing = nil
worksheet.TableParts = nil
worksheet.PageSetUp = nil
f.Sheet.Store(sheetXMLPath, worksheet)
toRels := "xl/worksheets/_rels/sheet" + toSheetID + ".xml.rels"
fromRels := "xl/worksheets/_rels/sheet" + strconv.Itoa(f.getSheetID(fromSheet)) + ".xml.rels"
if rels, ok := f.Pkg.Load(fromRels); ok && rels != nil {
f.Pkg.Store(toRels, rels.([]byte))
}
fromSheetXMLPath := f.sheetMap[trimSheetName(fromSheet)]
fromSheetAttr := f.xmlAttr[fromSheetXMLPath]
f.xmlAttr[sheetXMLPath] = fromSheetAttr
return err
}
worksheet := deepcopy.Copy(sheet).(*xlsxWorksheet)
github.com/mohae/deepcopy
func Copy(src interface{}) interface{} {
if src == nil {
return nil
}
// Make the interface a reflect.Value
original := reflect.ValueOf(src)
// Make a copy of the same type as the original.
cpy := reflect.New(original.Type()).Elem()
// Recursively copy the original.
copyRecursive(original, cpy)
// Return the copy as an interface.
return cpy.Interface()
}
sheetView
TabSelected
false
TabSelected
sheetXMLPath
worksheet
Sheet
三、结语
边栏推荐
- 本地开发好的 SAP UI5 应用部署到 ABAP 服务器时,中文字符变成乱码的原因分析和解决方案
- [Study Notes] Dual Theorem of Linear Programming
- Getting Started with Chrome Plug-in Development - Nanny Level Raiders
- PerfView project (first) : how to find hot spots function
- LeetCode每日一题(1754. Largest Merge Of Two Strings)
- 关于数据权限的设计
- C语言手写魂斗罗(一)
- php获取微信小程序码并存储到oss
- [Ext JS]11.14 SimXhr.js?_dc=1659315492151:65 Uncaught TypeError problem analysis and solution
- rem如何使用
猜你喜欢
中小企业如何实施MES管理系统
人是怎么废掉的?人是怎么变强的?
The ceiling-level microservice boss summed up this 451-page note to tell you that microservices should be learned this way
安装nodejs
1.TCP/IP基础知识
darknet 结构体汇总
巧用自定义函数,文本控件秒变高速缓存
a-upload上传图片去掉预览icon
解决 Pocess finished with exit code 1 Class not found 和 Command line is too long. Shorten the command
独家采访 | 智能源于自发产生而非计划:进化论拥趸,前OpenAI研究经理、UBC大学副教授Jeff Clune
随机推荐
云原生 · 镜像详解
scala 高级
【分享】PPT还能做成这样?你一定没见过
Algorithm---Jumping Game (Kotlin)
09什么是继承
darknet 结构体汇总
go语言学习:并发编程(Sync/GMP/爬虫案例)
【教程】区块链是数据库?那么区块链的数据存储在哪里?如何查看数据?FISCO-BCOS如何更换区块链的数据存储,由RocksDB更换为MySQL、MariaDB,联盟链区块链数据库,区块链数据库应用
Are there any foreign application cases for domestic databases?
Neuropathic pain classification picture Daquan, neuropathic pain classification
The crawler is encapsulated into an api
如何解决 “主节点故障恢复的自动化” 问题?
一站式PCBA组装加工有哪些环节?
Database indexes and their underlying data structures
10Super详解
03列中新增子行
日志使用注意事项和建议
解决 Pocess finished with exit code 1 Class not found 和 Command line is too long. Shorten the command
7 天找个 Go 工作,Gopher 要学的条件语句,循环语句 ,第3篇
算法---跳跃游戏(Kotlin)