• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

php根据excel里面的内容寻找文件的代码

php 搞代码 3年前 (2022-01-22) 16次浏览 已收录 0个评论

本文主要和大家分享php根据excel里面的内容寻找文件的代码,希望能帮助到大家。

using Aspose.Cells;using System;using System.Collections.Generic;using System.IO;using System.Linq;using System.Text.RegularExpressions;namespace FindFileByExcel{    class Program    {        public static void Main(string[] args)        {            //遗漏代码的excel记录文件夹            string excelPath = @"C:\Users\qingping.li\Desktop\股东报告自动化\各种bug\未解决\十大股东遗漏代码.xlsx";            //老的excel存储文件夹            string oldExcelStoragePath = @"\\10.10.129.77\巨潮下载测试\2017\第三季度年报测试Excel\";            //被挑选出来的excel文件夹            string newExcelStoragePath = @"\\10.10.129.77\巨潮下载测试\2017\第三季度年报测试Excel\十大股东遗漏\";            //程序集 Aspose.Cells.dll, v5.3.1.0(运用cell操作类)            Cells cells = GetExcel(excelPath);            //获得所有文件            string[] excelFiles = Directory.GetFiles(oldExcelStoragePath);            string signValue = "002768";            //找到第一个            Cell celltable = cells.FindStringContains(signValue, cells.FirstCell);            List<string> list = new List<string>();            if (celltable != null && celltable.Value != null)            {                list.Add(celltable.StringValue);                Cell cellCount = cells.GetCell(celltable.Row + 1, celltable.Column);                while (cellCount != null && cellCount.StringValue != null && Regex.IsMatch(cellCount.StringValue, @"\d"))                {                    cellCount = cells.GetCell(cellCount.Row + 1, cellCount.Column);                    //获得所有的list列表    <em style="color:transparent">本文来源gao.dai.ma.com搞@代*码#网</em><a>搞代gaodaima码</a>                if (cellCount != null)                        if (!list.Contains(cellCount.StringValue))                            list.Add(cellCount.StringValue);                }                //开始复制所有excel中存在的数据到另外一个文件夹下面                List<string> copyConpanyExcelFile = new List<string>();                          foreach (string countVaue in list)                {                                       foreach (string excelFile in excelFiles)                    {                        //如果已经找到了,就不再继续寻找                        if (copyConpanyExcelFile.Contains(excelFile))                            continue;                        if (excelFile.IndexOf(countVaue) > -1)                        {                            if (!Directory.Exists(newExcelStoragePath))                                Directory.CreateDirectory(newExcelStoragePath);                            string fileName = excelFile.Split('\\')[excelFile.Split('\\').Length - 1];                            try                            {                                if (!File.Exists(newExcelStoragePath + "\\" + fileName))                                    File.Copy(excelFile, newExcelStoragePath + "\\" + fileName);                                //将找到的excel文件存储起来;下次就不再寻找                                copyConpanyExcelFile.Add(excelFile);                                //跳出当前循环                                break;                            }                            catch                            {                                continue;                            }                        }                    }                }            }            Console.Write("复制完毕!");            Console.ReadKey();        }        public static Cells GetExcel(string excelPath)        {            Workbook workbook = new Workbook();            try            {                workbook.Open(excelPath);            }            catch            {                return null;            }            return workbook.Worksheets[0].Cells;        }    }}

相关推荐:

PHP读取Excel并展示实现代码

php中通用的excel导出方法实例

Node之Excel内容的获取

以上就是php根据excel里面的内容寻找文件的代码的详细内容,更多请关注搞代码gaodaima其它相关文章!


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:php根据excel里面的内容寻找文件的代码
喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址