/// </summary>
/// <param name="objFileRelativePath">导入Word文件拷贝在服务器上的全路径</param>
/// <param name="sScript">出错时的提示信息</param>
/// <param name="listRptID">导入生成报告的ID数组</param>
/// <param name="strXMLPath">用于数据验证的XML文件名</param>
/// <param name="strButID">导入按钮ID</param>
private void ImportWord(ref object objFileRelativePath, StringBuilder sScript, ref ArrayList listRptID,string strXMLPath,string strButID)
{
Microsoft.Office.Interop.Word.ApplicationClass wordApp = null;
object Missing = Type.Missing;
Microsoft.Office.Interop.Word.Document wordDoc = null;
using (clsDbAccept db = new clsDbAccept())
{
try
{
wordApp = new Microsoft.Office.Interop.Word.ApplicationClass();
wordDoc = wordApp.Documents.Open(ref objFileRelativePath, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing,
ref Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing);
//导入报告的创建者为当前用户
string strCreater = Session["UserID"] != null ? Session["UserID"].ToString() : string.Empty;
#region XML文件,用于校验上传Word中数据的正确性
strXMLPath = this.Server.MapPath(clsCommon.GetUrl(this, strXMLPath));
DataSet dsXML = ReadXMLFile(strXMLPath);
//所有报告信息构成的表
DataTable dtTable = null;
//单个具体报告构成的表
DataTable dtCol = null;
//特殊报告项验证信息构成的表
DataTable dtColCondition = null;
DataView dvTable = null;
DataView dvCol = null;
if (dsXML != null && dsXML.Tables.Count > 1)
{
dtTable = dsXML.Tables[0];
dtCol = dsXML.Tables[1];
if (dsXML.Tables.Count > 2)
{
dtColCondition = dsXML.Tables[2];
}
}
if (dtTable != null && dtTable.Rows.Count > 0)
{
dvTable =
C#代码实现导入Word并进行数据验证

这段代码展示了如何使用C#的Microsoft.Office.Interop.Word库导入Word文档,并结合XML文件进行数据验证。方法包括打开Word文档,读取内容,进行数据校验,以及根据特定模板(例如execWord_19)处理数据。
最低0.47元/天 解锁文章

891

被折叠的 条评论
为什么被折叠?



