Example #1
0
        private bool HasText(Word.Shape oShape)
        {
            bool bHasText = false;

            try
            {
                Word.TextFrame txtFrame = oShape.TextFrame;
                if (txtFrame.HasText != 0)
                {
                    bHasText = true;
                }
            }
            catch (Exception e)
            {
                bHasText = false;
            }

            return(bHasText);
        }
Example #2
0
 private int check_Kernel(List<OfficeElement> ls)
 {
     int points = 0, i;
     int curPart = -1;            //当前正在分析哪一部分的考点
     for (i = 0; i < ls.Count; i++)
     {
         OfficeElement oe = ls[i];
         #region 具体考点对象定位
         if (oe.AttribName == "Root")
             continue;
         if (oe.AttribName == "Documents")
             continue;
         if (oe.AttribName == "Paragraph")
         {
             #region 段落定位
             try
             {
                 int paraIdx = int.Parse(oe.AttribValue);
                 stuPara = stuDoc.Paragraphs[paraIdx];
                 ansPara = ansDoc.Paragraphs[paraIdx];
             }
             catch
             {
                 points = 0;
                 break;
             }
             #endregion
             curPart = PART_PARAGRAPH;
             continue;
         }
         if (oe.AttribName == "Table")
         {
             #region 表格定位
             try
             {
                 int tabIdx = int.Parse(oe.AttribValue);
                 stuTab = stuDoc.Tables[tabIdx];
                 ansTab = ansDoc.Tables[tabIdx];
             }
             catch
             {
                 points = 0;
                 break;
             }
             #endregion
             curPart = PART_TABLE;
             continue;
         }
         if (oe.AttribName == "Cell")
         {
             #region 单元格定位
             try
             {
                 int rowIdx, colIdx, commaIdx;
                 commaIdx = oe.AttribValue.IndexOf(',');
                 rowIdx = int.Parse(oe.AttribValue.Substring(0, commaIdx));
                 colIdx = int.Parse(oe.AttribValue.Substring(commaIdx + 1));
                 stuCell = stuTab.Cell(rowIdx, colIdx);
                 ansCell = ansTab.Cell(rowIdx, colIdx);
             }
             catch
             {
                 points = 0;
                 break;
             }
             #endregion
             curPart = PART_CELL;
             continue;
         }
         if (oe.AttribName == "Textbox")
         {
             #region 文本框定位
             try
             {
                 int tbIdx = int.Parse(oe.AttribValue);
                 object ob = tbIdx;
                 stuSp = stuDoc.Shapes.get_Item(ref ob);
                 ansSp = ansDoc.Shapes.get_Item(ref ob);
                 stuTf = stuSp.TextFrame;
                 ansTf = ansSp.TextFrame;
             }
             catch
             {
                 points = 0;
                 break;
             }
             #endregion
             curPart = PART_TEXTBOX;
             continue;
         }
         if (oe.AttribName == "PageSetup")
         {
             #region 页面设置定位
             try
             {
                 stuPs = stuDoc.PageSetup;
                 ansPs = ansDoc.PageSetup;
             }
             catch
             {
                 points = 0;
                 break;
             }
             #endregion
             continue;
         }
         #endregion
         #region 段落属性判分
         if (curPart == PART_PARAGRAPH)
         {
             switch (oe.AttribName)
             {
                 case "Indent":
                     break;
                 case "Font":
                     stuRange = stuPara.Range;
                     ansRange = ansPara.Range;
                     break;
                 case "Dropcap":
                     stuDc = stuPara.DropCap;
                     ansDc = ansPara.DropCap;
                     break;
                 case "TextColumns":
                     stuTc = stuPara.Range.PageSetup.TextColumns;
                     ansTc = ansPara.Range.PageSetup.TextColumns;
                     break;
                 #region 段落部分
                 case "Alignment":
                     if (stuPara.Alignment == ansPara.Alignment)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "CharacterUnitFirstLineIndent":
                     if (stuPara.CharacterUnitFirstLineIndent == ansPara.CharacterUnitFirstLineIndent)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "CharacterUnitLeftIndent":
                     if (stuPara.CharacterUnitLeftIndent == ansPara.CharacterUnitLeftIndent)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "CharacterUnitRightIndent":
                     if (stuPara.CharacterUnitRightIndent == ansPara.CharacterUnitRightIndent)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "LineUnitBefore":
                     if (stuPara.LineUnitBefore == ansPara.LineUnitBefore)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "LineUnitAfter":
                     if (stuPara.LineUnitAfter == ansPara.LineUnitAfter)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "LineSpacingRule":
                     if (stuPara.LineSpacingRule == ansPara.LineSpacingRule)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "LineSpacing":
                     if (stuPara.LineSpacing == ansPara.LineSpacing)
                         points = int.Parse(oe.AttribValue);
                     break;
                 #endregion
                 #region 文字部分
                 case "Text":
                     if (stuRange.Text == ansRange.Text)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "FontSize":
                     if (stuRange.Font.Size == ansRange.Font.Size)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "FontName":
                     if (stuRange.Font.Name == ansRange.Font.Name)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "Bold":
                     if (stuRange.Font.Bold == ansRange.Font.Bold)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "Italic":
                     if (stuRange.Font.Italic == ansRange.Font.Italic)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "Underline":
                     if (stuRange.Font.Underline == ansRange.Font.Underline)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "UnderlineColor":
                     if (stuRange.Font.UnderlineColor == ansRange.Font.UnderlineColor)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "ForeColor":
                     if (stuRange.Font.Color == ansRange.Font.Color)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "HighLightColor":
                     if (stuRange.HighlightColorIndex == ansRange.HighlightColorIndex)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "Superscript":
                     if (stuRange.Font.Superscript == ansRange.Font.Superscript)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "Subscript":
                     if (stuRange.Font.Subscript == ansRange.Font.Subscript)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "Spacing":
                     if (stuRange.Font.Spacing == ansRange.Font.Spacing)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "Animation":
                     if (stuRange.Font.Animation == ansRange.Font.Animation)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "BackgroundPatternColor":
                     if (stuRange.Shading.BackgroundPatternColor == ansRange.Shading.BackgroundPatternColor)
                         points = int.Parse(oe.AttribValue);
                     break;
                 #endregion
                 #region 首字下沉
                 case "Position":
                     if (stuDc.Position == ansDc.Position)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "DcFontName":
                     if (stuDc.FontName == ansDc.FontName)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "LinesToDrop":
                     if (stuDc.LinesToDrop == ansDc.LinesToDrop)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "DistanceFromText":
                     if (stuDc.DistanceFromText == ansDc.DistanceFromText)
                         points = int.Parse(oe.AttribValue);
                     break;
                 #endregion
                 #region 分栏与栏宽
                 case "TextColumnsCount":
                     if (stuTc.Count == ansTc.Count)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "TextColumnsWidth":
                     if (stuTc.Width == ansTc.Width)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "TextColumnsSpacing":
                     if (stuTc.Spacing == ansTc.Spacing)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "TextColumnsLineBetween":
                     if (stuTc.LineBetween == ansTc.LineBetween)
                         points = int.Parse(oe.AttribValue);
                     break;
                 #endregion
             }
             continue;
         }
         #endregion
         #region 表格属性判分
         if (curPart == PART_TABLE)
         {
             switch (oe.AttribName)
             {
                 case "Rows":
                     if (stuTab.Rows.Count == ansTab.Rows.Count)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "Columns":
                     if (stuTab.Columns.Count == ansTab.Columns.Count)
                         points = int.Parse(oe.AttribValue);
                     break;
             }
             continue;
         }
         #endregion
         #region 单元格属性判分
         if (curPart == PART_CELL)
         {
             switch (oe.AttribName)
             {
                 case "Text":
                     if (stuCell.Range.Text == ansCell.Range.Text)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "Height":
                     if (stuCell.Height == ansCell.Height)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "Width":
                     if (stuCell.Width == ansCell.Width)
                         points = int.Parse(oe.AttribValue);
                     break;
             }
             continue;
         }
         #endregion
         #region 文本框属性判分
         if (curPart == PART_TEXTBOX)
         {
             switch (oe.AttribName)
             {
                 case "Text":
                     if (stuTf.TextRange.Text == ansTf.TextRange.Text)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "Orientation":
                     if (stuTf.Orientation == ansTf.Orientation)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "FontName":
                     if (stuTf.TextRange.Font.Name == ansTf.TextRange.Font.Name)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "FontSize":
                     if (stuTf.TextRange.Font.Size == ansTf.TextRange.Font.Size)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "ForeColor":
                     if (stuTf.TextRange.Font.Color == ansTf.TextRange.Font.Color)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "HighLightColor":
                     if (stuTf.TextRange.HighlightColorIndex == ansTf.TextRange.HighlightColorIndex)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "Spacing":
                     if (stuTf.TextRange.Font.Spacing == ansTf.TextRange.Font.Spacing)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "Alignment":
                     if (stuTf.TextRange.ParagraphFormat.Alignment == ansTf.TextRange.ParagraphFormat.Alignment)
                         points = int.Parse(oe.AttribValue);
                     break;
             }
             continue;
         }
         #endregion
         #region 页面设置属性判分
         if (curPart == PART_PAGESETUP)
         {
             switch (oe.AttribName)
             {
                 case "TopMargin":
                     if (stuPs.TopMargin == ansPs.TopMargin)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "BottomMargin":
                     if (stuPs.BottomMargin == ansPs.BottomMargin)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "LeftMargin":
                     if (stuPs.LeftMargin == ansPs.LeftMargin)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "RightMargin":
                     if (stuPs.RightMargin == ansPs.RightMargin)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "HeaderDistance":
                     if (stuPs.HeaderDistance == ansPs.HeaderDistance)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "FooterDistance":
                     if (stuPs.FooterDistance == ansPs.FooterDistance)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "Orientation":
                     if (stuPs.Orientation == ansPs.Orientation)
                         points = int.Parse(oe.AttribValue);
                     break;
                 case "GutterPos":
                     if (stuPs.GutterPos == ansPs.GutterPos)
                         points = int.Parse(oe.AttribValue);
                     break;
             }
             continue;
         }
         #endregion
     }
     return points;
 }