使用Word API进行转换时以编程方式避免警告 [英] Programatically avoid warnings while converting using word api

查看:78
本文介绍了使用Word API进行转换时以编程方式避免警告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在使用以下功能将html文档转换为纯文本

Hi,

i am converting html document into plain text using the below funcion

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.DisplayAlerts = Word.WdAlertLevel.wdAlertsNone;
            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;
                 
                // Source document open here
                // Additional Parameters are not known so that are  
                // set as a missing type
                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);
                // 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);
            }
            catch (Exception ex)
            {
                ZoniacLogger.Error("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;
                }
            }
        }


在执行上述代码时,我得到这样的警告:

链接样式表仅在Web格式文件中受支持.作者:
保存为这种格式,到样式表的所有链接都将丢失"

单击继续"后,它将html文档转换为文本文件.
如何通过程序避免此类警告?
谁能帮助我克服这个问题.等待解决方案.

问候
kumaran


while executing above code , i get a warning like this :

"Linked style sheets are supported only in web format files. By
saving to this format , all links to style sheets would be lost"

After i click "continue" ,it converts the html document into text file.
How can i avoid such warnings through the program ?
Can anybody help me to overcome this problem. waiting for solution.

regards
kumaran

推荐答案

您可以在进行转换之前从html剥离样式表?如果最终文档是纯文本,没有格式,则可以考虑仅剥离自己代码中的HTML标签.如果它是RTF,那显然是行不通的.
You could strip the style sheets from the html before you do the conversion ? If the end document is plain text, no formatting, you could consider just stripping the HTML tags in your own code. If it''s an RTF, that doesn''t work, obviously.


请不要使用答案"按钮发布更多问题.样式表是具有已知格式的HTML标记.您可以使用reguar表达式在html文本中找到它们,然后将其从此处删除.
Please don''t use the ''answer'' button to post more questions. A stylesheet is a HTML tag with a known format. you can use reguar expressions to find them in your html text and then remove them from there.


克里斯蒂安·格劳斯(Christian Graus),

您能说明如何从html
剥离样式表吗?
您能否提供示例代码以从html
剥离样式表
等待您的重播

问候
kumaran
Hi Christian Graus,

Can you show how to strip the style sheets from html

Can you give example code to strip the style sheet from html

waiting for ur replay

regards
kumaran


这篇关于使用Word API进行转换时以编程方式避免警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