您的位置:首页 > 编程语言 > C#

c#.net 下的excel操作(二)

2013-11-13 16:42 274 查看
接续上文:

。。。主要实现数据对比并改变excel中指定单元格的内容。比如有:测试1.xls和测试2.xlsx  两个excel文件需要对比第一列数据。如果第一个文档中有该记录,第二个文档中没有。则把第一个文件中的记录变为红色字体。。。

开始正题:

上文提到了对比excel文档的实现。主要介绍了以简要思路和以数据库对象方式获得文件的数据

下面接着讨论一office excel对象方式操作excel文件的类。

    /// <SUMMARY>

    /// ExcelEdit 的摘要说明

    /// </SUMMARY>

    public class ExcelEdit

    {

        public string mFilename;

        public Microsoft.Office.Interop.Excel.Application app;

        public Microsoft.Office.Interop.Excel.Workbooks wbs;

        public Microsoft.Office.Interop.Excel.Workbook wb;

        public Microsoft.Office.Interop.Excel.Worksheets wss;

        public Microsoft.Office.Interop.Excel.Worksheet ws;

        public ExcelEdit()

        {

            //

            // TODO: 在此处添加构造函数逻辑

            //

        }

        public void Create()//创建一个Excel对象

        {

            app = new Microsoft.Office.Interop.Excel.Application();

            wbs = app.Workbooks;

            wb = wbs.Add(true);

        }

        /// <summary>

        ///    打开一个Excel文件

        /// </summary>

        /// <param name="FileName"></param>

        public void Open(string FileName)

        {

            app = new Microsoft.Office.Interop.Excel.Application();

            wbs = app.Workbooks;

            wb = wbs.Add(FileName);

            //wb = wbs.Open(FileName, 0, true, 5,"", "", true, Excel.XlPlatform.xlWindows, "t", false, false, 0, true,Type.Missing,Type.Missing);

            //wb = wbs.Open(FileName,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Excel.XlPlatform.xlWindows,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing);

            mFilename = FileName;

        }

        #region 添加的方法:获得所有工作表的名称

        /// <summary>

        /// 获得当前所选择的Excel Sheet的所有名字

        /// </summary>

        /// <param name="filePath"></param>

        /// <returns></returns>

        public static string[] GetExcelSheetNames(string filePath)

        {

            Microsoft.Office.Interop.Excel.ApplicationClass excelAppT = new ApplicationClass();

            Microsoft.Office.Interop.Excel.Workbooks wbsT = excelAppT.Workbooks;

            Microsoft.Office.Interop.Excel.Workbook wbT = wbsT.Open(filePath, Type.Missing, Type.Missing, Type.Missing, Type.Missing,

            Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,

            Type.Missing, Type.Missing, Type.Missing, Type.Missing);

            int count = wbT.Worksheets.Count;

            string[] names = new string[count];

            for (int i = 1; i <= count; i++)

            {

                names[i - 1] = ((Microsoft.Office.Interop.Excel.Worksheet)wbT.Worksheets[i]).Name;

            }

            wbT.Close(Type.Missing, Type.Missing, Type.Missing);

            wbsT.Close();

            excelAppT.Quit();

            return names;

        }

        #endregion

        /// <summary>

        /// 获取一个工作表

        /// </summary>

        /// <param name="SheetName"></param>

        /// <returns></returns>

        public Microsoft.Office.Interop.Excel.Worksheet GetSheet(string SheetName)

        //

        {

            Microsoft.Office.Interop.Excel.Worksheet s = (Microsoft.Office.Interop.Excel.Worksheet)wb.Worksheets[SheetName];

            return s;

        }

        /// <summary>

        /// 添加一个工作表

        /// </summary>

        /// <param name="SheetName"></param>

        /// <returns></returns>

        public Microsoft.Office.Interop.Excel.Worksheet AddSheet(string SheetName)

        //

        {

            Microsoft.Office.Interop.Excel.Worksheet s = (Microsoft.Office.Interop.Excel.Worksheet)wb.Worksheets.Add(Type.Missing, Type.Missing, Type.Missing, Type.Missing);

            s.Name = SheetName;

            return s;

        }

        /// <summary>

        /// 删除一个工作表

        /// </summary>

        /// <param name="SheetName"></param>

        public void DelSheet(string SheetName)//

        {

            ((Microsoft.Office.Interop.Excel.Worksheet)wb.Worksheets[SheetName]).Delete();

        }

        /// <summary>

        /// 重命名一个工作表一

        /// </summary>

        /// <param name="OldSheetName"></param>

        /// <param name="NewSheetName"></param>

        /// <returns></returns>

        public Microsoft.Office.Interop.Excel.Worksheet ReNameSheet(string OldSheetName, string NewSheetName)//

        {

            Microsoft.Office.Interop.Excel.Worksheet s = (Microsoft.Office.Interop.Excel.Worksheet)wb.Worksheets[OldSheetName];

            s.Name = NewSheetName;

            return s;

        }

        public Microsoft.Office.Interop.Excel.Worksheet ReNameSheet(Microsoft.Office.Interop.Excel.Worksheet Sheet, string NewSheetName)//重命名一个工作表二

        {

            Sheet.Name = NewSheetName;

            return Sheet;

        }

        public void SetCellValue(Microsoft.Office.Interop.Excel.Worksheet ws, int x, int y, object value)

        //ws:要设值的工作表        X行Y列     value   值

        {

            ws.Cells[x, y] = value;

        }

        public void SetCellValue(string ws, int x, int y, object value)

        //ws:要设值的工作表的名称 X行Y列 value 值

        {

            GetSheet(ws).Cells[x, y] = value;

        }

        /// <summary>

        /// 设置一个单元格的属性   字体,   大小,颜色   ,对齐方式

        /// </summary>

        /// <param name="ws"></param>

        /// <param name="Startx"></param>

        /// <param name="Starty"></param>

        /// <param name="Endx"></param>

        /// <param name="Endy"></param>

        /// <param name="size"></param>

        /// <param name="name"></param>

        /// <param name="color"></param>

        /// <param name="HorizontalAlignment"></param>

        public void SetCellProperty(Microsoft.Office.Interop.Excel.Worksheet ws, int Startx, int Starty, int Endx, int Endy, int size, string name, Microsoft.Office.Interop.Excel.Constants color, Microsoft.Office.Interop.Excel.Constants HorizontalAlignment)

        {

            //name = "宋体";

            //size = 12;

            //color = Microsoft.Office.Interop.Excel.Constants.xlAutomatic;

            //HorizontalAlignment = Microsoft.Office.Interop.Excel.Constants.xlRight;

            ws.get_Range(ws.Cells[Startx, Starty], ws.Cells[Endx, Endy]).Font.Name = name;

            ws.get_Range(ws.Cells[Startx, Starty], ws.Cells[Endx, Endy]).Font.Size = size;

            ws.get_Range(ws.Cells[Startx, Starty], ws.Cells[Endx, Endy]).Font.Color = color;

            ws.get_Range(ws.Cells[Startx, Starty], ws.Cells[Endx, Endy]).HorizontalAlignment = HorizontalAlignment;

        }

        public void SetCellProperty(string wsn, int Startx, int Starty, int Endx, int Endy, int size, string name, Microsoft.Office.Interop.Excel.Constants color, Microsoft.Office.Interop.Excel.Constants HorizontalAlignment)

        {

            //name = "宋体";

            //size = 12;

            //color = Excel.Constants.xlAutomatic;

            //HorizontalAlignment = Excel.Constants.xlRight;

            Microsoft.Office.Interop.Excel.Worksheet ws = GetSheet(wsn);

            ws.get_Range(ws.Cells[Startx, Starty], ws.Cells[Endx, Endy]).Font.Name = name;

            ws.get_Range(ws.Cells[Startx, Starty], ws.Cells[Endx, Endy]).Font.Size = size;

            ws.get_Range(ws.Cells[Startx, Starty], ws.Cells[Endx, Endy]).Font.Color = color;

            ws.get_Range(ws.Cells[Startx, Starty], ws.Cells[Endx, Endy]).HorizontalAlignment = HorizontalAlignment;

        }

        /// <summary>

        /// 设置一个单元格颜色

        /// </summary>

        /// <param name="wsn">中文名</param>

        /// <param name="StartX">行号</param>

        /// <param name="StartY">列号</param>

        /// <param name="color"> Microsoft.Office.Interop.Excel.Constants颜色</param>

        public void SetCellProperty(string wsn, int StartX, int StartY, Microsoft.Office.Interop.Excel.Constants color)

        {

            Microsoft.Office.Interop.Excel.Worksheet ws = GetSheet(wsn);

            //System.Drawing.ColorTranslator.ToOle(Color.Blue)

            // ws.get_Range(ws.Cells[StartX, StartY], ws.Cells[StartX, StartY]).Font.Color = System.Drawing.ColorTranslator.ToOle(Color.Blue);

            ws.get_Range(ws.Cells[StartX, StartY], ws.Cells[StartX, StartY]).Font.Color = color;

        }

        /// <summary>

        /// 设置一个单元格颜色

        /// </summary>

        /// <param name="wsn">中文名</param>

        /// <param name="StartX">行号</param>

        /// <param name="StartY">列号</param>

        /// <param name="color"> 颜色: System.Drawing.Color</param>

        public void SetCellProperty(string wsn, int StartX, int StartY, Color color)

        {

            Microsoft.Office.Interop.Excel.Worksheet ws = GetSheet(wsn);

            //System.Drawing.ColorTranslator.ToOle(Color.Blue)

            ws.get_Range(ws.Cells[StartX, StartY], ws.Cells[StartX, StartY]).Font.Color = System.Drawing.ColorTranslator.ToOle(color);

            // ws.get_Range(ws.Cells[StartX, StartY], ws.Cells[StartX, StartY]).Font.Color = color;

        }

        public void UniteCells(Microsoft.Office.Interop.Excel.Worksheet ws, int x1, int y1, int x2, int y2)

        //合并单元格

        {

            ws.get_Range(ws.Cells[x1, y1], ws.Cells[x2, y2]).Merge(Type.Missing);

        }

        public void UniteCells(string ws, int x1, int y1, int x2, int y2)

        //合并单元格

        {

            GetSheet(ws).get_Range(GetSheet(ws).Cells[x1, y1], GetSheet(ws).Cells[x2, y2]).Merge(Type.Missing);

        }

        public void InsertTable(System.Data.DataTable dt, string ws, int startX, int startY)

        //将内存中数据表格插入到Excel指定工作表的指定位置 为在使用模板时控制格式时使用一

        {

            for (int i = 0; i <= dt.Rows.Count - 1; i++)

            {

                for (int j = 0; j <= dt.Columns.Count - 1; j++)

                {

                    GetSheet(ws).Cells[startX + i, j + startY] = dt.Rows[i][j].ToString();

                }

            }

        }

        public void InsertTable(System.Data.DataTable dt, Microsoft.Office.Interop.Excel.Worksheet ws, int startX, int startY)

        //将内存中数据表格插入到Excel指定工作表的指定位置二

        {

            for (int i = 0; i <= dt.Rows.Count - 1; i++)

            {

                for (int j = 0; j <= dt.Columns.Count - 1; j++)

                {

                    ws.Cells[startX + i, j + startY] = dt.Rows[i][j];

                }

            }

        }

        public void AddTable(System.Data.DataTable dt, string ws, int startX, int startY)

        //将内存中数据表格添加到Excel指定工作表的指定位置一

        {

            for (int i = 0; i <= dt.Rows.Count - 1; i++)

            {

                for (int j = 0; j <= dt.Columns.Count - 1; j++)

                {

                    GetSheet(ws).Cells[i + startX, j + startY] = dt.Rows[i][j];

                }

            }

        }

        public void AddTable(System.Data.DataTable dt, Microsoft.Office.Interop.Excel.Worksheet ws, int startX, int startY)

        //将内存中数据表格添加到Excel指定工作表的指定位置二

        {

            for (int i = 0; i <= dt.Rows.Count - 1; i++)

            {

                for (int j = 0; j <= dt.Columns.Count - 1; j++)

                {

                    ws.Cells[i + startX, j + startY] = dt.Rows[i][j];

                }

            }

        }

        public void InsertPictures(string Filename, string ws)

        //插入图片操作一

        {

            GetSheet(ws).Shapes.AddPicture(Filename, MsoTriState.msoFalse, MsoTriState.msoTrue, 10, 10, 150, 150);

            //后面的数字表示位置

        }

        //public void InsertPictures(string Filename, string ws, int Height, int Width)

        //插入图片操作二

        //{

        //    GetSheet(ws).Shapes.AddPicture(Filename, MsoTriState.msoFalse, MsoTriState.msoTrue, 10, 10, 150, 150);

        //    GetSheet(ws).Shapes.get_Range(Type.Missing).Height = Height;

        //    GetSheet(ws).Shapes.get_Range(Type.Missing).Width = Width;

        //}

        //public void InsertPictures(string Filename, string ws, int left, int top, int Height, int Width)

        //插入图片操作三

        //{

        //    GetSheet(ws).Shapes.AddPicture(Filename, MsoTriState.msoFalse, MsoTriState.msoTrue, 10, 10, 150, 150);

        //    GetSheet(ws).Shapes.get_Range(Type.Missing).IncrementLeft(left);

        //    GetSheet(ws).Shapes.get_Range(Type.Missing).IncrementTop(top);

        //    GetSheet(ws).Shapes.get_Range(Type.Missing).Height = Height;

        //    GetSheet(ws).Shapes.get_Range(Type.Missing).Width = Width;

        //}

        public void InsertActiveChart(Microsoft.Office.Interop.Excel.XlChartType ChartType, string ws, int DataSourcesX1, int DataSourcesY1, int DataSourcesX2, int DataSourcesY2, Microsoft.Office.Interop.Excel.XlRowCol ChartDataType)

        //插入图表操作

        {

            ChartDataType = Microsoft.Office.Interop.Excel.XlRowCol.xlColumns;

            wb.Charts.Add(Type.Missing, Type.Missing, Type.Missing, Type.Missing);

            {

                wb.ActiveChart.ChartType = ChartType;

                wb.ActiveChart.SetSourceData(GetSheet(ws).get_Range(GetSheet(ws).Cells[DataSourcesX1, DataSourcesY1], GetSheet(ws).Cells[DataSourcesX2, DataSourcesY2]), ChartDataType);

                wb.ActiveChart.Location(Microsoft.Office.Interop.Excel.XlChartLocation.xlLocationAsObject, ws);

            }

        }

        public bool Save()

        //保存文档

        {

            if (mFilename == "")

            {

                return false;

            }

            else

            {

                try

                {

                    wb.Save();

                    return true;

                }

                catch (Exception ex)

                {

                    return false;

                }

            }

        }

        public bool SaveAs(object FileName)

        //文档另存为

        {

            try

            {

                wb.SaveAs(FileName, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlExclusive, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);

                return true;

            }

            catch (Exception ex)

            {

                return false;

            }

        }

        public void Close()

        //关闭一个Excel对象,销毁对象

        {

            //wb.Save();

            wb.Close(Type.Missing, Type.Missing, Type.Missing);

            wbs.Close();

            app.Quit();

            wb = null;

            wbs = null;

            app = null;

            GC.Collect();

        }

    }

