excel - Perl(或Python)和Excel有没有办法确定单元格中多行文本使用的字体类型?

标签 excel perl formatting ole strikethrough

我有 Excel 文件形式的数据,其中某些单元格包含字符串,其中包含以删除线字符表示的先前版本的数据。我知道如何使用 Perl 和 OLE 来解析/操作 Excel 文件,但我只看到可以在单元格级别访问文本格式。有没有一种方法可以逐个字符地访问格式?目标是找到并消除所有格式化为删除线的文本。

最佳答案

这是一个 VBA 解决方案,因为我的计算机上没有安装 Python。希望它能够展示访问单个字符格式的方法。

以下是Range("A1"):

enter image description here

Option Explicit

Sub test()
    Dim wb As Workbook
    Dim ws As Worksheet
    Dim sentence As Range
    Set wb = ThisWorkbook
    Set ws = wb.ActiveSheet
    Set sentence = ws.Range("A1")

    With sentence
        Dim i As Long
        For i = 1 To .Characters.Count
            If .Characters(i, 1).Font.Strikethrough Then
                Debug.Print "strikethrough at character " & i
            End If
        Next i
    End With
End Sub

给出输出:

strikethrough at character 17
strikethrough at character 18
strikethrough at character 19

关于excel - Perl(或Python)和Excel有没有办法确定单元格中多行文本使用的字体类型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42937819/

相关文章:

perl - 使用导入 2 个模块

perl - 重新声明Perl foreach控制变量时,为什么没有收到警告?

c++ - 对于 GCC <5,是否有 std::put_time 的内置替代方案?

excel - 将excel VBA中另存为对话框上的 "Cancel"文本更改为 "Review"

excel - 仅对一行中的可见单元格求和(不是列)?

linux - 如何确保仅当脚本在 Windows 上运行时才加载模块?

sql-server - 如何从文本字段中删除完全空白行?

python - 对于看似相同的列表,格式有不同的行为

excel - 在电子表格中计算每周和每月总计

python - python中的数字操作