0

0

[Go][Excelize] 确定单元格值是否有删除线

WBOY

WBOY

发布时间:2024-08-27 09:18:03

|

1138人浏览过

|

来源于dev.to

转载

简介

我想确定单元格的值是否有删除线。

[Go][Excelize] 确定单元格值是否有删除线

确定单元格的值是否有删除线

要确定单元格的值是否有删除线,我必须通过两种方式获取单元格样式。

Endel.io
Endel.io

Endel是一款可以创造个性化舒缓声音的应用程序,可帮助您集中注意力、放松身心和入睡。

下载

如果只有单元格的某些值被删除,如“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

相关专题

更多
vlookup函数使用大全
vlookup函数使用大全

本专题整合了vlookup函数相关 教程,阅读专题下面的文章了解更多详细内容。

26

2025.12.30

金山文档相关教程
金山文档相关教程

本专题整合了金山文档相关教程,阅读专题下面的文章了解更多详细操作。

28

2025.12.30

PS反选快捷键
PS反选快捷键

本专题整合了ps反选快捷键介绍,阅读下面的文章找到答案。

25

2025.12.30

表格中一行两行的方法
表格中一行两行的方法

本专题整合了表格中一行两行的相关教程,阅读专题下面的文章了解更多详细内容。

3

2025.12.30

cpu温度过高解决方法大全
cpu温度过高解决方法大全

本专题整合了cpu温度过高相关教程,阅读专题下面的文章了解更多详细内容。

5

2025.12.30

ASCII码介绍
ASCII码介绍

本专题整合了ASCII码相关内容,阅读专题下面的文章了解更多详细内容。

31

2025.12.30

GPS是什么
GPS是什么

本专题整合了GPS相关内容,阅读专题下面的文章了解更多详细内容。

3

2025.12.30

wifi拒绝接入
wifi拒绝接入

本专题整合了wifi拒绝接入相关教程,阅读下面的文章了解更多详细方法。

9

2025.12.30

丰网速运介绍
丰网速运介绍

本专题整合了丰网速运查询入口以及相关内容,阅读专题下面的文章了解更多内容。

3

2025.12.30

热门下载

更多
网站特效
/
网站源码
/
网站素材
/
前端模板

精品课程

更多
相关推荐
/
热门推荐
/
最新课程
Git 教程
Git 教程

共21课时 | 2.3万人学习

Git版本控制工具
Git版本控制工具

共8课时 | 1.5万人学习

Git中文开发手册
Git中文开发手册

共0课时 | 0人学习

关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号