• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
大个子
青岛张恩亮
博客园    首页    新随笔    联系   管理    订阅  订阅

.net实现word里面插入图片

using Word=Microsoft.Office.Interop.Word; //先要引入office安装下的msword.olb文件

方法是:

 

  protected void Button1_Click(object sender, EventArgs e)
    {
        OutPut();
    }
     private void OutPut()
    {
               
         object oMissing = System.Reflection.Missing.Value;
object Range=System.Reflection.Missing.Value;

 

        Word.Application oWord;
       
        Word.Document oDoc;
        oWord = new Word.ApplicationClass();
        oWord.Visible = true;
        oDoc = oWord.Documents.Add(ref oMissing, ref oMissing, ref oMissing, ref oMissing);
        oWord.Selection.Font.Bold = 1;
        oWord.Selection.Font.Size = 18;
        oWord.Selection.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;
        oWord.Selection.InlineShapes.AddPicture("http://www.gzpxmtj.gov.cn:8001/SafetyNet/WebCharts/0c81faaa-8141-44f6-9497-e5cf2bd7cbdb.Png", ref oMissing, ref oMissing, ref Range);

public void xiazai()//写入流下载word

{


       Response.Clear();
        Response.Buffer = true;
        Response.Charset = "GB2312";
        Response.AppendHeader("Content-Disposition", "attachment;filename=out.doc");
        Response.ContentType = "application/ms-word";
        this.EnableViewState = false;
        System.IO.StringWriter swOut = new System.IO.StringWriter();
        System.IO.BinaryWriter ss=new System.IO.BinaryWriter(
        HtmlTextWriter hTw = new HtmlTextWriter(swOut);

htw.write("张恩亮");
        
           
       Response.Write(swOut.ToString());
       Response.End();


    }

 

      

posted @ 2008-12-18 16:44  张恩亮  阅读(611)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3