NPOI读取excel中的上下标,转化为真实的下标

本文档介绍了如何使用NPOI库来识别和转换Excel或Word文档中的上下标内容。通过GetSuperChar和GetSuberChar两个方法,将上下标转换为对应的Unicode字符或HTML标签,确保复制后的上下标内容能正确显示。
摘要由CSDN通过智能技术生成

excel或者word中,有设置上下标的功能,将设置后的内容复制出来,上下标识消失了的。本文档主要内容是NPOI识别上下标,将上下标转为对应的真上下标。

1、识别上下标

 

2、转换

 

/// <summary>
        /// 上标
        /// </summary>
        /// <returns></returns>
        private static string GetSuperChar(string str)
        {
            switch (str)
            {
                case "0":
                    return "\x2070";
                case "1":
                    return "\x00B9";
                case "2":
                    return "\x00B2";
                case "3":
                    return "\x00B3";
                case "4":
                    return "\x2074";
                case "5":
                    return "\x2075";
                case "6":
                    return "\x2076";
                case "7":
                    return "\x2077";
                case "8":
                    return "\x2078";
                case "9":
                    return "\x2079";
                case "+":
                    return "\x207A";
                case "-":
                    return "\x207B";
                case "=":
                    return "\x207C";
                case "(":
                    return "\x207D";
                case ")":
                    return "\x207E";
                case "i":
                    return "\x2071";
                case "n":
                    return "\x207F";
                default:

                    return $"<sup>{str}</sup>";
            }
        }

 /// <summary>
        /// 下标
        /// </summary>
        /// <returns></returns>
        private static string GetSuberChar(string str)
        {
            switch (str)
            {
                case "0":
                    return "\x2080";
                case "1":
                    return "\x2081";
                case "2":
                    return "\x2082";
                case "3":
                    return "\x2083";
                case "4":
                    return "\x2084";
                case "5":
                    return "\x2085";
                case "6":
                    return "\x2086";
                case "7":
                    return "\x2087";
                case "8":
                    return "\x2088";
                case "9":
                    return "\x2089";
                case "+":
                    return "\x208A";
                case "-":
                    return "\x208B";
                case "=":
                    return "\x208C";
                case "(":
                    return "\x208D";
                case ")":
                    return "\x208E";
                case "a":
                    return "\x2090";
                case "e":
                    return "\x2091";
                case "o":
                    return "\x2092";
                case "i":
                    return "\x1D62";
                case "r":
                    return "\x1D63";
                case "u":
                    return "\x1D64";
                case "v":
                    return "\x1D65";
                case "x":
                    return "\x2093";
                case "β":
                    return "\x1D66";
                case "γ":
                    return "\x1D67";
                case "χ":
                    return "\x1D6A";
                case "ψ":
                    return "\x1D69";
                case "h":
                    return "ₕ";
                case "k":
                    return "ₖ";
                case "l":
                    return "ₗ";
                case "m":
                    return "ₘ";
                case "n":
                    return "ₙ";
                case "p":
                    return "ₚ";
                case "s":
                    return "ₛ";
                case "t":
                    return "ₜ";
                default:
                    return $"<sub>{str}</sub>";
            }
        }

3、结果

复制出来对比:

 

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值