如何用C#代码控制word文档目录的自动生成
2个回答
2014-11-27 · 知道合伙人数码行家
huanglenzhi
知道合伙人数码行家
向TA提问 私信TA
知道合伙人数码行家
采纳数:117538
获赞数:517174
长期从事计算机组装,维护,网络组建及管理。对计算机硬件、操作系统安装、典型网络设备具有详细认知。
向TA提问 私信TA
关注
展开全部
实现代码如下:
public class BiultReportForm
{
/// <SUMMARY></SUMMARY>
/// word 应用对象
///
private Microsoft.Office.Interop.Word.Application _wordApplication;
/// <SUMMARY></SUMMARY>
/// word 文件对象
///
private Microsoft.Office.Interop.Word.Document _wordDocument;
/// <SUMMARY></SUMMARY>
/// 创建文档
///
public void CreateAWord()
{
//实例化word应用对象
this._wordApplication = new Microsoft.Office.Interop.Word.ApplicationClass();
Object myNothing = System.Reflection.Missing.Value;
this._wordDocument = this._wordApplication.Documents.Add(ref myNothing, ref myNothing, ref myNothing, ref myNothing);
}
/// <SUMMARY></SUMMARY>
/// 添加页眉
///
/// <PARAM name="pPageHeader" />
public void SetPageHeader(string pPageHeader)
{
//添加页眉
this._wordApplication.ActiveWindow.View.Type =Microsoft .Office .Interop .Word.WdViewType.wdOutlineView;
this._wordApplication.ActiveWindow.View.SeekView = Microsoft.Office.Interop.Word.WdSeekView.wdSeekPrimaryHeader;
this._wordApplication.ActiveWindow.ActivePane.Selection.InsertAfter(pPageHeader);
//设置中间对齐
this._wordApplication.Selection.ParagraphFormat.Alignment =Microsoft .Office .Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter;
//跳出页眉设置
this._wordApplication.ActiveWindow.View.SeekView = Microsoft.Office.Interop.Word.WdSeekView.wdSeekMainDocument;
}
/// <SUMMARY></SUMMARY>
/// 插入文字
///
/// <PARAM name="pText" />文本信息
/// <PARAM name="pFontSize" />字体打小
/// <PARAM name="pFontColor" />字体颜色
/// <PARAM name="pFontBold" />字体粗体
/// <PARAM name="ptextAlignment" />方向
public void InsertText(string pText, int pFontSize, Microsoft.Office.Interop.Word.WdColor pFontColor, int pFontBold, Microsoft.Office.Interop.Word.WdParagraphAlignment ptextAlignment)
{
//设置字体样式以及方向
this._wordApplication.Application.Selection.Font.Size = pFontSize;
this._wordApplication.Application.Selection.Font.Bold = pFontBold;
this._wordApplication.Application.Selection.Font.Color= pFontColor;
this._wordApplication.Application.Selection.ParagraphFormat.Alignment = ptextAlignment;
this._wordApplication.Application.Selection.TypeText(pText);
}
/// <SUMMARY></SUMMARY>
/// 换行
///
public void NewLine()
{
//换行
this._wordApplication.Application.Selection.TypeParagraph();
}
/// <SUMMARY></SUMMARY>
/// 插入一个图片
///
/// <PARAM name="pPictureFileName" />
public void InsertPicture(string pPictureFileName)
{
object myNothing = System.Reflection.Missing.Value;
//图片居中显示
this._wordApplication.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter;
this._wordApplication.Application.Selection.InlineShapes.AddPicture(pPictureFileName, ref myNothing, ref myNothing, ref myNothing);
public class BiultReportForm
{
/// <SUMMARY></SUMMARY>
/// word 应用对象
///
private Microsoft.Office.Interop.Word.Application _wordApplication;
/// <SUMMARY></SUMMARY>
/// word 文件对象
///
private Microsoft.Office.Interop.Word.Document _wordDocument;
/// <SUMMARY></SUMMARY>
/// 创建文档
///
public void CreateAWord()
{
//实例化word应用对象
this._wordApplication = new Microsoft.Office.Interop.Word.ApplicationClass();
Object myNothing = System.Reflection.Missing.Value;
this._wordDocument = this._wordApplication.Documents.Add(ref myNothing, ref myNothing, ref myNothing, ref myNothing);
}
/// <SUMMARY></SUMMARY>
/// 添加页眉
///
/// <PARAM name="pPageHeader" />
public void SetPageHeader(string pPageHeader)
{
//添加页眉
this._wordApplication.ActiveWindow.View.Type =Microsoft .Office .Interop .Word.WdViewType.wdOutlineView;
this._wordApplication.ActiveWindow.View.SeekView = Microsoft.Office.Interop.Word.WdSeekView.wdSeekPrimaryHeader;
this._wordApplication.ActiveWindow.ActivePane.Selection.InsertAfter(pPageHeader);
//设置中间对齐
this._wordApplication.Selection.ParagraphFormat.Alignment =Microsoft .Office .Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter;
//跳出页眉设置
this._wordApplication.ActiveWindow.View.SeekView = Microsoft.Office.Interop.Word.WdSeekView.wdSeekMainDocument;
}
/// <SUMMARY></SUMMARY>
/// 插入文字
///
/// <PARAM name="pText" />文本信息
/// <PARAM name="pFontSize" />字体打小
/// <PARAM name="pFontColor" />字体颜色
/// <PARAM name="pFontBold" />字体粗体
/// <PARAM name="ptextAlignment" />方向
public void InsertText(string pText, int pFontSize, Microsoft.Office.Interop.Word.WdColor pFontColor, int pFontBold, Microsoft.Office.Interop.Word.WdParagraphAlignment ptextAlignment)
{
//设置字体样式以及方向
this._wordApplication.Application.Selection.Font.Size = pFontSize;
this._wordApplication.Application.Selection.Font.Bold = pFontBold;
this._wordApplication.Application.Selection.Font.Color= pFontColor;
this._wordApplication.Application.Selection.ParagraphFormat.Alignment = ptextAlignment;
this._wordApplication.Application.Selection.TypeText(pText);
}
/// <SUMMARY></SUMMARY>
/// 换行
///
public void NewLine()
{
//换行
this._wordApplication.Application.Selection.TypeParagraph();
}
/// <SUMMARY></SUMMARY>
/// 插入一个图片
///
/// <PARAM name="pPictureFileName" />
public void InsertPicture(string pPictureFileName)
{
object myNothing = System.Reflection.Missing.Value;
//图片居中显示
this._wordApplication.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter;
this._wordApplication.Application.Selection.InlineShapes.AddPicture(pPictureFileName, ref myNothing, ref myNothing, ref myNothing);
博思aippt
2024-07-20 广告
2024-07-20 广告
作为深圳市博思云创科技有限公司的工作人员,对于Word文档生成PPT的操作,我们有以下建议:1. 使用另存为功能:在Word中编辑完文档后,点击文件->另存为,选择PowerPoint演示文稿(*.pptx)格式,即可将文档内容转换为PPT...
点击进入详情页
本回答由博思aippt提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |