C#获取word 复选框问题

DLL: Aspose.Words

 

  //判断表的列是否有word书签
                if (doc.Range.Bookmarks.Any(p => p.Name.ToLower() == columnName.ToLower()))
                {
                    //单选框
                    if ("YD,FC,ZBZH,WCFWNCJ,CLCW,CLFT,YTWSHT".Contains(columnName.ToUpper()))
                    {
                        Shape shape = (Shape)doc.GetChild(NodeType.Shape, j, true);
                        if (shape != null)
                        {
                            OleControl oleControl = shape.OleFormat.OleControl;
                            if (oleControl.IsForms2OleControl)
                            {
                                Forms2OleControl checkBox = (Forms2OleControl)oleControl;
                                switch (checkBox.Caption)
                                {
                                    case "用地":
                                        columnName = "YD";
                                        break;
                                    case "房产":
                                        columnName = "FC";
                                        break;
                                    case "坐标转换":
                                        columnName = "ZBZH";
                                        break;
                                    case "误差范围内重界":
                                        columnName = "WCFWNCJ";
                                        break;
                                    case "测量错误":
                                        columnName = "CLCW";
                                        break;
                                    case "使用分图":
                                        columnName = "CLFT";
                                        break;
                                    case "原图为手画图":
                                        columnName = "YTWSHT";
                                        break;
                                }
                                updVal = checkBox.Value;
                                j++;
                            }
                        }


                    }
                }

  

 Aspose.Words.Document doc = new Aspose.Words.Document("word路径");
 foreach (DataColumn column in SQBModel.Tables[0].Columns)
 {
     //判断表的列是否有word书签
     if (doc.Range.Bookmarks.Any(p => p.Name.ToLower() == column.ColumnName.ToLower()))
     {
         string updVal = doc.Range.Bookmarks[column.ColumnName] != null ? doc.Range.Bookmarks[column.ColumnName].Text.Trim().Replace("\a", "") : SQBModel.Tables[0].Rows[i][column.ColumnName].ToString().Trim().Replace("\a", "");
         var mark = System.Text.RegularExpressions.Regex.Replace(updVal, @"[\u4e00-\u9fa5]", "").Replace("\a", "");
         //获取复选框的特殊字符编码(根据word而定 我的%EF%81%92是选中 %EF%82%A3是没选中 )
         var urlEncode = HttpUtility.UrlEncode(mark);
         //选中
         if (urlEncode.ToUpper() == "%EF%81%92")
         {
             updVal = "1";
         }//没选中
         else if (urlEncode.ToUpper() == "%EF%82%A3")
         {
             updVal = "0";
         }
       }
  }

 

posted @ 2021-04-01 16:39  流星泪  阅读(506)  评论(0编辑  收藏  举报