如何使用c#遍历word文件中的每个字母,并获得其颜色 例如一word文件如下:hello使用程序获得出此word文件中的每个字母的颜色,并输出。h 默认e 红色如此使用COM,看了Application,Document等等等等网上也找了不少,始终没有思路请指点指点,谢谢 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 楼主,在word里面有一个查找取代的功能,这个功能可以查找到指定颜色的文字,如果你把这个查找的原理搞懂了应该就可以遍历出来了。你去看下这个功能:http://www.it.com.cn/f/edu/0811/19/693143.htm 楼主,用VBA吧,很容易搞定,foreach(pgf) if words.color=? then... wdoc.Content.Font.Color 只能这么离颜色近点。文本没那个属性,只能取到文本内容关注! object oMissing = System.Reflection.Missing.Value; Microsoft.Office.Interop.Word._Application oWord; Microsoft.Office.Interop.Word._Document oDoc; oWord = new Microsoft.Office.Interop.Word.Application(); oWord.Visible = false; object fileName = System.IO.Directory.GetCurrentDirectory() + "\\test.doc"; oDoc = oWord.Documents.Open(ref fileName, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing); for (int i = 0; i < oDoc.Content.Text.Length; i++) { try { if (oDoc.Content.Text.ToString().Trim().Substring(i, 1) != " ") { oWord.Selection.MoveRight(ref oMissing, ref oMissing, ref oMissing); this.richTextBox1.Text += oDoc.Content.Text.ToString().Substring(i, 1) + ":" + oWord.Selection.Font.ColorIndex.ToString() + "\n\r"; } } catch { } } if (oDoc != null) oDoc.Close(ref oMissing, ref oMissing, ref oMissing); if (oWord != null) oWord.Quit(ref oMissing, ref oMissing, ref oMissing); 如何向其它窗体发送一直按下某个键的消息 关于开放的定义. 我下载了borland together 2005 可是用不来shock.jar注册机呢??我打开shock.jar要解压呢?解压后的文件一个也打不开,帮助一下吧!! 关于显示的问题! C#的串口读写问题 问一个C#的基础问题啊 如何设置服务器上的某一个目录任何人都有权限下载该文件夹下的所有文件 文件”正由另一进程使用,因此该进程无法访问此文件。 能做到计时打开4个网页地址吗? 编程中的Flash问题? 问个简单的关于运行顺序问题 事件驱动与线程调度
你去看下这个功能:http://www.it.com.cn/f/edu/0811/19/693143.htm
只能这么离颜色近点。
文本没那个属性,只能取到文本内容关注!
object oMissing = System.Reflection.Missing.Value;
Microsoft.Office.Interop.Word._Application oWord;
Microsoft.Office.Interop.Word._Document oDoc;
oWord = new Microsoft.Office.Interop.Word.Application();
oWord.Visible = false;
object fileName = System.IO.Directory.GetCurrentDirectory() + "\\test.doc";
oDoc = oWord.Documents.Open(ref fileName, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing); for (int i = 0; i < oDoc.Content.Text.Length; i++)
{
try
{
if (oDoc.Content.Text.ToString().Trim().Substring(i, 1) != " ")
{
oWord.Selection.MoveRight(ref oMissing, ref oMissing, ref oMissing);
this.richTextBox1.Text += oDoc.Content.Text.ToString().Substring(i, 1) + ":" + oWord.Selection.Font.ColorIndex.ToString() + "\n\r";
}
}
catch
{
}
} if (oDoc != null)
oDoc.Close(ref oMissing, ref oMissing, ref oMissing);
if (oWord != null)
oWord.Quit(ref oMissing, ref oMissing, ref oMissing);