private void saveTemplate(Word.Document doc)
        {
            object FileName = templatePath;
            object FileFormat = Word.WdSaveFormat.wdFormatXMLTemplate;
            object LockComments = false;
            object Password = System.Reflection.Missing.Value;
            object AddToRecentFiles = false;
            object WritePassword = System.Reflection.Missing.Value;
            object ReadOnlyRecommended = false;
            object EmbedTrueTypeFonts = false;
            object SaveNativePictureFormat = false;
            object SaveFormsData = false;
            object SaveAsAOCELetter = false;
            object Encoding = System.Reflection.Missing.Value;
            object InsertLineBreaks = System.Reflection.Missing.Value;
            object AllowSubstitutions = System.Reflection.Missing.Value;
            object LineEnding = System.Reflection.Missing.Value;
            object AddBiDiMarks = System.Reflection.Missing.Value;
            //object CompatibilityMode = Word.WdCompatibilityMode.wdWord2007;

            doc.SaveAs( ref  FileName,
                                        ref  FileFormat,
                                        ref  LockComments,
                                        ref  Password,
                                        ref  AddToRecentFiles,
                                        ref  WritePassword,
                                        ref  ReadOnlyRecommended,
                                        ref  EmbedTrueTypeFonts,
                                        ref  SaveNativePictureFormat,
                                        ref  SaveFormsData,
                                        ref  SaveAsAOCELetter,
                                        ref  Encoding,
                                        ref  InsertLineBreaks,
                                        ref  AllowSubstitutions,
                                        ref  LineEnding,
                                        ref  AddBiDiMarks);
                                        //ref  CompatibilityMode);
        }
