zoukankan      html  css  js  c++  java
  • 生成word并保存

    saveas方法只能用绝对路径,不能用相对路径,这个问题倒腾了好久,并且 Microsoft.Office.Interop.Word._Application 需要设置为不可见

     object oMissing = System.Reflection.Missing.Value;
                //创建一个Word应用程序实例  
                Microsoft.Office.Interop.Word._Application oWord = new Microsoft.Office.Interop.Word.Application();
                //设置为不可见  
                oWord.Visible = true;
                Microsoft.Office.Interop.Word._Document oDoc = oWord.Documents.Add(ref oMissing, ref oMissing, ref oMissing, ref oMissing);
                //弹出保存文件对话框,保存生成的Word  
                SaveFileDialog sfd = new SaveFileDialog();
                sfd.Filter = "Word Document(*.doc)|*.doc";
                sfd.DefaultExt = "Word Document(*.doc)|*.doc";
                if (sfd.ShowDialog() == DialogResult.OK)
                {
                    object filename = sfd.FileName;
    
                    oDoc.SaveAs(ref filename, ref oMissing, ref oMissing, ref oMissing,
                    ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
                    ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
                    ref oMissing, ref oMissing);
                    oDoc.Close(ref oMissing, ref oMissing, ref oMissing);
                    //关闭word  
                    oWord.Quit(ref oMissing, ref oMissing, ref oMissing);
                }  
  • 相关阅读:
    神秘题目4
    神秘题目3
    神秘题目2
    AC自动机
    Fence Obstacle Course 题解
    Fractal Streets
    龟速乘
    快速幂
    Stall Reservation
    Sunscreen
  • 原文地址:https://www.cnblogs.com/nygfcn1234/p/3600743.html
Copyright © 2011-2022 走看看