Esempio n. 1
0
        private static string Main_Process()
        {
            string        fileName = null;
            DirectoryInfo info     = new DirectoryInfo(oriPath);

            foreach (var ff in info.GetFiles())
            {
                if (ff.ToString().IndexOf(".xls") != -1)
                {
                    fileName = ff.ToString();
                    break;
                }
            }
            if (fileName == null)
            {
                return("無excel檔案");
            }


            Console.WriteLine("處理檔案檔名為 : {0} \n", fileName);
            Console.Write("輸入要處理的sheet頁數 : ");
            int sheetPo = Convert.ToInt32(Console.ReadLine());

            Console.WriteLine("\n---處理中---\n");

            string[,] data = ExcelClass.ExcelSaveAndRead.Read(Path.Combine(oriPath, fileName), 1, 1, sheetPo);
            MatrixS mStrData = new MatrixS(data);


            int startPo = mStrData.GetVector(0, 0).Find("日期") + 2;
            int endPo   = mStrData.GetVector(0, 0).Find("總計") - 1;
            int savePo1 = mStrData.GetVector(0, 0).Find("承商") + 1;
            int savePo2 = 9;


            DictStatstic  DICT  = new DictStatstic();
            List <string> Blong = new List <string>();

            string[,] Table2 = new string[data.GetLength(0), 2];

            MainCatch(ref DICT, ref Blong, startPo, endPo, data, ref Table2);


            string[,] OutPut = DICT.ToArray();

            string[,] OutBlong = new string[Blong.Count, 1];
            string[] tmp = Blong.ToArray();
            for (int i = 0; i < Blong.Count; i++)
            {
                OutBlong[i, 0] = tmp[i];
            }

            File.Delete(Path.Combine(savePath, fileName));
            File.Copy(Path.Combine(oriPath, fileName), Path.Combine(savePath, fileName));
            ExcelClass.ExcelSaveAndRead.Save(Path.Combine(savePath, fileName), sheetPo, savePo1 + 1, 1, OutPut);
            ExcelClass.ExcelSaveAndRead.Save(Path.Combine(savePath, fileName), sheetPo, startPo + 1, savePo2 + 1, OutBlong);
            ExcelClass.ExcelSaveAndRead.SaveCreat(Path.Combine(savePath, "Table2.xls"), "test", 2, 1, Table2);
            return("處理完成");
        }
Esempio n. 2
0
        private static void MainCatch(ref DictStatstic DICT, ref List <string> Blong, int startPo, int endPo, string[,] data, ref string[,] Table2)
        {
            MatrixS Mdata = new MatrixS(data);
            int     kk    = 0;

            for (int i = startPo; i <= endPo; i++)
            {
                /// 欲處理資料
                string[] content = data[i, 10].Split(' ');

                /// 至原始資料之字串矩陣取除目標列數,並將原始之Work與Stone工時與加班轉換並儲存至向量oriVWS中
                VectorS Vcontent = Mdata.GetVector(i, 1);
                Vector  oriVWS   = new Vector(new double[] { Convert.ToDouble(Vcontent.Data[1]), Convert.ToDouble(Vcontent.Data[2]), Convert.ToDouble(Vcontent.Data[3]), Convert.ToDouble(Vcontent.Data[4]) });

                /// 用來統計每一天所有之Work與Stone工時與加班
                Vector VWS = new Vector(new double[4]);

                /// 用來儲存每一天之歸屬資料
                string blong = "";

                foreach (string ff in content)
                {
                    if (ff.IndexOf(")") != -1)
                    {
                        Table2[kk, 0] = i.ToString();
                        Table2[kk, 0] = data[i, 0];
                        Table2[kk, 1] = ff.Split('.')[1];
                        string   catData      = ff.Substring(ff.IndexOf("(") + 1, ff.IndexOf(")") - ff.IndexOf("(") - 1);
                        string   CompanyName  = null;
                        double[] WorkAndStone = CatDataProcess(catData, ref CompanyName, ref blong);
                        Vector   vws          = new Vector(WorkAndStone);
                        DICT.Add(CompanyName, WorkAndStone);
                        VWS += vws;
                        kk++;
                    }
                }
                Vector ResVWS = oriVWS - VWS;
                blong = OriComBlongProcess(ResVWS, blong);

                Blong.Add(blong);
                DICT.Add("利晉", ResVWS.Data);
            }
        }