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);
                }  
  • 相关阅读:
    系统运行缓慢,CPU 100%,以及Full GC次数过多问题的排查思路
    微阵列杂交(Microarray Hybridization)
    autocad2018安装笔记
    java基础 大数类
    leetCode 23
    java语言基础 String类
    定时任务cronie
    Linux-vim使用操作大全
    计网期末复习题目
    操作系统期末复习题
  • 原文地址:https://www.cnblogs.com/nygfcn1234/p/3600743.html
Copyright © 2011-2022 走看看