zoukankan      html  css  js  c++  java
  • 用AutoHotkey解决Excel中修改超链接公式会自动修改文字格式的问题

    存在的困难

    如果用了excel的超链接,一定会被Excel自动修改格式折磨过。
    只要修改了公式中的任意内容,回车后单元格格式就变成蓝字,12号字体。
    然后就要手动改回原来的格式,非常繁琐

    解决方案:

    用脚本在修改前记录当前单元格的格式,设置公式后再自动设置字体格式。 记录单元格格式和恢复单元格格式的函数如下

    xl := ComObjActive("Excel.application")
    ac := xl.ActiveCell
    objFormat := get(ac)
    arrFormula := StrSplit(ac.formula, '"')
    rng := inputbox("引用区域",,,ltrim(arrFormula[2],"#"))
    name := inputbox("显示名称",,,ac.text)
    gs := format('=HYPERLINK("#{1}","{2}")', rng,name)
    xl.ScreenUpdating := false
    ac.formula := gs
    set(ac, objFormat)
    xl.ScreenUpdating := true
    return

    get(cell) {
    objFormat := {}
    objFormat.font := {}
    objFormat.interior := {}
    objFormat.font.name := cell.font.name,
    objFormat.font.Size := cell.font.Size,
    objFormat.font.bold := cell.font.bold,
    objFormat.font.italic := cell.font.italic,
    objFormat.font.Strikethrough := cell.font.Strikethrough,
    objFormat.font.underline := cell.font.underline,
    objFormat.font.ColorIndex := cell.font.ColorIndex,
    objFormat.interior.ColorIndex := cell.interior.ColorIndex,
    return objFormat
    }
    set(cell, objFormat) {
    cell.font.name := objFormat.font.name,
    cell.font.Size := objFormat.font.Size,
    cell.font.bold := objFormat.font.bold,
    cell.font.italic := objFormat.font.italic,
    cell.font.Strikethrough := objFormat.font.Strikethrough,
    cell.font.underline := objFormat.font.underline,
    cell.font.ColorIndex := objFormat.font.ColorIndex,
    cell.interior.ColorIndex := objFormat.interior.ColorIndex,
    }

  • 相关阅读:
    day10
    python学习第六天
    Python学习第五天
    python学习第四天第一部分
    python学习第三天第一部分
    python学习第二天第二部分
    python学习第二天第一部分
    崔西凡JavaWeb笔记day13-day15(2016年8月30日22:36:30)
    崔希凡JavaWeb笔记day10~day12(2016年8月22日11:55:20)
    崔希凡-javaWeb-笔记day07-day09(2016年7月26日23:14:40)
  • 原文地址:https://www.cnblogs.com/hyaray/p/15042214.html
Copyright © 2011-2022 走看看