日期:2014-05-19  浏览次数:20957 次

在C#中如何设置word文档中,一段文字的样式
在C#中如何设置word文档中,一段文字的样式

------解决方案--------------------
先通过录制宏得到相应的VBA代码
察看Word VBA帮助中对应方法的说明, 再转换成C#
------解决方案--------------------
可以看看vsto方面的书
------解决方案--------------------
答案 ls的两位已经说了
------解决方案--------------------
VSTO好像没有这方面的内容,能不能给段代码。或网站链接
------解决方案--------------------
// Create an instance of Word, make it visible,
// and open Doc1.doc.
Word.ApplicationClass oWord = new Word.ApplicationClass();
oWord.Visible = true;
Word.Documents oDocs = oWord.Documents;
object oFile = "c:\\doc1.doc ";

// If the Microsoft Word 10.0 Object Library is referenced
// use the following code.
Word._Document oDoc = oDocs.Open(ref oFile, 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);

// If the Microsoft Word 11.0 Object Library is referenced comment
// the previous line of code and uncomment the following code.
//Word._Document oDoc = oDocs.Open(ref oFile, 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);

// Run the macros.
RunMacro(oWord, new Object[]{ "DoKbTest "});
RunMacro(oWord, new Object[]{ "DoKbTestWithParameter ",
"Hello from C# Client. "});

// Quit Word and clean up.
oDoc.Close(ref oMissing, ref oMissing, ref oMissing);
System.Runtime.InteropServices.Marshal.ReleaseComObject (oDoc);
oDoc = null;
System.Runtime.InteropServices.Marshal.ReleaseComObject (oDocs);
oDocs = null;
oWord.Quit(ref oMissing, ref oMissing, ref oMissing);
System.Runtime.InteropServices.Marshal.ReleaseComObject (oWord);
oWord = null;

break;

------解决方案--------------------
http://support.microsoft.com/kb/306683/zh-cn