string pfilePath = "";
OpenFileDialog ofd = new OpenFileDialog();
ofd.Filter = "*.xlsx|*.xlsx";
if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
pfilePath = ofd.FileName;
}
if (string.IsNullOrEmpty(pfilePath))
{
MessageBox.Show("没有选中文件");
return;
}
FileInfo existingFile = new FileInfo(pfilePath);
try
{
ExcelPackage package = new ExcelPackage(existingFile);
int vSheetCount = package.Workbook.Worksheets.Count; //获取总Sheet页
ExcelWorksheet worksheet = package.Workbook.Worksheets[1];//选定 指定页
OpenFileDialog ofd = new OpenFileDialog();
ofd.Filter = "*.xlsx|*.xlsx";
if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
pfilePath = ofd.FileName;
}
if (string.IsNullOrEmpty(pfilePath))
{
MessageBox.Show("没有选中文件");
return;
}
FileInfo existingFile = new FileInfo(pfilePath);
try
{
ExcelPackage package = new ExcelPackage(existingFile);
int vSheetCount = package.Workbook.Worksheets.Count; //获取总Sheet页
ExcelWorksheet worksheet = package.Workbook.Worksheets[1];//选定 指定页