简体   繁体   English

C# 如何在单词段落范围内获取部分字线颜色

[英]C# How can i get part of the word line's color in a word paragraph range

am read WORD document with Word.ApplicationClass()使用 Word.ApplicationClass() 读取 WORD 文档

and the document style is kind this( doc )并且文档样式是这种( doc

AAAAA AAAAA

BBBB BBBB

①AAA ②BBB ③CCC(third part is red) ④DDD ①AAA ②BBB ③CCC(第三部分为红色)④DDD

and i get every line by using我通过使用得到每一行

String docLine= doc.paragraphs[i].range.text.Trim(); String docLine= doc.paragraphs[i].range.text.Trim();

and run [doc.paragraphs[3].range.text.Trim();] you get( line 3 )并运行 [doc.paragraphs[3].range.text.Trim();] 你得到(第 3 行

①AAA ②BBB ③CCC(third part is red) ④DDD ①AAA ②BBB ③CCC(第三部分为红色)④DDD

![enter image description here][2] a line with 4 parts words of different color. ![在此处输入图像描述][2] 一行由 4 个不同颜色的单词组成。

here is my problem, when i want to get the Red third part of the line i dont know how to get it.这是我的问题,当我想获得该行的红色第三部分时,我不知道如何获得它。

cause i dont know how to set a sub-Range in paragraphs[3].range which contains what i want.因为我不知道如何在包含我想要的内容的段落 [3].range 中设置子范围

i'v checked MSDN and only find u can set a Range's start and end when it's document.Range.我检查了 MSDN,只发现当它是 document.Range 时,你可以设置范围的开始和结束。

so what im asking is can someone tell me how to set a sub-range in a paragraphy[i].range.所以我要问的是有人能告诉我如何在一个段落[i].range 中设置一个子范围。 so that i can use range.font.colorindex这样我就可以使用 range.font.colorindex

or或者

if there is no way to do that then how can i get the color information when i read every prat of the line so that when i read the red part i can know.如果没有办法做到这一点,那么我如何在阅读该行的每个 prat 时获得颜色信息,以便当我阅读红色部分时我可以知道。

Thanks谢谢

thank you for all that help.谢谢你的帮助。 ive found the way to locate the part i want.我找到了找到我想要的部分的方法。 From this que: Re-defne a Paragraph Range to Include a Subset of Words in the Paragraph seems i didnt search right hum~从这个问题: 重新定义一个段落范围以在段落中包含一个词的子集似乎我没有搜索到正确的哼哼~

By using通过使用

Microsoft.Office.Interop.Word.Range rng = doc.paragraphs[3].Range.Duplicate; Microsoft.Office.Interop.Word.Range rng = doc.paragraphs[3].Range.Duplicate;

i can get an manipulable range( u cant change paragraphs.range),我可以得到一个可操作的范围(你不能改变段落范围),

and by using并通过使用

rng.MoveEnd(WdUnits.wdCharacter, endPos - rng.Characters.Count); rng.MoveEnd(WdUnits.wdCharacter, endPos - rng.Characters.Count); rng.MoveStart(WdUnits.wdCharacter, startPos); rng.MoveStart(WdUnits.wdCharacter, startPos);

i can locate what i want我可以找到我想要的

tips: range.setRange(int start, int end) will always(i think) relative the start and end of the document.提示: range.setRange(int start, int end) 将始终(我认为)相对于文档的开始和结束。 it's helpless when u try to work on a sentence or a line.当你试图处理一个句子或一行时,它是无助的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM