Example #1
0
 private void 打开Excel文件ToolStripMenuItem_Click(object sender, EventArgs e)
 {
     OpenFileDialog.Filter = "Excel文件|*.xls";              //设置打开文件筛选器
     OpenFileDialog.Title  = "打开Excel文件";                  //设置打开对话框标题
     if (OpenFileDialog.ShowDialog() == DialogResult.OK)   //判断是否选择了文件
     {
         WBrowser_Excel.Navigate(OpenFileDialog.FileName); //在窗体中显示Excel文件内容
     }
 }
Example #2
0
 private void 打開Excel文件ToolStripMenuItem_Click(object sender, EventArgs e)
 {
     OpenFileDialog.Filter = "Excel文件|*.xls";              //設定打開文件篩選器
     OpenFileDialog.Title  = "打開Excel文件";                  //設定打開對話框標題
     if (OpenFileDialog.ShowDialog() == DialogResult.OK)   //判斷是否選擇了文件
     {
         WBrowser_Excel.Navigate(OpenFileDialog.FileName); //在視窗中顯示Excel文件內容
     }
 }
Example #3
0
 private void 打开Excel文件ToolStripMenuItem_Click(object sender, EventArgs e)
 {
     OpenFileDialog.Filter      = "Excel文件|*.xls";       //设置打开文件筛选器
     OpenFileDialog.Title       = "打开Excel文件";           //设置打开对话框标题
     OpenFileDialog.Multiselect = false;                 //设置打开对话框中不能多选
     if (OpenFileDialog.ShowDialog() == DialogResult.OK) //判断是否选择了文件
     {
         M_str_Name = OpenFileDialog.FileName;           //记录选择的Excel文件
         WBrowser_Excel.Navigate(M_str_Name);            //在窗体中显示Excel文件内容
     }
 }
Example #4
0
 private void 打開Excel文件ToolStripMenuItem_Click(object sender, EventArgs e)
 {
     OpenFileDialog.Filter      = "Excel文件|*.xls";       //設定打開文件篩選器
     OpenFileDialog.Title       = "打開Excel文件";           //設定打開對話框標題
     OpenFileDialog.Multiselect = false;                 //設定打開對話框中不能多選
     if (OpenFileDialog.ShowDialog() == DialogResult.OK) //判斷是否選擇了文件
     {
         M_str_Name = OpenFileDialog.FileName;           //記錄選擇的Excel文件
         WBrowser_Excel.Navigate(M_str_Name);            //在視窗中顯示Excel文件內容
     }
 }
Example #5
0
        private void 创建工作表ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            CloseProcess();                                                                                      //关闭Excel进程
            Microsoft.Office.Interop.Excel.Application excel = new Microsoft.Office.Interop.Excel.Application(); //实例化Excel对象
            object missing = Missing.Value;                                                                      //获取缺少的object类型值

            //打开指定的Excel文件
            Microsoft.Office.Interop.Excel.Workbook  workbook     = excel.Application.Workbooks.Open(M_str_Name, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing);
            Microsoft.Office.Interop.Excel.Worksheet newWorksheet = (Microsoft.Office.Interop.Excel.Worksheet)workbook.Worksheets.Add(missing, missing, 1, missing);
            MessageBox.Show("添加工作表成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            excel.Application.DisplayAlerts = false; //不显示提示对话框
            workbook.Save();                         //保存工作表
            workbook.Close(false, missing, missing); //关闭工作表
            WBrowser_Excel.Navigate(M_str_Name);     //在窗体中显示Excel文件内容
        }
Example #6
0
        private void 建立工作表ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            CloseProcess();                                                                                      //關閉Excel進程
            Microsoft.Office.Interop.Excel.Application excel = new Microsoft.Office.Interop.Excel.Application(); //實例化Excel對像
            object missing = Missing.Value;                                                                      //取得缺少的object類型值

            //打開指定的Excel文件
            Microsoft.Office.Interop.Excel.Workbook  workbook     = excel.Application.Workbooks.Open(M_str_Name, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing);
            Microsoft.Office.Interop.Excel.Worksheet newWorksheet = (Microsoft.Office.Interop.Excel.Worksheet)workbook.Worksheets.Add(missing, missing, 1, missing);
            MessageBox.Show("新增工作表成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            excel.Application.DisplayAlerts = false; //不顯示提示對話框
            workbook.Save();                         //儲存工作表
            workbook.Close(false, missing, missing); //關閉工作表
            WBrowser_Excel.Navigate(M_str_Name);     //在視窗中顯示Excel文件內容
        }
Example #7
0
        private void tscbox_Sheet_SelectedIndexChanged(object sender, EventArgs e)
        {
            CloseProcess("EXCEL");                                                                               //关闭所有Excel进程
            object missing = System.Reflection.Missing.Value;                                                    //定义object缺省值

            Microsoft.Office.Interop.Excel.Application excel = new Microsoft.Office.Interop.Excel.Application(); //实例化Excel对象
            //打开Excel文件
            Microsoft.Office.Interop.Excel.Workbook  workbook = excel.Workbooks.Open(tstxt_Excel.Text, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing);
            Microsoft.Office.Interop.Excel.Worksheet worksheet;                                             //声明工作表
            worksheet = ((Microsoft.Office.Interop.Excel.Worksheet)workbook.Worksheets[tscbox_Sheet.Text]); //获取选择的工作表
            worksheet.Activate();                                                                           //激活工作表
            excel.DisplayAlerts = false;                                                                    //设置保存Excel时不显示对话框
            workbook.Save();                                                                                //保存工作表
            CloseProcess("EXCEL");                                                                          //关闭所有Excel进程
            WBrowser_Excel.Navigate(tstxt_Excel.Text);                                                      //在窗体中重新显示Excel文件内容
        }
Example #8
0
        private void tsbtn_Query_Click(object sender, EventArgs e)
        {
            CloseProcess("EXCEL");                                                                               //关闭所有Excel进程
            string P_str_Excel     = tstxt_Excel.Text;                                                           //记录Excel文件路径
            string P_str_SheetName = tscbox_Sheet.Text;                                                          //记录选择的工作表名称
            object P_obj_Start     = tstxt_Start.Text;                                                           //记录开始单元格
            object P_obj_End       = tstxt_End.Text;                                                             //记录结束单元格
            object missing         = System.Reflection.Missing.Value;                                            //定义object缺省值

            Microsoft.Office.Interop.Excel.Application excel = new Microsoft.Office.Interop.Excel.Application(); //实例化Excel对象
            //打开Excel文件
            Microsoft.Office.Interop.Excel.Workbook  workbook = excel.Workbooks.Open(P_str_Excel, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing);
            Microsoft.Office.Interop.Excel.Worksheet worksheet;                                              //声明工作表
            worksheet = ((Microsoft.Office.Interop.Excel.Worksheet)workbook.Worksheets[P_str_SheetName]);    //获取选择的工作表
            Microsoft.Office.Interop.Excel.Range searchRange  = worksheet.get_Range(P_obj_Start, P_obj_End); //定义查找范围
            Microsoft.Office.Interop.Excel.Range currentRange = null;                                        //定义当前找到的范围
            Microsoft.Office.Interop.Excel.Range firstRange   = null;                                        //定义找到的第一个范围
            object P_obj_Text = tstxt_Text.Text;                                                             //记录要搜索的文本

            //搜索第一个匹配项,指定从其后开始搜索的单元格以外的所有参数
            currentRange = searchRange.Find(P_obj_Text, missing, Microsoft.Office.Interop.Excel.XlFindLookIn.xlValues, Microsoft.Office.Interop.Excel.XlLookAt.xlPart, Microsoft.Office.Interop.Excel.XlSearchOrder.xlByRows, Microsoft.Office.Interop.Excel.XlSearchDirection.xlNext, false, missing, missing);
            //一直搜索,直到没有匹配项
            while (currentRange != null)
            {
                if (firstRange == null)        //如果第一个范围不包含任何值
                {
                    firstRange = currentRange; //记录当前范围
                }
                //如果查找范围的地址与第一个查找范围的地址匹配
                else if (currentRange.get_Address(missing, missing, Microsoft.Office.Interop.Excel.XlReferenceStyle.xlA1, missing, missing) == firstRange.get_Address(missing, missing, Microsoft.Office.Interop.Excel.XlReferenceStyle.xlA1, missing, missing))
                {
                    break;//退出
                }
                //为单元格加边框
                currentRange.BorderAround(Microsoft.Office.Interop.Excel.XlLineStyle.xlContinuous, Microsoft.Office.Interop.Excel.XlBorderWeight.xlThin, Microsoft.Office.Interop.Excel.XlColorIndex.xlColorIndexAutomatic, Color.Black.ToArgb());
                currentRange.Font.Color = System.Drawing.ColorTranslator.ToOle(Color.Red); //设置搜索到的文本颜色
                currentRange.Font.Bold  = true;                                            //设置搜索到的文本为粗体
                currentRange            = searchRange.FindNext(currentRange);              //查找下一处
            }
            MessageBox.Show("搜索完毕!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            excel.DisplayAlerts = false;          //设置保存Excel时不显示对话框
            workbook.Save();                      //保存工作表
            CloseProcess("EXCEL");                //关闭所有Excel进程
            WBrowser_Excel.Navigate(P_str_Excel); //在窗体中重新显示Excel文件内容
        }
Example #9
0
        private void tsbtn_Query_Click(object sender, EventArgs e)
        {
            CloseProcess("EXCEL");                                                                               //关闭所有Excel进程
            string P_str_Excel     = tstxt_Excel.Text;                                                           //记录Excel文件路径
            string P_str_SheetName = tscbox_Sheet.Text;                                                          //记录选择的工作表名称
            object P_obj_Start     = tstxt_Start.Text;                                                           //记录开始单元格
            object P_obj_End       = tstxt_End.Text;                                                             //记录结束单元格
            object missing         = System.Reflection.Missing.Value;                                            //定义object缺省值

            Microsoft.Office.Interop.Excel.Application excel = new Microsoft.Office.Interop.Excel.Application(); //实例化Excel对象
            //打开Excel文件
            Microsoft.Office.Interop.Excel.Workbook  workbook = excel.Workbooks.Open(P_str_Excel, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing);
            Microsoft.Office.Interop.Excel.Worksheet worksheet;                                           //声明工作表
            worksheet = ((Microsoft.Office.Interop.Excel.Worksheet)workbook.Worksheets[P_str_SheetName]); //获取选择的工作表
            Microsoft.Office.Interop.Excel.Range searchRange = worksheet.get_Range(P_obj_Start, missing); //定义查找范围
            switch (tscbox_Type.Text)                                                                     //按照下拉列表中的文本进行条件判断
            {
            case "数字":                                                                                    //以数字序列填充
                searchRange.AutoFill(worksheet.get_Range(P_obj_Start, P_obj_End), Microsoft.Office.Interop.Excel.XlAutoFillType.xlFillSeries);
                break;

            case "工作日":    //以工作日填充
                searchRange.AutoFill(worksheet.get_Range(P_obj_Start, P_obj_End), Microsoft.Office.Interop.Excel.XlAutoFillType.xlFillWeekdays);
                break;

            case "月份":    //以月份填充
                searchRange.AutoFill(worksheet.get_Range(P_obj_Start, P_obj_End), Microsoft.Office.Interop.Excel.XlAutoFillType.xlFillMonths);
                break;

            case "年份":    //以年份填充
                searchRange.AutoFill(worksheet.get_Range(P_obj_Start, P_obj_End), Microsoft.Office.Interop.Excel.XlAutoFillType.xlFillYears);
                break;

            default:    //以默认方式填充
                searchRange.AutoFill(worksheet.get_Range(P_obj_Start, P_obj_End), Microsoft.Office.Interop.Excel.XlAutoFillType.xlFillDefault);
                break;
            }
            excel.DisplayAlerts = false;             //设置保存Excel时不显示对话框
            workbook.Save();                         //保存工作簿
            workbook.Close(false, missing, missing); //关闭工作簿
            CloseProcess("EXCEL");                   //关闭所有Excel进程
            WBrowser_Excel.Navigate(P_str_Excel);    //在窗体中重新显示Excel文件内容
        }
Example #10
0
        private void tsbtn_Open_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFile = new OpenFileDialog(); //实例化打开对话框对象

            openFile.Filter = "Excel文件|*.xls";              //设置打开文件筛选器
            openFile.Title  = "打开Excel文件";                  //设置打开对话框标题
            if (openFile.ShowDialog() == DialogResult.OK)   //判断是否选择了文件
            {
                tstxt_Excel.Text = openFile.FileName;
                WBrowser_Excel.Navigate(openFile.FileName);                       //在窗体中显示Excel文件内容
                List <string> P_list_SheetNames = GetSheetName(tstxt_Excel.Text); //获取选中Excel中的所有工作表
                tscbox_Sheet.Items.Clear();                                       //清空工具栏中的下拉列表
                foreach (string P_str_SheetName in P_list_SheetNames)             //遍历工作表集合
                {
                    tscbox_Sheet.Items.Add(P_str_SheetName);                      //将工作表名称显示在下拉列表中
                }
                if (tscbox_Sheet.Items.Count > 0)                                 //判断下拉列表中是否有项
                {
                    tscbox_Sheet.SelectedIndex = 0;                               //设置默认选择第一项
                }
            }
        }
Example #11
0
        private void tsbtn_Build_Click(object sender, EventArgs e)
        {
            CloseProcess("EXCEL");                                                                               //关闭所有Excel进程
            object missing = System.Reflection.Missing.Value;                                                    //定义object缺省值

            Microsoft.Office.Interop.Excel.Application excel = new Microsoft.Office.Interop.Excel.Application(); //实例化Excel对象
            //打开Excel文件
            Microsoft.Office.Interop.Excel.Workbook  workbook = excel.Workbooks.Open(tstxt_Excel.Text, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing);
            Microsoft.Office.Interop.Excel.Worksheet worksheet;                                             //声明工作表
            worksheet = ((Microsoft.Office.Interop.Excel.Worksheet)workbook.Worksheets[tscbox_Sheet.Text]); //获取选择的工作表
            Microsoft.Office.Interop.Excel.Range searchRange = worksheet.get_Range("A1", "E1");             //定义标题范围
            object[] P_obj_Items = { "编程词典", "VC编程词典", "JAVA编程词典", "ASP.NET编程词典", "C#编程词典" };
            searchRange.set_Value(missing, P_obj_Items);                                                    //绘制标题
            searchRange.Font.Bold           = true;                                                         //设置字体加粗
            searchRange.Font.Name           = "宋体";                                                         //设置字体样式
            searchRange.Font.Size           = 10;                                                           //设置字体大小
            searchRange.HorizontalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignCenter;       //设置标题对齐方式
            //获得要生成图表的数据
            for (int i = 0; i < 13; i++)
            {
                worksheet.Cells[2 + i, 1] = i;
                worksheet.Cells[2 + i, 2] = i + 1;
                worksheet.Cells[2 + i, 3] = i + 2;
                worksheet.Cells[2 + i, 4] = i + 3;
                worksheet.Cells[2 + i, 5] = i + 4;
            }
            //实例化Excel绘图对象
            Microsoft.Office.Interop.Excel.Chart chart      = (Microsoft.Office.Interop.Excel.Chart)workbook.Charts.Add(missing, missing, missing, missing);
            Microsoft.Office.Interop.Excel.Range chartRange = worksheet.get_Range("A1:A14", "B1:E14");//定义绘制图表范围
            //在指定范围绘制图表
            chart.ChartWizard(chartRange, Microsoft.Office.Interop.Excel.XlChartType.xl3DColumn, missing, Microsoft.Office.Interop.Excel.XlRowCol.xlColumns, 1, 1, true, "编程词典销量分析", "月份", "销量", missing);
            excel.DisplayAlerts = false;               //设置保存Excel时不显示对话框
            workbook.Save();                           //保存工作簿
            workbook.Close(false, missing, missing);   //关闭工作簿
            CloseProcess("EXCEL");                     //关闭所有Excel进程
            WBrowser_Excel.Navigate(tstxt_Excel.Text); //在窗体中重新显示Excel文件内容
        }
