Exemplo n.º 1
0
        public static List <string> GetXlsxSheetnames(string filePath, out string message)
        {
            message = "success";
            List <string> listSheetname = new List <string>();

            if (ExcelUtils.getExcelExtesion(ExcelUtils.ExceType.Excel2007) != Path.GetExtension(filePath))
            {
                message = "文件格式不为Excel2007";
                return(new List <string>());
            }
            FileStream fileStream = null;

            try
            {
                fileStream = File.OpenRead(filePath);
            }
            catch (IOException ex)
            {
                message = ex.Message;
                return(new List <string>());
            }
            finally
            {
                int a = 2;
            }
            using (fileStream)
            {
                ExcelPackage package = new ExcelPackage(fileStream);
                foreach (var worksheet in package.Workbook.Worksheets)
                {
                    listSheetname.Add(worksheet.Name);
                }
            }
            return(listSheetname);
        }
Exemplo n.º 2
0
        public static bool IsExcelFile(string filePath)
        {
            string fileExtension = System.IO.Path.GetExtension(filePath);

            if (ExcelUtils.getExcelExtesion(ExcelUtils.ExceType.Excel2003) == fileExtension || ExcelUtils.getExcelExtesion(ExcelUtils.ExceType.Excel2007) == fileExtension)
            {
                return(true);
            }
            return(false);
        }
Exemplo n.º 3
0
        public static List <string> GetSheetnames(string filePath, out string message)
        {
            message = "success";
            List <string> listSheetname = new List <string>();

            if (!IsExcelFile(filePath))
            {
                return(new List <string>());
            }
            if (ExcelUtils.getExcelExtesion(ExcelUtils.ExceType.Excel2003) == Path.GetExtension(filePath))
            {
                listSheetname = GetXlsSheetnames(filePath, out message);
            }
            else if (ExcelUtils.getExcelExtesion(ExcelUtils.ExceType.Excel2007) == Path.GetExtension(filePath))
            {
                listSheetname = GetXlsxSheetnames(filePath, out message);
            }
            return(listSheetname);
        }