Exemplo n.º 1
0
 //检查图表考点,参数分别为考点列表、继续检索的位置、学生图表、答案图表、学生图表对象、答案图表对象
 private int check_Chart(List<OfficeElement> ls, int startPosition, 
     Excel.Chart stuCh, Excel.Chart ansCh, Excel.ChartObject stuObj, Excel.ChartObject ansObj)
 {
     int thisPoint = 0;
     int i, j;
     if (stuCh == null)
         return 0;
     for (i = startPosition; i < ls.Count; i++)
     {
         OfficeElement oe = ls[i];
         if (oe.AttribName == "Value")          //图表数值
         {
             List<List<string>> stuList, ansList;
             stuList = GetValue(stuCh, stuXls);
             ansList = GetValue(ansCh, ansXls);
             for (i = 0; i < stuList.Count && i < ansList.Count; i++)
             {
                 for (j = 0; j < stuList[i].Count && j < ansList[i].Count; j++ )
                     if (stuList[i][j] == ansList[i][j])
                         thisPoint++;
             }
             continue;
         }
         if (oe.AttribName == "Title")          //图表标题
         {
             if (ansCh.ChartTitle.Text == stuCh.ChartTitle.Text)
                 thisPoint += int.Parse(oe.AttribValue);
             continue;
         }
         if (oe.AttribName == "Type")            //图表类型
         {
             if (ansCh.ChartType == stuCh.ChartType)
                 thisPoint += int.Parse(oe.AttribValue);
             continue;
         }
         if (oe.AttribName == "Name")            //图表的工作表名称(只对独立图表有效)
         {
             if (stuObj == null && stuCh.Name == ansCh.Name)
                     thisPoint += int.Parse(oe.AttribValue);
             continue;
         }
         if (oe.AttribName == "Legend")          //图例
         {
             if (stuCh.HasLegend == true && stuCh.Legend.Position == ansCh.Legend.Position)
                 thisPoint += int.Parse(oe.AttribValue);
             continue;
         }
         if (oe.AttribName == "Position")        //图表位置(只对嵌入式的图表有效)
         {
             if (stuObj != null && checkRangeSame(stuObj.TopLeftCell, ansObj.TopLeftCell)
                 && checkRangeSame(stuObj.BottomRightCell, ansObj.BottomRightCell))
                 thisPoint += int.Parse(oe.AttribValue);
             continue;
         }
         if (oe.AttribName == "DataLabels")      //数据标志
         {
             bool check = false, right = true;
             foreach (Excel.Series ser in (Excel.SeriesCollection)ansCh.SeriesCollection(nullobj))
                 if (ser.HasDataLabels == true)
                 {
                     check = true;
                     break;
                 }
             foreach (Excel.Series ser in (Excel.SeriesCollection)stuCh.SeriesCollection(nullobj))
                 if (ser.HasDataLabels != check)
                 {
                     right = false;
                     break;
                 }
             if (right)
                 thisPoint += int.Parse(oe.AttribValue);
             continue;
         }
     }
     return thisPoint;
 }
Exemplo n.º 2
0
 //获取图表中的数据
 private List<List<string>> GetValue(Excel.Chart ch, Excel.Workbook xls)
 {
     int i, j, k, state;
     Excel.SeriesCollection sc = (Excel.SeriesCollection)ch.SeriesCollection(nullobj);
     List<List<string>> res = new List<List<string>>();
     for (i = 1; i <= sc.Count; i++)
     {
         res.Add(new List<string>());
         string seriesFormula = sc.Item(i).Formula;
         int firstComma = seriesFormula.IndexOf(',');
         int secondComma = seriesFormula.IndexOf(',', firstComma + 1);
         int thirdComma = seriesFormula.IndexOf(',', secondComma + 1);
         string yValues = seriesFormula.Substring(secondComma + 1, thirdComma - secondComma - 1);
         for (k = 1, state = 0; state == 0 && k <= xls.Worksheets.Count; k++)
         {
             try
             {
                 Excel.Worksheet ws = (Excel.Worksheet)xls.Worksheets[k];
                 Excel.Range yRange = ws.get_Range(yValues, nullobj);
                 for (j = 1; j <= yRange.Cells.Count; j++)
                 {
                     Excel.Range cell = (Excel.Range)yRange.Cells[j, nullobj];
                     res[i - 1].Add(cell.Value2.ToString());
                 }
                 state = 1;
             }
             catch { }
         }
     }
     return res;
 }
Exemplo n.º 3
0
 //获取图表中的数据个数
 private int GetGraphValueCount(Excel.Chart ch, Excel.Workbook xls)
 {
     int i, j, k, state, cnt = 0;
     Excel.SeriesCollection sc = (Excel.SeriesCollection)ch.SeriesCollection(nullobj);
     for (i = 1; i <= sc.Count; i++)
     {
         string seriesFormula = sc.Item(i).Formula;
         int firstComma = seriesFormula.IndexOf(',');
         int secondComma = seriesFormula.IndexOf(',', firstComma + 1);
         int thirdComma = seriesFormula.IndexOf(',', secondComma + 1);
         string yValues = seriesFormula.Substring(secondComma + 1, thirdComma - secondComma - 1);
         for (k = 1, state = 0; state == 0 && k <= xls.Worksheets.Count; k++)
         {
             try
             {
                 Excel.Worksheet ws = (Excel.Worksheet)xls.Worksheets[k];
                 Excel.Range yRange = ws.get_Range(yValues, nullobj);
                 cnt += yRange.Cells.Count;
                 state = 1;
             }
             catch { }
         }
     }
     return cnt;
 }