[Go][Excelize] 确定单元格值是否有删除线
来源:dev.to
时间:2024-08-27 20:15:45 203浏览 收藏
从现在开始,努力学习吧!本文《[Go][Excelize] 确定单元格值是否有删除线》主要讲解了等等相关知识点,我会在golang学习网中持续更新相关的系列文章,欢迎大家关注并积极留言建议。下面就先一起来看一下本篇正文内容吧,希望能帮到你!
简介
我想确定单元格的值是否有删除线。
确定单元格的值是否有删除线
要确定单元格的值是否有删除线,我必须通过两种方式获取单元格样式。
如果只有单元格的某些值被删除,如“a1”,我应该从“excelize.richtextrun”获取单元格样式。
如果单元格中的所有值都像“a2”一样被删除,我应该从“excelize.xlsxxf”获得单元格样式。
xlsxreader.go
package main import ( "fmt" "log" "github.com/xuri/excelize/v2" ) func getcellstyles(filepath string) { xlfile, err := excelize.openfile(filepath) if err != nil { fmt.println(err) } defer func() { // close the spreadsheet. if err := xlfile.close(); err != nil { fmt.println(err) } }() sheetname := xlfile.getsheetname(0) log.println(sheetname) printcellstyles(xlfile, sheetname, "a1") printcellstyles(xlfile, sheetname, "a2") printcellstyles(xlfile, sheetname, "a3") } func printcellstyles(xlfile *excelize.file, sheetname string, celladdress string) { log.printf("--------%s--------", celladdress) value, _ := xlfile.getcellvalue(sheetname, celladdress) log.println(value) // if the cell value has multiple formats, "getcellrichtext" will return multiple values. runs, _ := xlfile.getcellrichtext(sheetname, celladdress) if len(runs) > 0 { for _, r := range runs { if r.font == nil { log.printf("value: %s no fonts", r.text) } else { log.printf("value: %s strike through?: %t", r.text, r.font.strike) } } } styleid, _ := xlfile.getcellstyle(sheetname, celladdress) // get cell style info by styleid style := xlfile.styles.cellxfs.xf[styleid] // get font info by style.fontid font := xlfile.styles.fonts.font[*style.fontid] // check if font.strike != nil && *font.strike.val { log.println("the cell value has a strike through") } else { log.println("the cell value doesn't have a strike through") } }
结果
2024/08/27 03:02:32 Sheet1 2024/08/27 03:02:32 --------A1-------- 2024/08/27 03:02:32 123abc 2024/08/27 03:02:32 Value: 12 No fonts 2024/08/27 03:02:32 Value: 3ab Strike through?: true 2024/08/27 03:02:32 Value: c Strike through?: false 2024/08/27 03:02:32 The cell value doesn't have a strike through 2024/08/27 03:02:32 --------A2-------- 2024/08/27 03:02:32 aiu 2024/08/27 03:02:32 The cell value has a strike through 2024/08/27 03:02:32 --------A3-------- 2024/08/27 03:02:32 abc def ghi 2024/08/27 03:02:32 Value: abc No fonts 2024/08/27 03:02:32 Value: def Strike through?: false 2024/08/27 03:02:32 Value: Strike through?: false 2024/08/27 03:02:32 Value: ghi Strike through?: false 2024/08/27 03:02:32 The cell value doesn't have a strike through
资源
- 单元格 - excelize 文档
- xlsx/tutorial/tutorial.adoc - tealeg/xlsx - github
以上就是本文的全部内容了,是否有顺利帮助你解决问题?若是能给你带来学习上的帮助,请大家多多支持golang学习网!更多关于Golang的相关知识,也可关注golang学习网公众号。
声明:本文转载于:dev.to 如有侵犯,请联系study_golang@163.com删除
相关阅读
更多>
-
505 收藏
-
501 收藏
-
501 收藏
-
501 收藏
-
501 收藏
最新阅读
更多>
-
140 收藏
-
364 收藏
-
468 收藏
-
309 收藏
-
498 收藏
-
382 收藏
课程推荐
更多>
-
- 前端进阶之JavaScript设计模式
- 设计模式是开发人员在软件开发过程中面临一般问题时的解决方案,代表了最佳的实践。本课程的主打内容包括JS常见设计模式以及具体应用场景,打造一站式知识长龙服务,适合有JS基础的同学学习。
- 立即学习 541次学习
-
- GO语言核心编程课程
- 本课程采用真实案例,全面具体可落地,从理论到实践,一步一步将GO核心编程技术、编程思想、底层实现融会贯通,使学习者贴近时代脉搏,做IT互联网时代的弄潮儿。
- 立即学习 506次学习
-
- 简单聊聊mysql8与网络通信
- 如有问题加微信:Le-studyg;在课程中,我们将首先介绍MySQL8的新特性,包括性能优化、安全增强、新数据类型等,帮助学生快速熟悉MySQL8的最新功能。接着,我们将深入解析MySQL的网络通信机制,包括协议、连接管理、数据传输等,让
- 立即学习 497次学习
-
- JavaScript正则表达式基础与实战
- 在任何一门编程语言中,正则表达式,都是一项重要的知识,它提供了高效的字符串匹配与捕获机制,可以极大的简化程序设计。
- 立即学习 487次学习
-
- 从零制作响应式网站—Grid布局
- 本系列教程将展示从零制作一个假想的网络科技公司官网,分为导航,轮播,关于我们,成功案例,服务流程,团队介绍,数据部分,公司动态,底部信息等内容区块。网站整体采用CSSGrid布局,支持响应式,有流畅过渡和展现动画。
- 立即学习 484次学习