如题,在同一行。希望各位大神多多指教,先谢谢了,困扰三天了,烦。。。
foreach (DataInfoObj c in obj.attributes)
{
if (c.name.Equals("中文名称"))
{
string strContent;//文本内容变量
strContent = " " + c.value + " ";
//wordApp.Selection.EndKey(ref unite, ref Nothing);
wordDoc.Paragraphs.Last.Range.Font.Bold = 0;//Bold=0为不加粗
wordDoc.Paragraphs.Last.Range.Font.Name = "黑体";
wordDoc.Paragraphs.Last.Range.Font.NameOther = "Times New Roman";
wordDoc.Paragraphs.Last.Range.Font.Size = 16F;
wordDoc.Paragraphs.Last.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphJustify;
wordDoc.Paragraphs.Last.Range.ParagraphFormat.LineSpacing = 12F;//设置文档的行间距
//wordApp.Selection.ParagraphFormat.FirstLineIndent = 56.6;//首行缩进的长度
wordApp.CentimetersToPoints(float.Parse("56.6"));//首行缩进
wordDoc.Paragraphs.Last.SpaceBefore = float.Parse("0");//段前间距
wordDoc.Paragraphs.Last.SpaceAfter = float.Parse("0");//段后间距
wordDoc.Paragraphs.Last.Range.InsertAfter(strContent);
}
if (c.name.Equals("活动简述"))
{
string strContent;//文本内容变量
strContent = " " + c.value;
wordDoc.Paragraphs.Last.Range.Font.Bold = 0;//Bold=0为不加粗
//wordApp.Selection.EndKey(ref unite, ref Nothing);
wordDoc.Paragraphs.Last.Range.Font.Name = "仿宋 GB2312";
wordDoc.Paragraphs.Last.Range.Font.NameOther = "Times New Roman";
wordDoc.Paragraphs.Last.Range.Font.Size = 16F;
wordDoc.Paragraphs.Last.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphJustify;
wordDoc.Paragraphs.Last.Range.ParagraphFormat.LineSpacing = 12F;//设置文档的行间距
wordDoc.Paragraphs.Last.SpaceBefore = float.Parse("0");//段前间距
wordDoc.Paragraphs.Last.SpaceAfter = float.Parse("0");//段后间距
wordDoc.Paragraphs.Last.Range.InsertAfter(strContent);
}
strContent = " " + c.value + " "这句如果改成strContent = " " + c.value + "\n",那么前黑体后宋体,可是就会多一个回车符。如果不加,就会全是宋体。怎样不加"\n",也能保持前黑后宋体????
你录制一段宏,录制的时候把你的操作给重复一遍,然后去看下录制的宏的写法吧。
有什么意义???
n能解决我所问的吗????
我试了,没成功
@life清者自清: 这是我录制的一段宏。
Sub 宏1()
'
' 宏1 宏
'
'
Selection.TypeText Text:="abcddfdfdfdf"
Selection.MoveLeft Unit:=wdCharacter, Count:=7, Extend:=wdExtend
Selection.Font.Bold = wdToggle
Selection.Font.Italic = wdToggle
End Sub
把后面几个字母改粗改斜体。对照你的代码感觉是应该指定一个range(类似鼠标选择几个字符),然后再对这个对象改属性。
@Daniel Cai: 按照你的方法解决了,从头到尾所有的控件都换了,谢了。不过录制的宏还得修改,大体思路是对的,要早知道这个录制宏,开始设置word格式就不会浪费这么多时间了,郁闷。
给你个思路,用程序将你需要设成粗体的部分设置成range或者书签,然后再对其进行针对性的加粗处理
解决了才看到你的,给你个小豆子,嘻嘻