admin 管理员组文章数量: 888299
根据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列表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;}}
}
本文标签: 根据excel里面的内容寻找文件
版权声明:本文标题:根据excel里面的内容寻找文件 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.freenas.com.cn/jishu/1693582904h230586.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论