C#如何自定义word文档的文字颜色
C#如何自定义word文档的文字颜色,如要定义word文档中文字颜色的值为204,代码该如何写
--------------------编程问答--------------------
up
--------------------编程问答--------------------
选中部分.Font.Color=需要的颜色
--------------------编程问答--------------------
c#中现在不用font了,在你写的文档的框体那,<p style="宋体" color="#ccc" >你的文档</p>
--------------------编程问答--------------------
//参考,下面的是将粗体改为正常的字体
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);
if (oWord.Selection.Font.Bold == -1)
{
this.richTextBox1.Text += oDoc.Content.Text.ToString().Substring(i, 1) + "\n\r";
//这里可以改颜色的.
oWord.Selection.Font.Bold = 0;
}
}
}
catch
{
}
}
if (oDoc != null)
oDoc.Close(ref oMissing, ref oMissing, ref oMissing);
if (oWord != null)
oWord.Quit(ref oMissing, ref oMissing, ref oMissing);
补充:.NET技术 , C#