示例#1
0
 //获取考点信息
 public void getPoint(OfficeXML ox)
 {
     try { ox.getAllAnsPath(); }
     catch
     {
         MessageBox.Show("获取考点信息失败!");
         throw;
     }
 }
示例#2
0
 //打开文件,读入xml信息
 private void openFile(string stu, string ans, string xml)
 {
     word = new Word.Application();
     Object confirmConversions = Type.Missing;
     Object readOnly = true;
     Object addToRecentFiles = Type.Missing;
     Object passwordDocument = Type.Missing;
     Object passwordTemplate = Type.Missing;
     Object revert = Type.Missing;
     Object writePasswordDocument = Type.Missing;
     Object writePasswordTemplate = Type.Missing;
     Object format = Type.Missing;
     Object encoding = Type.Missing;
     Object visible = Type.Missing;
     Object openConflictDocument = Type.Missing;
     Object openAndRepair = Type.Missing;
     Object documentDirection = Type.Missing;
     Object noEncodingDialog = Type.Missing;
     Object file_path;
     file_path = stu;
     stuDoc = word.Documents.Open(ref file_path, ref confirmConversions,
         ref readOnly, ref addToRecentFiles, ref passwordDocument,
         ref passwordTemplate, ref revert, ref writePasswordDocument,
         ref writePasswordTemplate, ref format, ref encoding, ref visible,
         ref openConflictDocument, ref openAndRepair, ref documentDirection,
         ref noEncodingDialog);
     file_path = ans;
     ansDoc = word.Documents.Open(ref file_path, ref confirmConversions,
         ref readOnly, ref addToRecentFiles, ref passwordDocument,
         ref passwordTemplate, ref revert, ref writePasswordDocument,
         ref writePasswordTemplate, ref format, ref encoding, ref visible,
         ref openConflictDocument, ref openAndRepair, ref documentDirection,
         ref noEncodingDialog);
     oxml = new OfficeXML(xml);
     getPoint(oxml);
 }
示例#3
0
 public PptTestPointHelper(string xmlPath)
 {
     oxml = new OfficeXML(xmlPath);
 }
示例#4
0
 //从xml文件中读出考点
 private void getPoint(OfficeXML ox)
 {
     try { ox.getAllAnsPath(); }
     catch(Exception Ex)
     {
         MessageBox.Show("Get exam point error!");
         throw Ex;
     }
 }
示例#5
0
 //评分初始化
 public void init(string stu, string ans, string xml)
 {
     try
     {
         stuExcel = new Excel.Application();
         stuXls = stuExcel.Workbooks.Open(stu, nullobj, nullobj,
             nullobj, nullobj, nullobj, nullobj, nullobj, nullobj,
             nullobj, nullobj, nullobj, nullobj, nullobj, nullobj);  //载入学生xls
         ansExcel = new Excel.Application();
         ansXls = ansExcel.Workbooks.Open(ans, nullobj, nullobj,
             nullobj, nullobj, nullobj, nullobj, nullobj, nullobj,
             nullobj, nullobj, nullobj, nullobj, nullobj, nullobj);  //载入标答xls
         oxml = new OfficeXML(xml);                                  //读入考点文件
         getPoint(oxml);                                             //获取考点信息
         stuCate = getSheetCate(stuXls);              //检查学生工作表的类型
         ansCate = getSheetCate(ansXls);              //检查标答工作表的类型
     }
     catch (Exception Ex)
     {
         MessageBox.Show("Load file error!");
         throw Ex;
     }
 }
示例#6
0
 //打开文件
 public void openFile(string stu, string ans, string xml)
 {
     powerpoint = new PowerPoint.ApplicationClass();
     //powerpoint.Visible = True;
     powerpoint.Activate();
     //powerpoint.Visible = False;
     //stuPpt = powerpoint.Presentations.Add(True);
     //ansPpt = powerpoint.Presentations.Add(True);
     stuPpt = powerpoint.Presentations.Open(stu, False, True, True);
     ansPpt = powerpoint.Presentations.Open(ans, False, True, True);
     oxml = new OfficeXML(xml);
     getPoint(oxml);
 }