Example #12
0
        private void tsbtn_ASCSort_Click(object sender, EventArgs e)
        {
            CloseProcess("EXCEL");                                                                               //关闭所有Excel进程
            string P_str_Excel     = tstxt_Excel.Text;                                                           //记录Excel文件路径
            string P_str_SheetName = tscbox_Sheet.Text;                                                          //记录选择的工作表名称
            object P_obj_Start     = tstxt_Start.Text;                                                           //记录开始单元格
            object P_obj_End       = tstxt_End.Text;                                                             //记录结束单元格
            object missing         = System.Reflection.Missing.Value;                                            //定义object缺省值

            Microsoft.Office.Interop.Excel.Application excel = new Microsoft.Office.Interop.Excel.Application(); //实例化Excel对象
            //打开Excel文件
            Microsoft.Office.Interop.Excel.Workbook  workbook = excel.Workbooks.Open(P_str_Excel, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing);
            Microsoft.Office.Interop.Excel.Worksheet worksheet;                                             //声明工作表
            worksheet = ((Microsoft.Office.Interop.Excel.Worksheet)workbook.Worksheets[P_str_SheetName]);   //获取选择的工作表
            Microsoft.Office.Interop.Excel.Range searchRange = worksheet.get_Range(P_obj_Start, P_obj_End); //定义查找范围
            switch (searchRange.Columns.Count)
            {
            case 1:
                //按1列升序排序
                searchRange.Sort(
                    searchRange.Columns[1, missing], Microsoft.Office.Interop.Excel.XlSortOrder.xlAscending,
                    missing, missing, Microsoft.Office.Interop.Excel.XlSortOrder.xlAscending,
                    missing, Microsoft.Office.Interop.Excel.XlSortOrder.xlAscending,
                    Microsoft.Office.Interop.Excel.XlYesNoGuess.xlNo, missing, missing,
                    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);
                break;

            case 2:
                //按2列升序排序
                searchRange.Sort(
                    searchRange.Columns[1, missing], Microsoft.Office.Interop.Excel.XlSortOrder.xlAscending,
                    searchRange.Columns[2, missing], missing, Microsoft.Office.Interop.Excel.XlSortOrder.xlAscending,
                    missing, Microsoft.Office.Interop.Excel.XlSortOrder.xlAscending,
                    Microsoft.Office.Interop.Excel.XlYesNoGuess.xlNo, missing, missing,
                    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);
                break;

            case 3:
            default:
                //按3列升序排序
                searchRange.Sort(
                    searchRange.Columns[1, missing], Microsoft.Office.Interop.Excel.XlSortOrder.xlAscending,
                    searchRange.Columns[2, missing], missing, Microsoft.Office.Interop.Excel.XlSortOrder.xlAscending,
                    searchRange.Columns[3, missing], Microsoft.Office.Interop.Excel.XlSortOrder.xlAscending,
                    Microsoft.Office.Interop.Excel.XlYesNoGuess.xlNo, missing, missing,
                    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);
                break;
            }
            excel.DisplayAlerts = false;          //设置保存Excel时不显示对话框
            workbook.Save();                      //保存工作表
            CloseProcess("EXCEL");                //关闭所有Excel进程
            WBrowser_Excel.Navigate(P_str_Excel); //在窗体中重新显示Excel文件内容
        }
