How to remove symbols in a word document
i am programaticall converting word document into a plain text file using word api(c# 2.0 application). For some documents the process in hanging due to symbols available in the word document. i want to remove those symbols in word document programatically or how could i saveas a word document into plain text file which contains symbols without hanging.
help me please to over come the problem
here is the sample code
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, ref Unknown,
ref Unknown, ref Unknown, ref Unknown,
开发者_运维知识库 ref Unknown, ref Unknown, ref Unknown,
ref Unknown, ref Unknown, ref Unknown,
ref Unknown, 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, ref Unknown, ref Unknown,
ref Unknown, ref Unknown, ref Unknown,
ref Unknown, ref Unknown, ref Unknown,
ref Unknown, ref Unknown, ref Unknown,
ref Unknown, 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, ref Unknown);
newApp = null;
}
}
}
If save word as plain text is all what you need to do may be fastest and simplest way to do this is use SaveAs method of the DocumentClass?
Document.SaveAs on MSDN
You just need to set appropriate output format as the second parameter. Save formats
精彩评论