示例#7
0
 public TestWordHelper(string xmlPath)
 {
     oxml = new OfficeXML(xmlPath);
 }
示例#8
0
        public void loadExcel(string name,string xmlPath)
        {
            string file = name;
            excel = new Excel.Application();
            xls = excel.Workbooks.Open(file, nullobj, nullobj,
                nullobj, nullobj, nullobj, nullobj, nullobj,
                nullobj, nullobj, nullobj, nullobj, nullobj,
                nullobj,nullobj);
            excel.Visible = true;
            sheetCate = new int[xls.Sheets.Count + 1];
            worksheetIndex = new int[xls.Sheets.Count + 1];
            chartIndex = new int[xls.Sheets.Count + 1];
            sheetCate[0] = -1;
            for (int i = 1; i <= xls.Sheets.Count; i++)
            {
                string str = "";
                try
                {
                    str = ((Excel.Worksheet)xls.Sheets[i]).Name;
                    sheetCate[i] = 0;
                    worksheetIndex[comboWorksheet.Items.Count] = i;
                    comboWorksheet.Items.Add(str);
                    comboSheet.Items.Add(str);
                }   //工作簿
                catch
                {
                    str = ((Excel.Chart)xls.Sheets[i]).Name;
                    sheetCate[i] = 1;
                    chartIndex[comboChart.Items.Count] = i;
                    comboChart.Items.Add(str);
                }   //图表
            }
            if (comboChart.Items.Count == 0)
                comboChart.Items.Add("(没有单独存在的图表!)");
            if (comboSheet.Items.Count == 0)
            {
                comboSheet.Items.Add("(没有工作表!)");
                comboWorksheet.Items.Add("(没有工作表!)");
            }
            comboWorksheet.SelectedIndex = comboWorksheet.Items.Count > 0 ? 0 : -1;
            comboSheet.SelectedIndex = comboSheet.Items.Count > 0 ? 0 : -1;
            comboChart.SelectedIndex = comboChart.Items.Count > 0 ? 0 : -1;

            radioCell.Checked = true;
            radioSingleChart.Checked = true;

            oxml = new OfficeXML(xmlPath);
        }
