C#excel 文件上传并进行分页

 private int Inum = 1;  //行号,规定其索引初始值为1
        int pagesize = 2;//每页的数据条数
        int pagecount = 0;//共有几页
        string file = "";
        int allCount = 0;//共有几条
        DataTable dw = new DataTable();

        private void view_bt_Click(object sender, EventArgs e)
        {
            OpenFileDialog fileDialog = new OpenFileDialog();
            fileDialog.Multiselect = true;
            fileDialog.Title = "请选择文件";
            fileDialog.Filter = "所有文件(*.*)|*.*";//判断文件类型
            if (fileDialog.ShowDialog() == DialogResult.OK)
            {
                file = fileDialog.FileName;
                //MessageBox.Show("已选择文件:" + file, "选择文件提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            if (MessageBoxButtons.OK.ToString().Equals("OK"))
            {
                filePath_text.Text = file;
            }

            ReadFromExcelFileService readFromExcelFileService = new ReadFromExcelFileService();
            dw = readFromExcelFileService.GetData(file);//调用GetData方发写上Excel文件所在的路径,这样就能获取到Excel表里面的数据了然后我们用个集合把读取到数据添加进去


            show(1, pagesize);

        }

        private void UploadDelivery_Load(object sender, EventArgs e)
        {

        }


        public DataTable GetPagedTable(DataTable dt, int PageIndex, int PageSize)//PageIndex表示第几页,PageSize表示每页的记录数
        {
            if (PageIndex == 0)
                return dt;//0页代表每页数据,直接返回

            DataTable newdt = dt.Copy();
            newdt.Clear();//copy dt的框架

            int rowbegin = (PageIndex - 1) * PageSize;
            int rowend = PageIndex * PageSize;

            if (rowbegin >= dt.Rows.Count)
                return newdt;//源数据记录数小于等于要显示的记录,直接返回dt

            if (rowend > dt.Rows.Count)
                rowend = dt.Rows.Count;
            for (int i = rowbegin; i <= rowend - 1; i++)
            
评论 14
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值