Word“消息筛选器显示应用程序正在使用中”

最近遇到这样一个问题,.Net生成Word当数据量过大时,会引发异常“消息筛选器显示应用程序正在使用中”,几十条数据没事。

后来发现原因是由于大量的拼写错误(Word会默认检查每个字的拼写嘛),Word弹出的对话框阻止了生成所以引发了异常。

解决方法仅需将Word的拼写检查取消,“文件”–>”选项”–>”校对”,将下图红框内的勾选取消即可。

消息筛选器显示应用程序正在使用中

也可在操作Word时添加如下代码,将拼写检查和显示拼写错误禁用。

Word.Document oDoc = new Word.Document();

oDoc.SpellingChecked=false;
oDoc.ShowSpellingErrors=false;

.Net XML 与 DataSet 相互转换

.Net 的XML与DataSet 相互转换代码模版:

public static DataSet ConvertXMLFileToDataSet(string xmlText)
{

StringReader stream = null;

     XmlTextReader reader = null;

     try

{

         DataSet xmlDS = new DataSet();

stream = new StringReader(xmlText);

reader = new XmlTextReader(stream);

xmlDS.ReadXml(reader);

reader.Close();

         return xmlDS;

}

     catch (System.Exception ex)

{

reader.Close();

}

}


public static string DataToXml(DataSet ds)

{

     if (ds != null && ds.Tables.Count > 0)

{

         MemoryStream ms = null;

         XmlTextWriter XmlWt = null;

         try

{

ms = new MemoryStream();
              
XmlWt = new XmlTextWriter(ms, Encoding.Unicode);

//获取ds中的数据

ds.WriteXml(XmlWt);

int count = (int)ms.Length;

byte[] temp = new byte[count];

ms.Seek(0, SeekOrigin.Begin);

ms.Read(temp, 0, count);

//返回Unicode编码的文本

UnicodeEncoding ucode = new UnicodeEncoding();

string returnValue = ucode.GetString(temp).Trim();

return returnValue;

}

catch (System.Exception ex)

{


}

finally

{

if (XmlWt != null)

{

XmlWt.Close();

ms.Close();

}

}

}

else
       
return “”;
        
}