Ejemplo n.º 1
0
        private void sb_newwork_Click(object sender, EventArgs e)
        {
            XtraTabPage xinka = new XtraTabPage();

            xinka.Name = "xin";
            xinka.Text = "新工作区";
            NepCalaTable xintab = new NepCalaTable();

            xintab.Dock = DockStyle.Fill;
            xinka.Controls.Add(xintab);
            this.xtraTabControl1.TabPages.Add(xinka);
            this.xtraTabControl1.SelectedTabPage = xinka;
            this.active_nepCalaTable             = xintab;
        }
Ejemplo n.º 2
0
        private void sb_import_Click(object sender, EventArgs e)
        {
            DataSet   ds = new DataSet();
            DataTable dt = null;

            OpenFileDialog sflg = new OpenFileDialog();

            sflg.Filter = "Excel(*.xls)|*.xls|Excel(*.xlsx)|*.xlsx";
            if (sflg.ShowDialog() == System.Windows.Forms.DialogResult.Cancel)
            {
                return;
            }
            FileStream fs = new FileStream(sflg.FileName, FileMode.Open, FileAccess.Read);

            NPOI.HSSF.UserModel.HSSFWorkbook book = new NPOI.HSSF.UserModel.HSSFWorkbook(fs);
            int sheetCount = book.NumberOfSheets;

            for (int sheetIndex = 0; sheetIndex < sheetCount; sheetIndex++)
            {
                string      st_name = book.GetSheetName(sheetIndex);
                XtraTabPage xinka   = new XtraTabPage();
                xinka.Name = "xin";
                xinka.Text = st_name;
                NepCalaTable xintab = new NepCalaTable();
                xintab.Dock = DockStyle.Fill;
                xinka.Controls.Add(xintab);
                this.xtraTabControl1.TabPages.Add(xinka);
                this.xtraTabControl1.SelectedTabPage = xinka;
                this.active_nepCalaTable             = xintab;

                NPOI.SS.UserModel.ISheet sheet = book.GetSheetAt(sheetIndex);
                if (sheet == null)
                {
                    continue;
                }

                NPOI.SS.UserModel.IRow row = sheet.GetRow(0);
                if (row == null)
                {
                    continue;
                }

                int firstCellNum = row.FirstCellNum;
                int lastCellNum  = row.LastCellNum;
                if (firstCellNum == lastCellNum)
                {
                    continue;
                }

                dt = new DataTable(sheet.SheetName);
                dt.Columns.Add("bushe_xianshu", typeof(int));
                //MessageBox.Show(dt.Columns["bushe_xianshu"].DataType.ToString());
                dt.Columns.Add("bushe_daoshu", typeof(int));
                dt.Columns.Add("bushe_zongdaoshu", typeof(int));
                dt.Columns.Add("banqian_daoshu", typeof(int));
                dt.Columns.Add("ke_caiji", typeof(int));
                dt.Columns.Add("banjia_daoshu", typeof(int));
                dt.Columns.Add("hengxiangchang", typeof(int));
                dt.Columns.Add("zongxiangchang", typeof(int));
                dt.Columns.Add("zonghengbi", typeof(double));
                dt.Columns.Add("paodaobi", typeof(double));
                lastCellNum = 10;
                for (int i = firstCellNum; i < lastCellNum; i++)
                {
                    dt.Columns.Add(row.GetCell(i).StringCellValue, typeof(string));
                }

                for (int i = 1; i <= sheet.LastRowNum; i++)
                {
                    DataRow newRow = dt.Rows.Add();
                    for (int j = firstCellNum; j < lastCellNum; j++)
                    {
                        newRow[j] = sheet.GetRow(i).GetCell(j).StringCellValue;
                    }
                }
                NPOI.SS.UserModel.IRow row0 = sheet.GetRow(0);
                this.active_nepCalaTable.jifa_dianju.Text = row0.GetCell(13).StringCellValue;
                row0 = sheet.GetRow(1);
                this.active_nepCalaTable.jieshou_dianju.Text = row0.GetCell(13).StringCellValue;
                row0 = sheet.GetRow(2);
                this.active_nepCalaTable.jieshou_dianshu.Text = row0.GetCell(13).StringCellValue;
                row0 = sheet.GetRow(3);
                this.active_nepCalaTable.jifa_xianju.Text = row0.GetCell(13).StringCellValue;
                row0 = sheet.GetRow(4);
                this.active_nepCalaTable.jieshou_xianju.Text = row0.GetCell(13).StringCellValue;
                row0 = sheet.GetRow(5);
                this.active_nepCalaTable.muban_zong.Text = row0.GetCell(13).StringCellValue;
                row0 = sheet.GetRow(6);
                this.active_nepCalaTable.mobanpao.Text = row0.GetCell(13).StringCellValue;
                row0 = sheet.GetRow(7);
                this.active_nepCalaTable.jieshou_xianshu.Text = row0.GetCell(13).StringCellValue;
                row0 = sheet.GetRow(8);
                this.active_nepCalaTable.muban_heng.Text = row0.GetCell(13).StringCellValue;
                row0 = sheet.GetRow(9);
                this.active_nepCalaTable.bushe_jieshouxianshu.Text = row0.GetCell(13).StringCellValue;
                row0 = sheet.GetRow(10);
                this.active_nepCalaTable.bushe_jifaxianshu.Text = row0.GetCell(13).StringCellValue;

                ds.Tables.Add(dt);
                this.active_nepCalaTable.DDT = dt;
            }
        }