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++)
C#excel 文件上传并进行分页
最新推荐文章于 2024-01-19 14:13:02 发布