我要将数据导出到word当中,对于word表格一个单元格中的一段文字,要设置不同的样式,比如第一行文字作为标题要居中,加粗,第二行为正常的正文,这样的情况,该如何去实现?求大神告知!
启用录制宏功能,然后手动插入一个表格,填写内容并设置格式,然后查看宏代码。
太好了大神,我理解你的意思了,3Q
Word.ApplicationClass oWordApp = new Word.ApplicationClass(); //添加页眉 oWordDoc.ActiveWindow.ActivePane.View.SeekView = WdSeekView.wdSeekCurrentPageHeader; //激活页眉的编辑 oWordApp.Selection.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphCenter; //设置对齐方式 string headtext1 ="Head Text"; oWordApp.Selection.Font.Name ="华文新魏"; //设置字体 oWordApp.Selection.Font.Size =10.5f; oWordApp.Selection.Font.UnderlineColor = Word.WdColor.wdColorAutomatic; oWordApp.Selection.Font.Underline = Word.WdUnderline.wdUnderlineSingle; //添加下划线 oWordApp.Selection.TypeText(headtext1); oWordApp.Selection.Font.Underline = Word.WdUnderline.wdUnderlineNone; //添加页脚 string foottext1 ="Foot Text"; oWordDoc.ActiveWindow.ActivePane.View.SeekView =Word.WdSeekView.wdSeekCurrentPageFooter; //激活页脚的编辑 oWordApp.Selection.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphCenter; oWordApp.Selection.Font.Name ="仿宋_GB2312"; oWordApp.Selection.Font.Size =8; oWordApp.Selection.TypeText(foottext1); //添加正文 oWordDoc.ActiveWindow.ActivePane.View.SeekView =Word.WdSeekView.wdSeekMainDocument;//激活页面内容的编辑 oWordApp.Selection.Font.Name ="宋体"; oWordApp.Selection.Font.Size =10.5f; oWordApp.Selection.Font.Scaling = 200; oWordApp.Selection.TypeText("Hello!!!"); oWordApp.Selection.TypeParagraph();//另起一段 oWordApp.Selection.Font.Name ="黑体"; oWordApp.Selection.Font.Size =10.5f; oWordApp.Selection.Font.Scaling = 100; oWordApp.Selection.TypeText("Hello!!!"); oWordApp.Selection.TypeParagraph();//另起一段