Esempio n. 2
0
        private void saveAsPdf(ref Word._Application oWord, ref Word._Document oDoc, string fname)
        {
            object oMissing = System.Reflection.Missing.Value;
            object outputFileName = fname;

            try
            {
                if (File.Exists(outputFileName.ToString()))
                {
                    File.Delete(outputFileName.ToString());
                }

                object fileFormat = Word.WdSaveFormat.wdFormatPDF;

                // Save document into PDF Format
                oDoc.SaveAs(ref outputFileName,
                    ref fileFormat, 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);
            }
            catch (Exception e)
            {
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Documentを別名保存
        /// </summary>
        /// <param name="doc">Document</param>
        /// <param name="oPath">保存先ファイルパス</param>
        public void SaveAs(Word.Document doc, string oPath)
        {
            foreach (char c in Path.GetInvalidPathChars()) {
                if (oPath.Contains(c))
                    throw new FormatException(
                        this.GetType().FullName + "." +
                        MethodBase.GetCurrentMethod().Name);
            }

            object oFmt = Word.WdSaveFormat.wdFormatDocumentDefault; // MS-Word(docx) Format
            doc.SaveAs(
                FileName: oPath,
                FileFormat: oFmt);
        }
 public void SaveAsPDF(MSWord._Document myWordDoc, string targetPath, out bool success)
 {
     Object fileformat = MSWord.WdSaveFormat.wdFormatPDF;
     Object missing = System.Reflection.Missing.Value;
     try
     {
         myWordDoc.SaveAs(targetPath, fileformat);
         success = true;
     }
     catch (Exception ex)
     {
         success = false;
         Log.LogHelper.AddException(ex.Message, true);
     }
 }
Esempio n. 5
0
 /// <summary>  
 /// 文档另存为其他文件名  
 /// </summary>  
 /// <param name="fileName">文件名</param>  
 /// <param name="wDoc">Document对象</param>  
 public static bool SaveAs(string fileName, Word.Document wDoc)
 {
     Object FileName = fileName; // 文档的名称。默认值是当前文件夹名和文件名。如果文档在以前没有保存过,则使用默认名称(例如,Doc1.doc)。如果已经存在具有指定文件名的文档,则会在不先提示用户的情况下改写文档。
     Object FileFormat = Word.WdSaveFormat.wdFormatDocument; // 文档的保存格式。可以是任何 WdSaveFormat 值。要以另一种格式保存文档,请为 SaveFormat 属性指定适当的值。
     Object LockComments = false; // 如果为 true,则锁定文档以进行注释。默认值为 false。
     Object Password = System.Type.Missing; // 用来打开文档的密码字符串。(请参见下面的备注。)
     Object AddToRecentFiles = false; // 如果为 true,则将该文档添加到“文件”菜单上最近使用的文件列表中。默认值为 true。
     Object WritePassword = System.Type.Missing; // 用来保存对文件所做更改的密码字符串。(请参见下面的备注。)
     Object ReadOnlyRecommended = false; // 如果为 true,则让 Microsoft Office Word 在打开文档时建议只读状态。默认值为 false。
     Object EmbedTrueTypeFonts = false; //如果为 true,则将 TrueType 字体随文档一起保存。如果省略的话,则 EmbedTrueTypeFonts 参数假定 EmbedTrueTypeFonts 属性的值。
     Object SaveNativePictureFormat = true; // 如果图形是从另一个平台(例如,Macintosh)导入的,则 true 表示仅保存导入图形的 Windows 版本。
     Object SaveFormsData = false; // 如果为 true,则将用户在窗体中输入的数据另存为数据记录。
     Object SaveAsAOCELetter = false; // 如果文档附加了邮件程序,则 true 表示会将文档另存为 AOCE 信函(邮件程序会进行保存)。
     Object Encoding = System.Type.Missing; // MsoEncoding。要用于另存为编码文本文件的文档的代码页或字符集。默认值是系统代码页。
     Object InsertLineBreaks = true; // 如果文档另存为文本文件,则 true 表示在每行文本末尾插入分行符。
     Object AllowSubstitutions = false; //如果文档另存为文本文件,则 true 允许 Word 将某些符号替换为外观与之类似的文本。例如,将版权符号显示为 (c)。默认值为 false。
     Object LineEnding = Word.WdLineEndingType.wdCRLF;// Word 在另存为文本文件的文档中标记分行符和换段符。可以是任何 WdLineEndingType 值。
     Object AddBiDiMarks = true;//如果为 true,则向输出文件添加控制字符,以便保留原始文档中文本的双向布局。
     try
     {
         wDoc.SaveAs(ref FileName, ref FileFormat, ref LockComments, ref Password, ref AddToRecentFiles, ref WritePassword
                 , ref ReadOnlyRecommended, ref EmbedTrueTypeFonts, ref SaveNativePictureFormat
                 , ref SaveFormsData, ref SaveAsAOCELetter, ref Encoding, ref InsertLineBreaks, ref AllowSubstitutions
                 , ref LineEnding, ref AddBiDiMarks);
         return true;
     }
     catch (Exception ex)
     {
         string err = string.Format("另存文件出错,错误原因:{0}", ex.Message);
         throw new Exception(err, ex);
     }
 }
Esempio n. 6
0
 public static string SaveDocAsDoc(Word.Document doc,string filename, bool close)
 {
     CheckWinWordProcess();
     object filepath = OUTPUT_PATH + filename+".doc";
     object format = Word.WdSaveFormat.wdFormatDocument;
     doc.SaveAs(ref filepath, ref format, ref MISSING, ref MISSING, ref MISSING, ref MISSING, ref MISSING, ref MISSING, ref MISSING, ref MISSING, ref MISSING, ref MISSING, ref MISSING, ref MISSING, ref MISSING, ref MISSING);
     if (close)
         CloseDoc(doc);
     return (string)filepath;
 }
Esempio n. 7
0
 public static string SaveDocAsXPS(Word.Document doc, bool close)
 {
     CheckWinWordProcess();
     object filepath = TEMP_PATH + "temp.xps";
     object format = Word.WdSaveFormat.wdFormatXPS;
     doc.SaveAs(ref filepath, ref format, ref MISSING, ref MISSING, ref MISSING, ref MISSING, ref MISSING, ref MISSING, ref MISSING, ref MISSING, ref MISSING, ref MISSING, ref MISSING, ref MISSING, ref MISSING, ref MISSING);
     if (close)
         CloseDoc(doc);
     return (string)filepath;
 }
Esempio n. 8
0
 /// <summary>
 /// Copies a document to a specified path.
 /// </summary>
 /// <param name="document">The Document instance.</param>
 /// <param name="path">The path where the new file will be saved.</param>
 /// <param name="saveFormat">The save format.</param>
 /// <exception cref="IOException">When the file cannot be saved.</exception>
 /// <remarks>The document is saved in Unicode little endian encoding.</remarks>
 /// <returns>True if the operation succedes. False otherwise.</returns>
 public bool ShadowCopyDocument(Word.Document document, string path, Word.WdSaveFormat saveFormat)
 {
     try
     {
         Object format = saveFormat;
         Object copyPath = path;
         Object encoding = MsoEncoding.msoEncodingUTF8;
         Object missing = Type.Missing;
         Object originalFilePath = document.FullName;
         Object initialDocSaveFormat = document.SaveFormat;
         document.SaveAs(ref copyPath, ref format, ref missing, ref missing, ref missing, ref missing,
                         ref missing, ref missing, ref missing, ref missing, ref missing, ref encoding,
                         ref missing, ref missing, ref missing, ref missing);
         //Refresh the active instance(required after acquiring chart data from Excel)
         document = addin.Application.ActiveWindow.Document;
         document.SaveAs(ref originalFilePath, ref initialDocSaveFormat, ref missing, ref missing, ref missing, ref missing,
                         ref missing, ref missing, ref missing, ref missing, ref missing, ref missing,
                         ref missing, ref missing, ref missing, ref missing);
     }
     catch (IOException ioex)
     {
         Log.Exception(ioex);
         UserNotifier.Error(ioex.Message);
         return false;
     }
     catch (Exception ex)
     {
         Log.Exception(ex);
         return false;
     }
     return true;
 }
Esempio n. 9
0
        static string SaveW(Wd.Application app, Wd.Document WData)
        {
            //string pth = Directory.GetParent(Directory.GetParent(TemplateFilePath).FullName) + "\\" + TempDir + "TMP" + DateTime.Now.Ticks + ".doc";
            string pth = Environment.CurrentDirectory + "\\Результат.doc";

            WData.SaveAs(pth);

            return pth;
        }
Esempio n. 10
0
        private bool createBookmarks(string targetDoc, int index, Word.Document wordDocPar, object strFileName)
        {
            int docLen = targetDoc.Length;
            string startText ="";
            if (docLen >= 250)
            {
                startText = targetDoc.Substring(0, 250);
            }
            else
            {
                startText = targetDoc;
            }

            Object Nothing = System.Reflection.Missing.Value;

            Word.Range rng = wordDocPar.Range();
            rng.Find.ClearFormatting();
            object findText = startText;

            if (rng.Find.Execute(ref findText,
                ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing,
                ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing,
                ref Nothing, ref Nothing))
            {
                // insert_one_bookmark(rng, index, anotherWordDoc);
                int start = rng.Start;
                //end = rng.End;
                object bookmark_rng = wordDocPar.Range(start, start + docLen);
                //MessageBox.Show(index.ToString());
                //MessageBox.Show(start.ToString(), end.ToString());
                string bookmark_name = "ST" + start.ToString(); //
                bookmark_list.Add(bookmark_name);
                wordDocPar.Bookmarks.Add(bookmark_name, ref bookmark_rng);
                //将WordDoc文档对象的内容保存为DOC文档
                wordDocPar.SaveAs(ref   strFileName, ref   Nothing, ref   Nothing, ref   Nothing, ref   Nothing, ref   Nothing, ref   Nothing, ref   Nothing, ref   Nothing, ref   Nothing, ref   Nothing, ref   Nothing, ref   Nothing, ref   Nothing, ref   Nothing, ref   Nothing);
                return true;
            }
            else
            {
                return false;
                //MessageBox.Show("Text not found.");
            }
        }