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

小云云
发布: 2018-03-05 11:19:59
原创
1708人浏览过

本文主要和大家分享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:Usersqingping.liDesktop股东报告自动化各种bug未解决十大股东遗漏代码.xlsx";
            //老的excel存储文件夹
            string oldExcelStoragePath = @"\10.10.129.77巨潮下载测试7第三季度年报测试Excel";
            //被挑选出来的excel文件夹
            string newExcelStoragePath = @"\10.10.129.77巨潮下载测试7第三季度年报测试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列表
                    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导出方法实例

代码小浣熊
代码小浣熊

代码小浣熊是基于商汤大语言模型的软件智能研发助手,覆盖软件需求分析、架构设计、代码编写、软件测试等环节

代码小浣熊 51
查看详情 代码小浣熊

Node之Excel内容的获取

立即学习PHP免费学习笔记(深入)”;

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

相关标签:
WPS零基础入门到精通全套教程!
WPS零基础入门到精通全套教程!

全网最新最细最实用WPS零基础入门到精通全套教程!带你真正掌握WPS办公! 内含Excel基础操作、函数设计、数据透视表等

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
作者最新文章
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号