Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/288.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何删除word文档中的符号_C#_Ms Word - Fatal编程技术网

C# 如何删除word文档中的符号

C# 如何删除word文档中的符号,c#,ms-word,C#,Ms Word,我正在使用word apic 2.0应用程序将word文档编程转换为纯文本文件。对于某些文档,由于word文档中可用的符号,该过程处于挂起状态。我想通过编程删除word文档中的符号,或者如何将word文档另存为包含符号的纯文本文件而不挂起 请帮我解决这个问题 下面是示例代码 若您只需要将单词另存为纯文本,那个么最快最简单的方法就是使用DocumentClass的SaveAs方法 您只需要将适当的输出格式设置为第二个参数。 可用符号:这是什么意思?您有任何示例文档吗?@alexD和@Kamyar:

我正在使用word apic 2.0应用程序将word文档编程转换为纯文本文件。对于某些文档,由于word文档中可用的符号,该过程处于挂起状态。我想通过编程删除word文档中的符号,或者如何将word文档另存为包含符号的纯文本文件而不挂起

请帮我解决这个问题

下面是示例代码
若您只需要将单词另存为纯文本,那个么最快最简单的方法就是使用DocumentClass的SaveAs方法

您只需要将适当的输出格式设置为第二个参数。

可用符号:这是什么意思?您有任何示例文档吗?@alexD和@Kamyar:我在问题中给出了代码示例
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;
                }
            }
        }