c# 怎么识别word里面的上标是多少?
我现在能用Font.Subscript判断word里面的一个字符串中是否有上标,但是不能把上标提取出来,各位大神有什么好办法?
上标就是和正文是一样的,只是字体不同。为什么你说提取不了。
还有一个是脚注,你说的不是脚注吧。
你可以使用 unicode super/subscripts,如:
var o2 = "O₂"; // or "O\x2082"
var unit2 = "unit²"; // or "unit\xB2"
Font.Superscript = 0;//上标
Font.Subscript = 1;//下标
用Spire.Doc可以读取上下标的值,参考代码
using System.Collections.Generic;
using Spire.Doc;
using Spire.Doc.Documents;
using Spire.Doc.Fields;
namespace GetSuperscript
{
class Program
{
static void Main(string[] args)
{
//加载Word文档
Document doc = new Document();
doc.LoadFromFile("test.docx");
//获取含上标的段落
Paragraph para = doc.Sections[0].Paragraphs[0];
//申明list变量
List<string> superScripts = null;
//遍历段落的子项
foreach (var item in para.Items)
{
//判断子项是否为TextRange
if(item is TextRange)
{
TextRange textRange = item as TextRange;
//判断TextRange的格式是否为上标
if(textRange.CharacterFormat.SubSuperScript== SubSuperScript.SuperScript)
{
//将上标添加至list
superScripts.Add(textRange.Text);
}
}
}
}
}
}