此类以excel对象方式进行各种操作。不过有一个bug。需要实例化此类后,对ws变量进行赋值。

我写的窗体后台代码如下:

    public partial class frmCustNoComp : Form

    {

        #region 成员变量

        private Dat _dtblFirst = new Dat();

        private Dat _dtblSecond = new Dat();

        private string _FirstFilePath = string.Empty;

        private string _SecondFilePath = string.Empty;

        #endregion

        public frmCustNoComp()

        {

            InitializeComponent();

        }

        /// <summary>

        /// 打开文件

        /// </summary>

        /// <param name="sender"></param>

        /// <param name="e"></param>

        private void btnOpenFile_Click(object sender, EventArgs e)

        {

            try

            {

                dgrvResult.DataSource = null;

                string fName;

                opfdShow.FileName = @"*.xls";

                opfdShow.Filter = "excel2003(*.xls)|*.xls|excel2007|*.xlsx";

                opfdShow.FilterIndex = 1;

                opfdShow.RestoreDirectory = true;

                if (opfdShow.ShowDialog() == DialogResult.OK)

                {

                    tabResult.SelectedIndex = 0;

                 

                    fName = opfdShow.FileName;

                    DataSet dsAll = MyExcelUtls.GetExcelToDataSet(fName, false);

                    _dtblFirst = dsAll.Tables[0];

                    dgrvResult.DataSource = _dtblFirst;

                    _FirstFilePath = fName;

                }

            }

            catch (Exception ex)

            {

                MessageBox.Show(@"打开第一个文件时出错!\n" + ex.ToString());

            }

        }

        /// <summary>

        /// 目标文件

        /// </summary>

        /// <param name="sender"></param>

        /// <param name="e"></param>

        private void btnFileTarget_Click(object sender, EventArgs e)

        {

            try

            {

                // dgrvResult.DataSource = null;

                OpenFileDialog opfdTarget = new OpenFileDialog();

                opfdTarget.FileName = @"*.xls";

                opfdTarget.Filter = "excel2003(*.xls)|*.xls|excel 2007|*.xlsx";

                opfdTarget.RestoreDirectory = true;

                opfdTarget.FilterIndex = 1;

                if (opfdTarget.ShowDialog() == DialogResult.OK)

                {

                    tpSecond.Show();

                    tabResult.SelectedIndex = 1;

                    string strFilePath = opfdTarget.FileName;

                    string[] strArray = ExcelEdit.GetExcelSheetNames(strFilePath);

                    DataSet dsAll = MyExcelUtls.GetExcelToDataSet(strFilePath, false);

                    _dtblSecond = dsAll.Tables[0];

                    dgrvSecond.DataSource = _dtblSecond;

                    _SecondFilePath = strFilePath;

                }

            }

            catch (Exception ex)

            {

                MessageBox.Show(@"打开第二个文件出错!\n" + ex.ToString());

            }

        }

        /// <summary>

        /// 对比按钮单击事件

        /// </summary>

        /// <param name="sender"></param>

        /// <param name="e"></param>

        private void btnCompare_Click(object sender, EventArgs e)

        {

            panel1.Show();

            bool blnFirstSucc = false;

            bool blnSecSucc = false;

            for (int bar = 1; bar < 10; bar++)

            {

                pgbShow.Value = bar;

            }

            try

            {

                if (_dtblFirst == null || _dtblFirst.Rows.Count < 1)

                {

                    MessageBox.Show("第一个文件为空,请选择");

                    btnOpenFile.Focus();

                    return;

                }

                if (_dtblSecond == null || _dtblSecond.Rows.Count < 1)

                {

                    MessageBox.Show("第二个文件为空,请选择");

                    btnFileTarget.Focus();

                    return;

                }

   

                ExcelEdit FirstExcel = new ExcelEdit();

                FirstExcel.Open(_FirstFilePath);

                FirstExcel.ws = FirstExcel.GetSheet(ExcelEdit.GetExcelSheetNames(_FirstFilePath)[0]);

                string FirstWSName = ExcelEdit.GetExcelSheetNames(_FirstFilePath)[0];

                ExcelEdit SecondExcel = new ExcelEdit();

                SecondExcel.Open(_SecondFilePath);

                string SecondWSName = ExcelEdit.GetExcelSheetNames(_SecondFilePath)[0];

                SecondExcel.ws = SecondExcel.GetSheet(ExcelEdit.GetExcelSheetNames(_SecondFilePath)[0]);

                #region 第一张表比对。

             

                List<InfoModel> lstFirHaveSecNo = new List<InfoModel>();

           

                for (int i = 0; i < _dtblFirst.Rows.Count; i++)

                {

                    bool blnHave = false;

                  

                    string strFirst = string.Empty;

                    if (_dtblFirst.Rows[i][0] != null && _dtblFirst.Rows[i][0].ToString().Length > 0)

                    {

                        strFirst = _dtblFirst.Rows[i][0].ToString().Trim();

                    }

                    for (int j = 0; j < _dtblSecond.Rows.Count; j++)

                    {

                        string strSecond = string.Empty;

                        if (_dtblSecond.Rows[j][0] != null && _dtblSecond.Rows[j][0].ToString().Length > 0)

                        {

                            strSecond = _dtblSecond.Rows[j][0].ToString().Trim();

                        }

                      

                        if (strFirst == strSecond)

                        {

                            blnHave = true;

                            break;

                        }

                    }

                    // 判断第一个文件遍历中的单元格内容是否存在于第二个文件

                    int Column = 1;

                    if (!blnHave)

                    {

                        InfoModel model = new InfoModel();

                        model.RowIndex = (i + 2).ToString();

                        model.RowValue = _dtblFirst.Rows[i][0].ToString();

                        lstFirHaveSecNo.Add(model);

                        FirstExcel.SetCellProperty(FirstWSName, i + 2, Column, Color.Red);

                    }

                    else if (blnHave)

                    {

                     

                        FirstExcel.SetCellProperty(FirstWSName, i + 2, Column, Color.Black);

                    }

                    blnHave = false;

                }

                try

                {

                    string strFi = Path.GetFileName(_FirstFilePath);

                    string FirstFileDirec = Path.GetDirectoryName(_FirstFilePath);

                    string FirstFileName = Path.GetFileName(_FirstFilePath);

                    string FirstFileExt = Path.GetExtension(_FirstFilePath);

                    string FirstFileSaved = FirstFileDirec + @"\" + FirstFileName.Substring(0, FirstFileName.Length - FirstFileExt.Length) + "1.xlsx";

                    // blnFirstSucc = FirstExcel.SaveAs(FirstFileSaved);

                    blnFirstSucc = FirstExcel.SaveAs(_FirstFilePath);

                    FirstExcel.Close();

                }

                catch (Exception exx)

                {

                    //MessageBox.Show(@"比较1-2出错:\n" + exx.ToString());

                    FirstExcel.Close();

                }

                finally

                {

                }

                #endregion

                for (int halfBar = 30; halfBar < 60; halfBar++)

                {

                    pgbShow.Value = halfBar;

                }

                #region 第二张表比对

             

                List<InfoModel> lstSecHaveFirNo = new List<InfoModel>();

               

                for (int i = 0; i < _dtblSecond.Rows.Count; i++)

                {

                    bool blnHave = false;

                    string strSecond = string.Empty;

                    if (_dtblSecond.Rows[i][0] != null && _dtblSecond.Rows[i][0].ToString().Length > 0)

                    {

                        strSecond = _dtblSecond.Rows[i][0].ToString().Trim();

                    }

                    for (int j = 0; j < _dtblFirst.Rows.Count; j++)

                    {

                

                        string strFirst = string.Empty;

                        if (_dtblFirst.Rows[j][0] != null && _dtblFirst.Rows[j][0].ToString().Length > 0)

                        {

                            strFirst = _dtblFirst.Rows[j][0].ToString().Trim();

                        }

                        // 比较

                        if (strFirst == strSecond)

                        {

                            blnHave = true;

                            break;

                        }

                    }

                    int Column = 1;

                    if (!blnHave)

                    {

                        InfoModel model = new InfoModel();

                        model.RowIndex = (i + 2).ToString();

                        model.RowValue = _dtblSecond.Rows[i][0].ToString();

                        lstSecHaveFirNo.Add(model);

                        SecondExcel.SetCellProperty(SecondWSName, i + 2, Column, Color.Red);

                    }

                    else if (blnHave)

                    {

                        SecondExcel.SetCellProperty(SecondWSName, i + 2, Column, Color.Black);

                    }

                    blnHave = false;

                }

                try

                {

                    string strSe = Path.GetFileName(_SecondFilePath);

                    string SecFileDirec = Path.GetDirectoryName(_SecondFilePath);

                    string SecFileName = Path.GetFileName(_SecondFilePath);

                    string SecFileExt = Path.GetExtension(_SecondFilePath);

                    string SecFileSaved = SecFileDirec + @"\" + SecFileName.Substring(0, SecFileName.Length - SecFileExt.Length) + "1.xlsx";

                    // blnSecSucc = SecondExcel.SaveAs(SecFileSaved);

                    blnSecSucc = SecondExcel.SaveAs(_SecondFilePath);

                    SecondExcel.Close();

                }

                catch (Exception exx)

                {

                    //MessageBox.Show(@"比较2-1出错:\n" + exx.ToString());

                    SecondExcel.Close();

                }

                finally

                {

                }

                #endregion

            }

            catch (Exception ex)

            {

                MessageBox.Show("对比失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);//\n对比数据时产生异常:\n" + ex.ToString());

                return;

            }

            //if (bln)

            //{

            //}

            for (int totalNum = 60; totalNum < 101; totalNum++)

            {

                pgbShow.Value = totalNum;

            }

            if (blnFirstSucc == false || blnSecSucc == false)

            {

                MessageBox.Show("您取消了对比,对比失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);

            }

            else

            {

                MessageBox.Show("对比成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

            }

            panel1.Hide();

        }

        private void frmCustNoComp_Load(object sender, EventArgs e)

        {

            panel1.Hide();

        }

    }

    public class InfoModel

    {

        string _rowIndex;

        public string RowIndex

        {

            get { return _rowIndex; }

            set { _rowIndex = value; }

        }

        string _rowValue;

        public string RowValue

        {

            get { return _rowValue; }

            set { _rowValue = value; }

        }

    }

}

本人qq为1419226548 有问题请联系此QQ 如有雷同,纯属剽窃。如果侵犯版权,请告知本人,本人必删此贴!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息