本文整理汇总了C#中Microsoft.Office.Interop.Word.SaveAs方法的典型用法代码示例。如果您正苦于以下问题:C# Microsoft.Office.Interop.Word.SaveAs方法的具体用法?C# Microsoft.Office.Interop.Word.SaveAs怎么用?C# Microsoft.Office.Interop.Word.SaveAs使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.Office.Interop.Word
的用法示例。
在下文中一共展示了Microsoft.Office.Interop.Word.SaveAs方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: saveTemplate
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);
}
示例2: saveAsPdf
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)
{
}
}
示例3: SaveAs
/// <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);
}
示例4: SaveAsPDF
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);
}
}
示例5: SaveAs
/// <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);
}
}
示例6: SaveDocAsDoc
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;
}
示例7: SaveDocAsXPS
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;
}
示例8: ShadowCopyDocument
/// <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;
}
示例9: SaveW
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;
}
示例10: createBookmarks
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.");
}
}