如何解决如何删除Word文档中的符号
| 我正在使用word api(C#2.0应用程序)将Word文档转换为纯文本文件。对于某些文档,由于单词文档中可用的符号,导致挂起过程。我想以编程方式删除Word文档中的那些符号,或者如何将Word文档另存为纯文本文件(其中包含符号而不会挂起)。 请帮助我解决问题 这是示例代码private void TextFileConvertion(string strsource,string strtarget)
{
// Use for the parameter whose type are not kNown or
// say Missing
object UnkNown = Type.Missing;
//Creating the instance of Word Application
Word.Application newApp = new Word.Application();
newApp.AutomationSecurity = Microsoft.Office.Core.MsoAutomationSecurity.msoAutomationSecurityForcedisable;
newApp.displayAlerts = Word.WDalertLevel.wDalertsNone;
Word.Document doc = null;
try
{
lblProgress.Text = \"Converting \" + strsource + \" into Text file is under process.\";
Application.DoEvents();
// specifying the Source & Target file names
object Source = strsource;
object Target = strtarget;
object objTrue = true;
object objFalse = false;
// Source document open here
// Additional Parameters are not kNown so that are
// set as a missing type
try
{
newApp.Visible = false;
doc = newApp.Documents.Open(ref Source,ref UnkNown,ref UnkNown);
}
catch (Exception exp)
{
ZoniacLogger.Error(\"Exception : \" + exp.Message + \" Stack Trace : \" + exp.StackTrace);
}
if (doc.ReadOnlyRecommended == true)
return;
// Specifying the format in which you want the output file
object format = Word.WdSaveFormat.wdFormatText;
//Changing the format of the document
newApp.ActiveDocument.SaveAs(ref Target,ref format,ref UnkNown);
//if (doc.ReadOnlyRecommended == true)
// SetuncheckReadonly(doc,strsource);
//intTxtCounter = intTxtCounter + 1;
strTxtCounter = \"OK\";
}
catch (Exception ex)
{
strTxtCounter = \"Failed\";
ZoniacLogger.Error(\"<TextFileConvertion> Exception : \" + ex.Message + \" Stack Trace : \" + ex.StackTrace);
}
finally
{
if (newApp != null)
{
// for closing the application
newApp.Quit(ref UnkNown,ref UnkNown);
newApp = null;
}
}
}
解决方法
如果仅将单词保存为纯文本,那么要做的最快和最简单的方法就是使用DocumentClass的SaveAs方法吗?
MSDN上的Document.SaveAs
您只需要设置适当的输出格式作为第二个参数。
保存格式
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。