示例#9
0
文件: Form1.cs 项目: kaiss78/hustoes
        private void Form1_Load(object sender, EventArgs e)
        {
            string file = @"D:\Test\Test.xls";
            excel = new Excel.Application();
            xls = excel.Workbooks.Open(file, nullobj, nullobj,
                nullobj, nullobj, nullobj, nullobj, nullobj,
                nullobj, nullobj, nullobj, nullobj, nullobj,
                nullobj,nullobj);
            excel.Visible = true;
            sheetCate = new int[xls.Sheets.Count + 1];
            worksheetIndex = new int[xls.Sheets.Count + 1];
            chartIndex = new int[xls.Sheets.Count + 1];
            sheetCate[0] = -1;
            for (int i = 1; i <= xls.Sheets.Count; i++)
            {
                string str = "";
                try
                {
                    str = ((Excel.Worksheet)xls.Sheets[i]).Name;
                    sheetCate[i] = 0;
                    worksheetIndex[comboWorksheet.Items.Count] = i;
                    comboWorksheet.Items.Add(str);
                    comboSheet.Items.Add(str);
                }   //工作簿
                catch
                {
                    str = ((Excel.Chart)xls.Sheets[i]).Name;
                    sheetCate[i] = 1;
                    chartIndex[comboChart.Items.Count] = i;
                    comboChart.Items.Add(str);
                }   //图表
            }
            if (comboChart.Items.Count == 0)
                comboChart.Items.Add("(没有单独存在的图表!)");
            if (comboSheet.Items.Count == 0)
            {
                comboSheet.Items.Add("(没有工作表!)");
                comboWorksheet.Items.Add("(没有工作表!)");
            }
            comboWorksheet.SelectedIndex = comboWorksheet.Items.Count > 0 ? 0 : -1;
            comboSheet.SelectedIndex = comboSheet.Items.Count > 0 ? 0 : -1;
            comboChart.SelectedIndex = comboChart.Items.Count > 0 ? 0 : -1;

            radioCell.Checked = true;
            radioSingleChart.Checked = true;

            ws = (Excel.Worksheet)(xls.Worksheets[1]);

            //Console.WriteLine(ws.Name);

            #region Set Value
            /*
            range = ws.get_Range(ws.Cells[11, 6], ws.Cells[15, 10]);

            object[,] value = new object[5, 5];
            for (int i = 0; i < 5; i++)
                for (int j = 0; j < 5; j++)
                    value[i, j] = 10;
            range.Value2 = value;
            ((Excel.Range)range.Cells[12, 8]).Value2 = 22;      //range左上角为原点,往下11行,往右5列,便是目的地

             * */
            #endregion
            #region 合并单元格
            //只有左上角的单元格有值,其他的为空
            /*
            range = getCell(22, 11);
            Console.WriteLine(range.Value2);
            range = getCell(22, 12);
            Console.WriteLine(range.Value2);
            range = getCell(22, 13);
            Console.WriteLine(range.Value2);
            */
            #endregion
            #region chart
            /*
                    ch = (Excel.Chart)xls.Charts[1];

                    Excel.ChartObjects charts = (Excel.ChartObjects)ws.ChartObjects(nullobj);
                    Excel.ChartObject chartObj = charts.Add(0, 0, 400, 300);
                    ch = chartObj.Chart;
                    Excel.Range range = ws.get_Range("B5", "D15");
                    ch.ChartWizard(range, Excel.XlChartType.xlXYScatter, nullobj, Excel.XlRowCol.xlColumns, 1, 1, true, "标题", "X轴标题", "Y轴标题", nullobj);
                    //ch.ChartWizard(range, Excel.XlChartType.xlXYScatterSmooth, nullobj, Excel.XlRowCol.xlColumns, 1, 1, true, "Title", "Category", "Value", nullobj);
                    chartObj.Left = Convert.ToDouble(range.Left);
                    chartObj.Top = Convert.ToDouble(range.Top) + Convert.ToDouble(range.Height);

                    //ch.ChartArea.Fill.TwoColorGradient(Microsoft.Office.Core.MsoGradientStyle.msoGradientHorizontal,1);

                     */
            //ch = (Excel.Chart)xls.Charts[1];
            //ch.Name = "fsffsfsfsfsfs";
            //ch.HasLegend = true;
            //ch.Legend.Position = Microsoft.Office.Interop.Excel.XlLegendPosition.xlLegendPositionBottom;

            #region 数据标志

            //Excel.SeriesCollection sc = (Excel.SeriesCollection)ch.SeriesCollection(nullobj);       //读图表中的数据!!!!!!!!!!!!!!!!!!!!!!
            //Test(sc);
            //Excel.Series ser = (Excel.SeriesCollection)ch.SeriesCollection(1);
            //ser.HasDataLabels = true;           //数据标志
            //ser.ApplyDataLabels(Microsoft.Office.Interop.Excel.XlDataLabelsType.xlDataLabelsShowPercent, false, true, false, true, true, true, nullobj, nullobj, "~");
            //ser.MarkerBackgroundColor = System.Drawing.ColorTranslator.ToOle(Color.Wheat);
            #endregion
            #endregion

            //range = getRegion(20, 10, 22, 12);
            //Excel.Range r1 = getCell(22, 11);
            //Excel.Range r2 = getCell(22, 11);
            //Console.WriteLine(r1.Top + " " + r1.Height + " " + r1.Left + " " + r1.Width + " " + r1.Value2);
            //Console.WriteLine(r2.Top + " " + r2.Height + " " + r2.Left + " " + r2.Width + " " + r2.Value2);
            //range = getRegion(11, 6, 15, 10);
            #region 边框设置
            /*
            range.Borders.Weight = 2;
            range.Borders.get_Item(Excel.XlBordersIndex.xlEdgeRight).LineStyle = Excel.XlLineStyle.xlContinuous;
            range.Borders.get_Item(Excel.XlBordersIndex.xlEdgeBottom).LineStyle = Excel.XlLineStyle.xlContinuous;
            range.Borders.get_Item(Excel.XlBordersIndex.xlEdgeTop).LineStyle = Excel.XlLineStyle.xlContinuous;
            range.Borders.get_Item(Excel.XlBordersIndex.xlEdgeLeft).LineStyle = Excel.XlLineStyle.xlContinuous;
            range.Borders.get_Item(Excel.XlBordersIndex.xlDiagonalDown).LineStyle = Excel.XlLineStyle.xlLineStyleNone;
            range.Borders.get_Item(Excel.XlBordersIndex.xlDiagonalUp).LineStyle = Excel.XlLineStyle.xlLineStyleNone;
            range.Borders.get_Item(Excel.XlBordersIndex.xlInsideHorizontal).LineStyle = Excel.XlLineStyle.xlLineStyleNone;
            range.Borders.get_Item(Excel.XlBordersIndex.xlInsideVertical).LineStyle = Excel.XlLineStyle.xlLineStyleNone;
            range.Borders.get_Item(Excel.XlBordersIndex.xlEdgeLeft).Color = System.Drawing.ColorTranslator.ToOle(Color.Blue);
            */
            #endregion
            #region 底纹设置
            //range.Interior.Pattern = Excel.XlPattern.xlPatternNone;                                     //底纹样式
            //range.Interior.PatternColor = System.Drawing.ColorTranslator.ToOle(Color.Transparent);    //底纹线条颜色
            //range.Interior.Color = System.Drawing.ColorTranslator.ToOle(Color.Transparent);           //背景颜色
            #endregion
            //range.Merge(false);               //合并单元格
            //range = getCell(16, 10);
            //range.Formula = "=SUM(J11:J15)";    //公式设置
            #region 字体设置
            /*
            range.Font.Strikethrough = true;    //删除线
            range.Font.Underline = true;        //下划线
            range.Font.Superscript = false;     //上标
            range.Font.Subscript = false;       //下标
            range.Font.Bold = true;             //粗体
            range.Font.Italic = true;           //斜体
            range.Font.Name = "华文琥珀";       //字体
            range.Font.Size = 20;               //字号
            range.Font.Color = System.Drawing.ColorTranslator.ToOle(Color.OrangeRed);   //颜色
             */
            #endregion
            #region 自动筛选
            //range = getRegion(5, 11, 31, 14);
            //range.AutoFilter(3, "=6", Microsoft.Office.Interop.Excel.XlAutoFilterOperator.xlOr, "<=3", true);
            //Console.WriteLine(ws.AutoFilter.Filters.Count);
            //Console.WriteLine(ws.AutoFilter.Filters[3].Criteria1.ToString());\
            //Console.WriteLine(ws.AutoFilter.Range.Rows.Count);
            #endregion
            #region 对齐方式
            //range.HorizontalAlignment = Excel.XlHAlign.xlHAlignLeft;
            //Console.WriteLine(range.HorizontalAlignment.ToString());
            #endregion
            #region 数字格式&行高列宽
            //range = getCell(27, 4);
            //MessageBox.Show(range.Formula.ToString() + "\r\n" +
            //                range.FormulaLocal.ToString() + "\r\n" +
            //                range.FormulaR1C1.ToString() + "\r\n" +
            //                range.FormulaR1C1Local.ToString());
            //range.Value2 = "4-Apr-1974";
            //range.NumberFormat = "m/d/yyyy";
            //range.RowHeight = 20;
            //range.ColumnWidth = 40;
            //MessageBox.Show(range.NumberFormat.ToString());
            #endregion
            #region 排序
            //range = getRegion(5, 11, 31, 13);
            //range.Activate();

            //range.Sort("URL", Microsoft.Office.Interop.Excel.XlSortOrder.xlAscending,
            //            nullobj, nullobj, Microsoft.Office.Interop.Excel.XlSortOrder.xlAscending,
            //            nullobj, Microsoft.Office.Interop.Excel.XlSortOrder.xlAscending,
            //            Microsoft.Office.Interop.Excel.XlYesNoGuess.xlYes, nullobj, false,
            //            Microsoft.Office.Interop.Excel.XlSortOrientation.xlSortColumns,
            //            Microsoft.Office.Interop.Excel.XlSortMethod.xlPinYin,
            //            Microsoft.Office.Interop.Excel.XlSortDataOption.xlSortNormal,
            //            Microsoft.Office.Interop.Excel.XlSortDataOption.xlSortNormal,
            //            Microsoft.Office.Interop.Excel.XlSortDataOption.xlSortNormal);
            //MessageBox.Show(((Excel.Range)range.Cells[2, 2]).Formula.ToString());
            #endregion
            #region 分类汇总
            //range = getRegion(1, 1, 12, 3);
            //int[] field = new int[]{3};
            //range.Subtotal(
            //    2,                                                                  //对第几列进行分类
            //    Microsoft.Office.Interop.Excel.XlConsolidationFunction.xlSum,       //汇总方式
            //    field,                                                              //对哪些列进行汇总
            //    true,                                                               //是否替换原来的分类汇总
            //    false,                                                              //是否分页显示
            //    Microsoft.Office.Interop.Excel.XlSummaryRow.xlSummaryBelow          //汇总信息显示在上面还是下面
            //    );
            //MessageBox.Show(range.OutlineLevel.ToString());

            //range = getRegion(1, 1, 12, 3);
            //range.Rows.OutlineLevel = 3;

            //range = getRegion(1, 1, 16, 3);
            //foreach (Excel.Range rg in range.Rows)
            //    MessageBox.Show(rg.ShowDetail.ToString());
            #endregion
            //range = getCell(3, 1);
            //range.Next.Interior.Color = System.Drawing.ColorTranslator.ToOle(Color.Bisque);
            //MessageBox.Show(range.Rows.Count.ToString() + " " + range.Columns.Count.ToString());
            //MessageBox.Show(range.MergeArea.Cells.Count);
            //MessageBox.Show(range.Row.ToString() + " " + range.Column.ToString() + " " + range.MergeArea.Cells.Count);
            //MessageBox.Show(range.MergeArea.Columns.Count.ToString());
            //MessageBox.Show(range.MergeArea.Cells.EntireColumn.Count.ToString());
            oxml = new OfficeXML("test.xml");
        }
