Пример #1
0
        private void button2_Click(object sender, EventArgs e)
        {
            ExcelOpreate ExcelOp = new ExcelOpreate("E:\\TEST\\2.xlsx");
            int          count   = 0;

            progressBar2.Maximum = 51;
            for (int i = 7; i < 51; i++)
            {
                if (count < GetTB.Rows.Count)
                {
                    ExcelOp.WriteExcelCell(i, 2, GetTB.Rows[count]["姓名"].ToString());
                    for (int j = 0; j < 31; j++)
                    {
                        ExcelOp.WriteExcelCell(i, j + 3, GetTB.Rows[count]["考勤代码"].ToString());
                        count++;
                    }
                    progressBar2.Value = i + 1;
                }
                else
                {
                    break;
                }
            }
            progressBar2.Value = 51;
            ExcelOp.Save();
            ExcelOp.KillExcel();
        }
Пример #2
0
        /// <summary>
        /// 读取Excel文件(孔隙度、渗透率)
        /// </summary>
        /// <param name="FilePath"></param>
        private void ReadExcel(string FilePath)
        {
            // ExcelOperate EO = new ExcelOperate();
            //Excel.Application myExcel = new Excel.Application();

            ////取得Excel文件中共有的sheet的数目

            //object oMissing = System.Reflection.Missing.Value;

            //myExcel.Application.Workbooks.Open(FilePath, oMissing, oMissing, oMissing, oMissing, oMissing,
            //oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing);

            //Excel.Workbook myBook = myExcel.Workbooks[1];
            //int sheetNum = myBook.Worksheets.Count;

            ExcelOpreate ExcelOp  = new ExcelOpreate(FilePath);
            DataTable    tblDatas = new DataTable("Datas");
            DataColumn   dc       = null;

            dc = tblDatas.Columns.Add("姓名", Type.GetType("System.String"));
            dc = tblDatas.Columns.Add("部门", Type.GetType("System.String"));
            dc = tblDatas.Columns.Add("日期", Type.GetType("System.String"));
            dc = tblDatas.Columns.Add("状态", Type.GetType("System.String"));
            dc = tblDatas.Columns.Add("考勤代码", Type.GetType("System.String"));
            //for (int j = 1; j < sheetNum; j++)
            //{
            ExcelOp.SheelTableIndex = 1;
            DataRow newRow;

            //string falg = ExcelOp.ReadExcelCellString(1, 2);
            //if (falg.Contains("月度汇总"))
            //{
            for (int i = 5; i < 200; i++)
            {
                progressBar1.Maximum = 100;
                if (ExcelOp.ReadExcelCellString(i, 1) != "")
                {
                    for (int j = 27; j < 58; j++)
                    {
                        newRow         = tblDatas.NewRow();
                        newRow["姓名"]   = ExcelOp.ReadExcelCellString(i, 1);
                        newRow["部门"]   = ExcelOp.ReadExcelCellString(i, 2);
                        newRow["日期"]   = ExcelOp.ReadExcelCellString(3, j);
                        newRow["状态"]   = ExcelOp.ReadExcelCellString(i, j);
                        newRow["考勤代码"] = GetWorkCode(ExcelOp.ReadExcelCellString(i, j));
                        //newRow["渗透率水平"] = ExcelOp.ReadExcelCellString(i, 8);
                        //newRow["渗透率垂直"] = ExcelOp.ReadExcelCellString(i, 9);
                        tblDatas.Rows.Add(newRow);
                    }
                    progressBar1.Value = i + 1;
                }
                else
                {
                    break;
                }
                progressBar1.Value = 100;
            }
            //}
            //progressBar1.Maximum = sheetNum;
            //progressBar1.Value = j + 1;
            //}
            dataGridView1.DataSource = tblDatas;
            GetTB = tblDatas;
            //MessageBox.Show("共" + tblDatas.Rows.Count.ToString() + "行");
            ExcelOp.KillExcel();
        }