Example #13
0
        private void CalcData(int P_int_Row, string P_str_Column)
        {
            CloseProcess("EXCEL");                                                                                          //关闭所有Excel进程
            string P_str_workBook1 = Application.StartupPath + "\\Excel1.xls";                                              //记录第一个要计算的工作簿路径
            string P_str_workBook2 = Application.StartupPath + "\\Excel2.xls";                                              //记录第二个要计算的工作簿路径
            string P_str_workBook3 = Application.StartupPath + "\\Excel3.xls";                                              //记录第三个要计算的工作簿路径
            string P_str_workBook4 = Application.StartupPath + "\\Sum.xls";                                                 //记录存储计算结果的工作簿路径
            object missing         = System.Reflection.Missing.Value;                                                       //定义object缺省值

            Microsoft.Office.Interop.Excel.ApplicationClass excel1 = new Microsoft.Office.Interop.Excel.ApplicationClass(); //实例化Excel对象
            excel1.Visible = false;                                                                                         //设置Excel文件隐藏
            //打开第一个计算的工作簿
            Microsoft.Office.Interop.Excel.Workbook workbook1 = excel1.Workbooks.Open(P_str_workBook1, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing);
            //记录要计算的第一个工作表
            Microsoft.Office.Interop.Excel._Worksheet       worksheet1 = (Microsoft.Office.Interop.Excel._Worksheet)workbook1.Worksheets.get_Item(tscbox_Sheet.Text);
            Microsoft.Office.Interop.Excel.ApplicationClass excel2     = new Microsoft.Office.Interop.Excel.ApplicationClass(); //实例化Excel对象
            excel2.Visible = false;                                                                                             //设置Excel文件隐藏
            //打开第二个计算的工作簿
            Microsoft.Office.Interop.Excel.Workbook workbook2 = excel2.Workbooks.Open(P_str_workBook2, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing);
            //记录要计算的第二个工作表
            Microsoft.Office.Interop.Excel._Worksheet       worksheet2 = (Microsoft.Office.Interop.Excel._Worksheet)workbook2.Worksheets.get_Item(tscbox_Sheet.Text);
            Microsoft.Office.Interop.Excel.ApplicationClass excel3     = new Microsoft.Office.Interop.Excel.ApplicationClass(); //实例化Excel对象
            excel3.Visible = false;                                                                                             //设置Excel文件隐藏
            //打开第三个计算的工作簿
            Microsoft.Office.Interop.Excel.Workbook workbook3 = excel3.Workbooks.Open(P_str_workBook3, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing);
            //记录要计算的第三个工作表
            Microsoft.Office.Interop.Excel._Worksheet       worksheet3 = (Microsoft.Office.Interop.Excel._Worksheet)workbook3.Worksheets.get_Item(tscbox_Sheet.Text);
            Microsoft.Office.Interop.Excel.ApplicationClass excel4     = new Microsoft.Office.Interop.Excel.ApplicationClass(); //实例化Excel对象
            excel4.Visible = false;                                                                                             //设置Excel文件隐藏
            //打开存储计算结果的工作簿
            Microsoft.Office.Interop.Excel.Workbook workbook4 = excel4.Workbooks.Open(P_str_workBook4, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing);
            //记录要存储结算结果的工作表
            Microsoft.Office.Interop.Excel._Worksheet worksheet4 = (Microsoft.Office.Interop.Excel._Worksheet)workbook4.Worksheets.get_Item(tscbox_Sheet.Text);
            excel4.DisplayAlerts = false; //设置保存Excel时不显示对话框
            worksheet4.Activate();        //激活工作表
            Decimal P_dml_NumOne   = 0;   //获取第一个工作表的值
            Decimal P_dml_NumTwo   = 0;   //获取第二个工作表的值
            Decimal P_dml_NumThree = 0;   //获取第三个工作表的值

            //判断指定单元格内容是否为空
            if (((Microsoft.Office.Interop.Excel.Range)worksheet1.Cells[P_int_Row, P_str_Column]).Text.ToString() == "" || ((Microsoft.Office.Interop.Excel.Range)worksheet1.Cells[P_int_Row, P_str_Column]).Text == null)
            {
                P_dml_NumOne = 0;//将第一个值设置为0
            }
            else
            {
                P_dml_NumOne = Convert.ToDecimal(((Microsoft.Office.Interop.Excel.Range)worksheet1.Cells[P_int_Row, P_str_Column]).Text);//记录第一个值
            }
            //判断指定单元格内容是否为空
            if (((Microsoft.Office.Interop.Excel.Range)worksheet2.Cells[P_int_Row, P_str_Column]).Text.ToString() == "" || ((Microsoft.Office.Interop.Excel.Range)worksheet2.Cells[P_int_Row, P_str_Column]).Text == null)
            {
                P_dml_NumTwo = 0;//将第二个值设置为0
            }
            else
            {
                P_dml_NumTwo = Convert.ToDecimal(((Microsoft.Office.Interop.Excel.Range)worksheet2.Cells[P_int_Row, P_str_Column]).Text);//记录第二个值
            }
            //判断指定单元格内容是否为空
            if (((Microsoft.Office.Interop.Excel.Range)worksheet3.Cells[P_int_Row, P_str_Column]).Text.ToString() == "" || ((Microsoft.Office.Interop.Excel.Range)worksheet3.Cells[P_int_Row, P_str_Column]).Text == null)
            {
                P_dml_NumThree = 0;//将第三个值设置为0
            }
            else
            {
                P_dml_NumThree = Convert.ToDecimal(((Microsoft.Office.Interop.Excel.Range)worksheet3.Cells[P_int_Row, P_str_Column]).Text); //记录第三个值
            }
            Decimal P_dml_Sum = P_dml_NumOne + P_dml_NumTwo + P_dml_NumThree;                                                               //计算总和

            try
            {
                worksheet4.Cells[P_int_Row, P_str_Column] = P_dml_Sum.ToString(); //向工作簿的指定单元格中写入计算后的数据
                workbook4.Save();                                                 //保存Excel文件
            }
            catch
            {
                MessageBox.Show("写入第" + P_int_Row.ToString() + "行,第" + P_str_Column + "列时出错!");
            }
            finally
            {
                workbook4.Save();//保存Excel文件
                //退出打开的4个Excel文件
                excel1.Quit();
                excel2.Quit();
                excel3.Quit();
                excel4.Quit();
            }
            WBrowser_Excel.Navigate(P_str_workBook4);//在窗体中显示多表计算后的Excel文件
        }