首页 新闻 会员 周边

c# word同一行两种字体,下面仿宋部分的代码完全被上面黑体部分的影响了,导致全是黑体。代码如下:

0
悬赏园豆:10 [已解决问题] 解决于 2016-10-08 11:16

public void putword(Microsoft.Office.Interop.Word._Application wordApp, Microsoft.Office.Interop.Word._Document wordDoc, CatagoryInfoObj obj, Object Nothing)
{
foreach (DataInfoObj c in obj.attributes)
{
if (c.name.Equals("中文名称"))
{
string strContent;//文本内容变量
strContent = c.value + " ";
wordApp.Selection.EndKey(ref unite, ref Nothing);
wordApp.Selection.Font.Bold = 0;//Bold=0为不加粗
//wordApp.Selection.Font.Name = "仿宋 GB2312";
wordApp.Selection.Font.Name = "黑体";
wordApp.Selection.Font.Name = "Times New Roman";
wordApp.Selection.Font.Size = 16;
wordApp.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphJustify;
wordApp.Selection.ParagraphFormat.LineSpacing = 12F;
wordApp.Selection.ParagraphFormat.CharacterUnitFirstLineIndent = float.Parse("2");//首行缩进的长度
wordApp.Selection.ParagraphFormat.SpaceBefore = float.Parse("0");//段前间距
wordApp.Selection.ParagraphFormat.SpaceAfter = float.Parse("0");//段后间距
wordApp.Selection.Text = strContent;
}
if (c.name.Equals("活动简述"))
{
string strContent;//文本内容变量
strContent = c.value + " ";
wordApp.Selection.EndKey(ref unite, ref Nothing);
wordApp.Selection.Font.Bold = 0;//Bold=0为不加粗
wordApp.Selection.Font.Name = "仿宋 GB2312";
//wordApp.Selection.Font.Name = "黑体";
wordApp.Selection.Font.Name = "Times New Roman";
wordApp.Selection.Font.Size = 16;
wordApp.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphJustify;
wordApp.Selection.ParagraphFormat.LineSpacing = 12F;
wordApp.Selection.ParagraphFormat.CharacterUnitFirstLineIndent = float.Parse("2");//首行缩进的长度
wordApp.Selection.ParagraphFormat.SpaceBefore = float.Parse("0");//段前间距
wordApp.Selection.ParagraphFormat.SpaceAfter = float.Parse("0");//段后间距
wordApp.Selection.Text = strContent;
}

问题补充:

我在台式机上装的vs2015就可以实现,在笔记本vs2012就无法实现

life清者自清的主页 life清者自清 | 初学一级 | 园豆:76
提问于:2016-09-30 12:43
< >
分享
最佳答案
0

自己解决了,只需将wordApp.Selection.Text = strContent;写到wordApp.Selection.EndKey(ref unite, ref Nothing);后面即可

life清者自清 | 初学一级 |园豆:76 | 2016-10-08 11:16
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册