php根據excel裡面的內容尋找檔案的代碼

來源:互聯網
上載者:User
本文主要和大家分享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列表                    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;        }    }}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.