示例#10
0
        private void testExcel_Load(object sender, EventArgs e)
        {
            MessageBox.Show("");
            string file = @"D:\Test\Test.xls";
            excel = new Excel.Application();
            xls = excel.Workbooks.Open(file, nullobj, nullobj,
                nullobj, nullobj, nullobj, nullobj, nullobj,
                nullobj, nullobj, nullobj, nullobj, nullobj,
                nullobj,nullobj);
            excel.Visible = true;
            sheetCate = new int[xls.Sheets.Count + 1];
            worksheetIndex = new int[xls.Sheets.Count + 1];
            chartIndex = new int[xls.Sheets.Count + 1];
            sheetCate[0] = -1;
            for (int i = 1; i <= xls.Sheets.Count; i++)
            {
                string str = "";
                try
                {
                    str = ((Excel.Worksheet)xls.Sheets[i]).Name;
                    sheetCate[i] = 0;
                    worksheetIndex[comboWorksheet.Items.Count] = i;
                    comboWorksheet.Items.Add(str);
                    comboSheet.Items.Add(str);
                }   //工作簿
                catch
                {
                    str = ((Excel.Chart)xls.Sheets[i]).Name;
                    sheetCate[i] = 1;
                    chartIndex[comboChart.Items.Count] = i;
                    comboChart.Items.Add(str);
                }   //图表
            }
            if (comboChart.Items.Count == 0)
                comboChart.Items.Add("(没有单独存在的图表!)");
            if (comboSheet.Items.Count == 0)
            {
                comboSheet.Items.Add("(没有工作表!)");
                comboWorksheet.Items.Add("(没有工作表!)");
            }
            comboWorksheet.SelectedIndex = comboWorksheet.Items.Count > 0 ? 0 : -1;
            comboSheet.SelectedIndex = comboSheet.Items.Count > 0 ? 0 : -1;
            comboChart.SelectedIndex = comboChart.Items.Count > 0 ? 0 : -1;

            radioCell.Checked = true;
            radioSingleChart.Checked = true;

            oxml = new OfficeXML("test.xml");
        }