[이동][Excelize] 셀 값에 취소선이 있는지 확인

王林
풀어 주다: 2024-08-27 06:36:32
원래의
579명이 탐색했습니다.

소개

셀 값에 취소선이 있는지 확인하고 싶습니다.

[Go][Excelize] Determining if a cell

셀 값에 취소선이 있는지 확인

셀 값에 취소선이 있는지 확인하려면 두 가지 방법으로 셀 스타일을 가져와야 합니다.

"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
로그인 후 복사

자원

  • 셀 - 문서 엑셀화
  • xlsx/tutorial/tutorial.adoc - tealeg/xlsx - GitHub

위 내용은 [이동][Excelize] 셀 값에 취소선이 있는지 확인의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

원천:dev.to
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!