public WorksheetProcessor(object dataSource) {
     wb = new Workbook();
     wb.CreateNewDocument();
     Worksheet sheet = wb.Worksheets[0];
     Table sheetDataTable = sheet.Tables.Add(dataSource, sheet.Range["B2:C50"]);
     sheet.Cells["E2"].Formula = "IFERROR(CORREL(Table1[Column1], Table1[Column2]),0)";
 }
        private void btn_open_Click(object sender, EventArgs e)
        {
            isFirstLoad = true;
            string fileName;

            SaveFileDialog saveFileDialog = new SaveFileDialog();

            saveFileDialog.Filter           = "excel2003文件|*.xls|excel文件|*.xlsx";
            saveFileDialog.RestoreDirectory = true;
            saveFileDialog.FilterIndex      = 2;
            if (saveFileDialog.ShowDialog() == DialogResult.OK)
            {
                docPath = fileName = saveFileDialog.FileName;

                textEdit_file.EditValue = fileName;

                workbook = new Workbook();

                workbook.CreateNewDocument();

                workbook.SaveDocument(textEdit_file.EditValue.ToString());

                textEdit_fileName.EditValue = "main_sheet";

                isFirstLoad = false;
            }
        }
예제 #3
0
        public void fun(string path, string date, string h, string m, string s)
        {
            WebClient client = new WebClient();

            client.Encoding = Encoding.UTF8;
            client.Headers.Add("Content-Type", "application/x-www-form-urlencoded");

            //庐山 1179
            //北京欢乐谷 5381
            //丽江古城 894
            //首都机场786
            //厦门大学6423
            string str    = string.Format(@"https://heat.qq.com/api/getHeatDataByTime.php?region_id=5381&datetime={0}+{1}:{2}:{3}", date, h, m, s);
            Stream stream = client.OpenRead(str);

            string str_json = new StreamReader(stream).ReadToEnd();

            str_json = str_json.Replace("{", "").Replace("}", "");

            string[] strs = str_json.Split('"');

            CoordVal coordVal = null;

            Workbook workbook = new Workbook();

            workbook.CreateNewDocument();
            workbook.SaveDocument(string.Format(@"{0}\r{1}_{2}{3}.xls", path, date.Replace("-", ""), h, m));

            Worksheet worksheet = workbook.Worksheets[0];

            worksheet.Name = "routeSheet";

            worksheet[0, 0].SetValue("xcoord");
            worksheet[0, 1].SetValue("ycoord");
            worksheet[0, 2].SetValue("val");

            int rowOrder = 0;

            for (int i = 1; i < strs.Length; i = i + 2)
            {
                rowOrder++;

                coordVal = new CoordVal();

                coordVal.coordX = Convert.ToInt32(strs[i].Split(',')[0]);
                coordVal.coordY = Convert.ToInt32(strs[i].Split(',')[1]);
                coordVal.val    = Convert.ToInt32(strs[i + 1].Replace(":", "").Replace(",", ""));

                //Console.WriteLine(string.Format("x:{0}, y:{1}, val:{2}", coordVal.coordX, coordVal.coordY, coordVal.val));

                worksheet[rowOrder, 0].SetValue(coordVal.coordX);
                worksheet[rowOrder, 1].SetValue(coordVal.coordY);
                worksheet[rowOrder, 2].SetValue(coordVal.val);
            }

            workbook.SaveDocument(string.Format(@"{0}\r{1}_{2}{3}.xls", path, date.Replace("-", ""), h, m));
        }
예제 #4
0
        private void btn_open_Click(object sender, EventArgs e)
        {
            UtilClass.FolderBrowserDialog dlg = new UtilClass.FolderBrowserDialog();

            DialogResult dr = dlg.ShowDialog(this);

            if (dr == System.Windows.Forms.DialogResult.OK)
            {
                filePath = dlg.DirectoryPath;
                textEdit_file.EditValue = filePath;
            }

            workbook = new Workbook();

            workbook.CreateNewDocument();

            workbook.SaveDocument(textEdit_file.EditValue.ToString() + @"\aa.xlsx");

            textEdit_fileName.EditValue = "main_sheet";

            isFirstLoad = false;
            //string fileName;

            //SaveFileDialog saveFileDialog = new SaveFileDialog();
            //saveFileDialog.Filter = "excel2003文件|*.xls|excel文件|*.xlsx";
            //saveFileDialog.RestoreDirectory = true;
            //saveFileDialog.FilterIndex = 2;
            //if (saveFileDialog.ShowDialog() == DialogResult.OK)
            //{
            //    docPath = fileName = saveFileDialog.FileName;

            //    textEdit_file.EditValue = fileName;

            //    workbook = new Workbook();

            //    workbook.CreateNewDocument();

            //    workbook.SaveDocument(textEdit_file.EditValue.ToString());

            //    textEdit_fileName.EditValue = "main_sheet";

            //    isFirstLoad = false;
            //}
        }
예제 #5
0
        private static void Main()
        {
            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();

            try
            {
                string connectionString = ConfigurationUtility
                                          .GetString("connectionString")
                                          .ThrowIfNull("connectionString not set");

                int delay = ConfigurationUtility
                            .GetInt32("delay");

                DateTime threshold = DateTime.Today
                                     .AddMonths(-delay);

                using (IrbisConnection connection
                           = new IrbisConnection(connectionString))
                {
                    DatabaseInfo[] databases
                        = connection.ListDatabases();

                    DebtorManager manager
                        = new DebtorManager(connection)
                        {
                        ToDate = threshold
                        };
                    manager.BatchRead += (sender, args) =>
                    {
                        Console.Write(".");
                    };
                    DebtorInfo[] debtors = manager.GetDebtors
                                           (
                        connection.Search("RB=$")
                                           );
                    debtors = debtors.Where
                              (
                        debtor => !debtor.WorkPlace
                        .SafeContains(LibraryName)
                              )
                              .ToArray();
                    Console.WriteLine();
                    Console.WriteLine
                    (
                        "Debtors: {0}",
                        debtors.Length
                    );

                    VisitInfo[] allDebt = debtors.SelectMany
                                          (
                        debtor => debtor.Debt
                                          )
                                          .ToArray();
                    Console.WriteLine
                    (
                        "Books in debt: {0}",
                        allDebt.Length
                    );


                    Workbook workbook = new Workbook();
                    workbook.CreateNewDocument();
                    Worksheet worksheet = workbook.Worksheets[0];

                    int row = 0;

                    worksheet.Cells[row, 0].Value = "ФИО";
                    worksheet.Cells[row, 1].Value = "Билет";
                    worksheet.Cells[row, 2].Value = "Краткое описание";
                    worksheet.Cells[row, 3].Value = "Год";
                    worksheet.Cells[row, 4].Value = "Номер";
                    worksheet.Cells[row, 5].Value = "Цена";
                    worksheet.Cells[row, 6].Value = "Хранение";
                    worksheet.Cells[row, 7].Value = "Дата";
                    worksheet.Cells[row, 8].Value = "Отдел";

                    row++;

                    for (int i = 0; i < allDebt.Length; i++)
                    {
                        if (i % 100 == 0)
                        {
                            Console.Write(".");
                        }

                        VisitInfo debt = allDebt[i];

                        string description = debt.Description;
                        string inventory   = debt.Inventory;
                        string database    = debt.Database;
                        string year        = string.Empty;
                        string index       = debt.Index;
                        string price       = string.Empty;

                        if (!string.IsNullOrEmpty(index) &&
                            !string.IsNullOrEmpty(database))
                        {
                            if (databases.FirstOrDefault
                                (
                                    db => db.Name.SameString(database)
                                )
                                == null)
                            {
                                continue;
                            }

                            try
                            {
                                connection.Database = database;
                                MarcRecord record
                                    = connection.SearchReadOneRecord
                                      (
                                          "\"I={0}\"",
                                          index
                                      );
                                if (!ReferenceEquals(record, null))
                                {
                                    description = connection.FormatRecord
                                                  (
                                        FormatName,
                                        record.Mfn
                                                  );
                                    year  = GetYear(record);
                                    price = GetPrice(debt, record);
                                }
                            }
                            catch (Exception ex)
                            {
                                Console.WriteLine(ex.Message);
                            }
                        }

                        worksheet.Cells[row, 0].Value = debt.Reader.FullName;
                        worksheet.Cells[row, 1].Value = debt.Reader.Ticket;
                        worksheet.Cells[row, 2].Value = description;
                        worksheet.Cells[row, 3].Value = year;
                        worksheet.Cells[row, 4].Value = inventory;
                        worksheet.Cells[row, 5].Value = price;
                        worksheet.Cells[row, 6].Value = debt.Sigla;
                        worksheet.Cells[row, 7].Value = debt.DateExpectedString;
                        worksheet.Cells[row, 8].Value = debt.Department;

                        for (int j = 0; j <= 6; j++)
                        {
                            Cell cell = worksheet.Cells[row, j];
                            cell.Borders.SetAllBorders
                            (
                                Color.Black,
                                BorderLineStyle.Hair
                            );
                        }

                        row++;
                    }

                    workbook.SaveDocument(OutputFile);

                    Console.WriteLine("All done");

                    stopwatch.Stop();
                    TimeSpan elapsed = stopwatch.Elapsed;
                    Console.WriteLine("Elapsed: {0}", elapsed);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
예제 #6
0
        private void button3_Click(object sender, EventArgs e)
        {
            string path = @"G:\数据采集\景点人流\test7";
            string date = "2018-04-29";

            string h, m;

            WebClient client = new WebClient();

            client.Encoding = Encoding.UTF8;
            client.Headers.Add("Content-Type", "application/x-www-form-urlencoded");

            string str    = @"https://heat.qq.com/api/getRegionHeatMapInfoById.php?id=5381";
            Stream stream = client.OpenRead(str);

            string str_json = new StreamReader(stream).ReadToEnd();

            JObject obj = JObject.Parse(str_json);

            string max         = obj["max"].ToString();
            string name        = obj["name"].ToString();
            string boundary    = obj["boundary"].ToString();
            string center_gcj  = obj["center_gcj"].ToString();
            string lower_left  = obj["lower_left"].ToString();
            string upper_right = obj["upper_right"].ToString();

            Workbook workbook = new Workbook();

            workbook.CreateNewDocument();
            workbook.SaveDocument(string.Format(@"{0}\tt01.xlsx", path));

            Worksheet worksheet = workbook.Worksheets[0];

            worksheet.Name = "routeSheet";

            worksheet[0, 0].SetValue("oid");
            worksheet[0, 1].SetValue("b_name");
            worksheet[0, 2].SetValue("b_type");
            worksheet[0, 3].SetValue("lng");
            worksheet[0, 4].SetValue("lat");

            worksheet[1, 0].SetValue(1);
            worksheet[1, 1].SetValue(name);
            worksheet[1, 2].SetValue("center_pnt");
            worksheet[1, 3].SetValue(center_gcj.Split(',')[0]);
            worksheet[1, 4].SetValue(center_gcj.Split(',')[1]);

            worksheet[2, 0].SetValue(2);
            worksheet[2, 1].SetValue(name);
            worksheet[2, 2].SetValue("lower_left");
            worksheet[2, 3].SetValue(lower_left.Split(',')[0]);
            worksheet[2, 4].SetValue(lower_left.Split(',')[1]);

            worksheet[3, 0].SetValue(3);
            worksheet[3, 1].SetValue(name);
            worksheet[3, 2].SetValue("upper_right");
            worksheet[3, 3].SetValue(upper_right.Split(',')[0]);
            worksheet[3, 4].SetValue(upper_right.Split(',')[1]);

            string[] boundStrs = boundary.Split('|');
            for (int i = 0; i < boundStrs.Length - 1; i++)
            {
                worksheet[i + 4, 0].SetValue(i + 4);
                worksheet[i + 4, 1].SetValue(name);
                worksheet[i + 4, 2].SetValue("bound_pnt");
                worksheet[i + 4, 3].SetValue(boundStrs[i].Split(',')[0]);
                worksheet[i + 4, 4].SetValue(boundStrs[i].Split(',')[1]);
            }

            workbook.SaveDocument(string.Format(@"{0}\tt01.xlsx", path));


            //MessageBox.Show(obj["max"].ToString());
        }
예제 #7
0
        private static void Main()
        {
            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();

            try
            {
                string connectionString = ConfigurationUtility
                                          .GetString("connectionString")
                                          .ThrowIfNull("connectionString not set");
                Threshold = IrbisDate.ConvertStringToDate
                            (
                    ConfigurationUtility
                    .GetString("threshold")
                    .ThrowIfNull("threshold not set")
                            );
                LowerBound = DateTime.MinValue;
                string lowerText = ConfigurationUtility.GetString("lowerBound");
                if (!string.IsNullOrEmpty(lowerText))
                {
                    LowerBound = IrbisDate.ConvertStringToDate(lowerText);
                }

                Console.WriteLine("Loading readers");

                List <ReaderInfo> allReaders = new List <ReaderInfo>();
                OldReaders = new BlockingCollection <ReaderInfo>();

                using (IrbisConnection connection
                           = new IrbisConnection(connectionString))
                {
                    ReaderManager manager = new ReaderManager(connection)
                    {
                        OmitDeletedRecords = true
                    };
                    manager.BatchRead += (obj, ea) => Console.Write(".");

                    string[] databases = ConfigurationUtility.GetString("databases")
                                         .ThrowIfNull("databases not specified")
                                         .Split
                                         (
                        new[] { ' ', ';', ',' },
                        StringSplitOptions.RemoveEmptyEntries
                                         );

                    foreach (string database in databases)
                    {
                        Console.WriteLine
                        (
                            "Database: {0}, records: {1}",
                            database,
                            connection.GetMaxMfn(database) - 1
                        );

                        allReaders.AddRange
                        (
                            manager.GetAllReaders(database)
                        );

                        Console.WriteLine();
                    }
                }

                WriteDelimiter();

                Console.WriteLine("Merging");
                Console.WriteLine("Records before merging: {0}", allReaders.Count);

                allReaders = ReaderManager.MergeReaders(allReaders);

                Console.WriteLine("Records after merging: {0}", allReaders.Count);
                WriteDelimiter();

                Console.WriteLine("Filtering");

                ParallelOptions options = new ParallelOptions
                {
                    MaxDegreeOfParallelism = 4
                };
                Parallel.ForEach(allReaders, options, ProcessReader);

                ReaderInfo[] oldReaders = OldReaders.ToArray();

                WriteDelimiter();

                Console.WriteLine("Sorting");

                oldReaders = oldReaders.OrderBy
                             (
                    reader => reader.FullName
                             )
                             .ToArray();

                WriteDelimiter();

                Console.WriteLine
                (
                    "Create table: {0} lines",
                    oldReaders.Length
                );

                Workbook workbook = new Workbook();
                workbook.CreateNewDocument();
                Worksheet worksheet = workbook.Worksheets[0];

                int row = 0;

                worksheet.Cells[row, 0].Value = "ФИО";
                worksheet.Cells[row, 1].Value = "Билет";
                worksheet.Cells[row, 2].Value = "Регистрация";
                worksheet.Cells[row, 3].Value = "Кол-во";
                worksheet.Cells[row, 4].Value = "Последнее событие";
                worksheet.Cells[row, 5].Value = "Отделы";

                DrawBorders(worksheet, row);

                row++;

                for (int i = 0; i < oldReaders.Length; i++)
                {
                    if (i % 100 == 0)
                    {
                        Console.Write(".");
                    }

                    ReaderInfo reader   = oldReaders[i];
                    string     lastDate = (string)reader.UserData;
                    if (string.IsNullOrEmpty(lastDate))
                    {
                        lastDate = "--";
                    }

                    string departments = StringUtility.Join
                                         (
                        ", ",
                        reader.Registrations
                        .Select(reg => reg.Chair)
                        .Concat
                        (
                            reader.Visits
                            .Select(visit => visit.Department)
                        )
                        .NonEmptyLines()
                        .Distinct()
                                         );

                    worksheet.Cells[row, 0].Value = reader.FullName;
                    worksheet.Cells[row, 1].Value = reader.Ticket;
                    worksheet.Cells[row, 2].Value = reader.RegistrationDate
                                                    .ToShortDateString();
                    worksheet.Cells[row, 3].Value = reader.Visits.Length
                                                    + reader.Registrations.Length;
                    worksheet.Cells[row, 4].Value = lastDate;
                    worksheet.Cells[row, 5].Value = departments;

                    DrawBorders(worksheet, row);

                    row++;
                }

                WriteDelimiter();

                workbook.SaveDocument(OutputFile);

                Console.WriteLine("All done");

                stopwatch.Stop();
                TimeSpan elapsed = stopwatch.Elapsed;
                Console.WriteLine("Elapsed: {0}", elapsed);
                Console.WriteLine("Old readers: {0}", oldReaders.Length);
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception);
            }
        }
예제 #8
0
        protected override ResultStatus Retrieve()
        {
            documentViewer1.DocumentSource = null;

            try {
                ShowMsg("開始讀取");
                if (!GetData())
                {
                    return(ResultStatus.Fail);
                }

                ShowMsg("資料搜尋...");
                //判斷連續x個月不符造市規定
                DataTable ids = b50032.CompareDataByParallel(_Data, SleCMth.Text);
                _Data = b50032.FilterDataByParallel(_Data, ids);

                ShowMsg("讀取中...");

                List <ReportProp> caption = new List <ReportProp> {
                    new ReportProp {
                        DataColumn = "CP_ROW", Caption = "筆數", CellWidth = 40, DetailRowFontSize = 8, HeaderFontSize = 11
                    },
                    new ReportProp {
                        DataColumn = "AMM0_BRK_NO", Caption = "期貨商        代號", CellWidth = 70, DetailRowFontSize = 10, HeaderFontSize = 11, DataRowMerge = true
                    },
                    new ReportProp {
                        DataColumn = "BRK_ABBR_NAME", Caption = "期貨商名稱", CellWidth = 150, DetailRowFontSize = 9, HeaderFontSize = 11, DataRowMerge = true
                    },
                    new ReportProp {
                        DataColumn = "AMM0_ACC_NO", Caption = "帳號", CellWidth = 60, DetailRowFontSize = 10, HeaderFontSize = 11, DataRowMerge = true
                    },
                    new ReportProp {
                        DataColumn = "AMM0_PROD_ID", Caption = "商品名稱", CellWidth = 80, DetailRowFontSize = 10, HeaderFontSize = 11, DataRowMerge = true
                    },
                    new ReportProp {
                        DataColumn = "AMM0_YMD", Caption = "日期", CellWidth = 65, DetailRowFontSize = 9, HeaderFontSize = 11
                    },
                    new ReportProp {
                        DataColumn = "AMM0_OM_QNTY", Caption = "委託          成交量", CellWidth = 65, textAlignment = TextAlignment.MiddleRight, TextFormatString = "{0:#,##0}", DetailRowFontSize = 10, HeaderFontSize = 11
                    },
                    new ReportProp {
                        DataColumn = "AMM0_QM_QNTY", Caption = "報價          成交量", CellWidth = 65, textAlignment = TextAlignment.MiddleRight, TextFormatString = "{0:#,##0}", DetailRowFontSize = 10, HeaderFontSize = 11
                    },
                    new ReportProp {
                        DataColumn = "QNTY", Caption = "造市量", CellWidth = 65, textAlignment = TextAlignment.MiddleRight, TextFormatString = "{0:#,##0}", DetailRowFontSize = 10, HeaderFontSize = 11,
                        Expression = new DevExpress.XtraReports.UI.ExpressionBinding[] {
                            new DevExpress.XtraReports.UI.ExpressionBinding("BeforePrint", "Text", "[QNTY]"),
                            new DevExpress.XtraReports.UI.ExpressionBinding("BeforePrint", "BackColor", "Iif ([QNTY] < [MMF_QNTY_LOW], RGB(255,128,255), RGB(255,255,255))")
                        }
                    },
                    new ReportProp {
                        DataColumn = "CP_M_QNTY", Caption = "造市者   總成交量", CellWidth = 75, textAlignment = TextAlignment.MiddleRight, TextFormatString = "{0:#,##0}", DetailRowFontSize = 10, HeaderFontSize = 11
                    },
                    new ReportProp {
                        DataColumn = "CP_RATE_M", Caption = "總成交量   市佔率(%)", CellWidth = 60, textAlignment = TextAlignment.MiddleRight, TextFormatString = "{0:##0.0#}", DetailRowFontSize = 10, HeaderFontSize = 8
                    },
                    new ReportProp {
                        DataColumn = "AMM0_VALID_CNT", Caption = "有效報價     筆數", CellWidth = 75, textAlignment = TextAlignment.MiddleRight, TextFormatString = "{0:#,##0}", DetailRowFontSize = 10, HeaderFontSize = 11
                    },
                    new ReportProp {
                        DataColumn = "VALID_RATE", Caption = "有效報/詢價   比例(%)", CellWidth = 70, textAlignment = TextAlignment.MiddleRight, TextFormatString = "{0:##0.0#}", DetailRowFontSize = 10, HeaderFontSize = 8,
                        Expression = new DevExpress.XtraReports.UI.ExpressionBinding[] {
                            new DevExpress.XtraReports.UI.ExpressionBinding("BeforePrint", "Text", "[VALID_RATE]"),
                            new DevExpress.XtraReports.UI.ExpressionBinding("BeforePrint", "BackColor", "Iif ([VALID_RATE] < [MMF_RESP_RATIO], RGB(255,128,255), RGB(255,255,255))")
                        }
                    },
                    new ReportProp {
                        DataColumn = "AMM0_MARKET_R_CNT", Caption = "全市場   詢價筆數", CellWidth = 75, textAlignment = TextAlignment.MiddleRight, TextFormatString = "{0:#,##0}", DetailRowFontSize = 10, HeaderFontSize = 11
                    },
                    new ReportProp {
                        DataColumn = "AMM0_MARKET_M_QNTY", Caption = "全市場   總成交量", CellWidth = 75, textAlignment = TextAlignment.MiddleRight, TextFormatString = "{0:#,##0}", DetailRowFontSize = 10, HeaderFontSize = 11
                    },
                    new ReportProp {
                        DataColumn = "AMM0_KEEP_FLAG", Caption = "符合報價每日平均維持時間", CellWidth = 55, textAlignment = TextAlignment.MiddleCenter, DetailRowFontSize = 10, HeaderFontSize = 8
                    }
                };
                _defReport = new defReport(_Data, caption);
                ShowReport(_defReport);

                ShowMsg("匯出檔案...");
                string destinationFilePath = Path.Combine(GlobalInfo.DEFAULT_REPORT_DIRECTORY_PATH, "50032.xlsx");
                try {
                    Workbook workbook = new Workbook();
                    workbook.CreateNewDocument();
                    workbook.SaveDocument(destinationFilePath, DocumentFormat.Xlsx);
                    ids.Columns.Remove(ids.Columns["CP_ROW"]);
                    ids.Columns.Remove(ids.Columns["CP_M_QNTY"]);
                    ids.Columns.Remove(ids.Columns["CP_RATE_M"]);
                    ids.Columns.Remove(ids.Columns["CP_INVALID"]);
                    workbook.Worksheets[0].Import(ids, true, 0, 0);
                    workbook.SaveDocument(destinationFilePath);
                }
                catch (Exception ex) {
                    if (File.Exists(destinationFilePath))
                    {
                        File.Delete(destinationFilePath);
                    }
                    throw ex;
                }
            }
            catch (Exception ex) {
                throw ex;
            }
            finally {
                EndExport();
            }

            return(ResultStatus.Success);
        }
예제 #9
0
        protected override ResultStatus Export()
        {
            string lsRptName = ConditionText().Trim();

            StartExport(_ProgramID, lsRptName);

            //開啟檔案
            Workbook workbook = new Workbook();

            try {
                if (gbDetial.EditValue.Equals("rb_detail"))
                {
                    DataTable dt;
                    if (gbMarket.EditValue.Equals("rb_market_1"))
                    {
                        dt = dao50020.List50020dAH(emStartDate.DateTimeValue, emEndDate.DateTimeValue);
                    }
                    else
                    {
                        dt = dao50020.List50020d(emStartDate.DateTimeValue, emEndDate.DateTimeValue);
                    }

                    if (dt.Rows.Count <= 0)
                    {
                        MessageDisplay.Info(MessageDisplay.MSG_NO_DATA);
                        return(ResultStatus.Fail);
                    }

                    dt.Columns["DATA_DATE"].ColumnName = "交易日期";
                    dt.Columns["FCM"].ColumnName       = "期貨商";
                    dt.Columns["PROD"].ColumnName      = "商品";
                    dt.Columns["SEND_TIME"].ColumnName = "詢價送出時間";

                    string csvFilePath = Path.Combine(GlobalInfo.DEFAULT_REPORT_DIRECTORY_PATH, $"50020_detail_{DateTime.Now.ToString("yyyy.MM.dd-hh.mm.ss")}.csv");
                    workbook.CreateNewDocument();
                    workbook.SaveDocument(csvFilePath, DocumentFormat.Csv);
                    workbook.Options.Export.Csv.WritePreamble = true;//不加這段中文會是亂碼
                    workbook.Worksheets[0].Import(dt, true, 0, 0);
                    workbook.SaveDocument(csvFilePath);
                    return(ResultStatus.Success);
                }

                Retrieve();

                //讀取資料
                if (_Data.Rows.Count <= 0)
                {
                    MessageDisplay.Info(MessageDisplay.MSG_NO_DATA);
                    return(ResultStatus.Fail);
                }

                //複製檔案
                _D500Xx.Filename = PbFunc.wf_copy_file(_ProgramID, _ProgramID);
                if (_D500Xx.Filename == "")
                {
                    return(ResultStatus.Fail);
                }
                _D500Xx.LogText = _D500Xx.Filename;

                if (lsRptName == "")
                {
                    lsRptName = "報表條件:" + "(" + DateText() + ")";
                }
                else
                {
                    lsRptName = ConditionText().Trim() + " " + "(" + DateText() + ")";
                }

                workbook.LoadDocument(_D500Xx.Filename);
                //切換Sheet
                Worksheet worksheet = workbook.Worksheets[0];
                worksheet.Cells["E3"].Value = lsRptName;

                worksheet.Import(_Data, false, 4, 0);
                workbook.SaveDocument(_D500Xx.Filename);
            }
            catch (Exception ex) {
                WriteLog(ex);
                WfRunError();
            }
            finally {
                EndExport();
            }

            return(ResultStatus.Success);
        }
예제 #10
0
        private void fun1()
        {
            DateTime dt    = Convert.ToDateTime(dateEdit1.EditValue.ToString());
            DateTime dt1   = Convert.ToDateTime(dateEdit2.EditValue.ToString());
            string   date  = dt.ToString("yyyyMMdd");
            string   date1 = dt1.ToString("yyyyMMdd");

            int      dayInterval = (dt1 - dt).Days;
            DateTime dt_temp     = dt;
            string   date_temp   = "";

            for (int d = 0; d <= dayInterval; d++)
            {
                dt_temp   = dt.AddDays(d);
                date_temp = dt_temp.ToString("yyyyMMdd");

                workbook_temp_path = string.Format(@"{0}\{1}.xlsx", filePath, date_temp);

                workBook_temp = new Workbook();
                workBook_temp.CreateNewDocument();
                workBook_temp.SaveDocument(workbook_temp_path);
                workBook_temp.Worksheets[0].CopyFrom(worksheet);
                worksheet_temp = workBook_temp.Worksheets[0];


                Workbook tem_workbook = new Workbook();
                tem_workbook.LoadDocument(forecastCodeFile);

                Range range = tem_workbook.Worksheets[0].GetUsedRange();

                WebClient client = new WebClient();
                client.Encoding = Encoding.UTF8;
                client.Headers.Add("Content-Type", "application/x-www-form-urlencoded");

                Stream        stream   = null;
                string        str_json = null;
                List <string> list     = new List <string>();
                string[]      itemStrs = null;

                for (int i = 1; i < range.RowCount; i++)
                {
                    try
                    {
                        string vv = SetAddress(date_temp, tem_workbook.Worksheets[0][i, 1].Value.ToString(), dataType);
                        stream = client.OpenRead(vv);
                    }
                    catch (Exception ex)
                    {
                        // MessageBox.Show(tem_workbook.Worksheets[0][i, 1].Value.ToString() + "," + tem_workbook.Worksheets[0][i, 2].Value.ToString());
                        //MessageBox.Show("操作超时,当前工作将自动退出。请在稳定的网络环境下执行此任务!");

                        continue;

                        if (thread.ThreadState == System.Threading.ThreadState.Running)
                        {
                            thread.Abort();
                        }
                        this.Close();
                    }



                    str_json = new StreamReader(stream).ReadToEnd();

                    if (str_json != "")
                    {
                        try
                        {
                            //MessageBox.Show(str_json);
                            Regex regexObj = new Regex(@"\[(?<result>)[^[\]]+\]");
                            System.Text.RegularExpressions.Match matchResult = regexObj.Match(str_json);
                            int tempRow = 1;
                            while (matchResult.Success)
                            {
                                string s1 = matchResult.Groups[0].Value.Replace("[", "").Replace("]", "");
                                //MessageBox.Show(string.Format("i:{0}, {1}", i, s1));
                                itemStrs = s1.Split(',');

                                if (target_datatype == "全部")
                                {
                                    worksheet_temp[10 * (i - 1) + tempRow, 0].SetValue(10 * (i - 1));
                                    worksheet_temp[10 * (i - 1) + tempRow, 1].SetValue(dataType);
                                    worksheet_temp[10 * (i - 1) + tempRow, 2].SetValue(tem_workbook.Worksheets[0][i, 2].Value.ToString());
                                    worksheet_temp[10 * (i - 1) + tempRow, 3].SetValue(date_temp);

                                    worksheet_temp[10 * (i - 1) + tempRow, 4].SetValue(itemStrs[0].Replace("\"", ""));
                                    worksheet_temp[10 * (i - 1) + tempRow, 5].SetValue(itemStrs[1]);
                                    worksheet_temp[10 * (i - 1) + tempRow, 6].SetValue(itemStrs[2]);
                                    worksheet_temp[10 * (i - 1) + tempRow, 7].SetValue(itemStrs[3]);
                                    worksheet_temp[10 * (i - 1) + tempRow, 8].SetValue(itemStrs[4]);
                                    worksheet_temp[10 * (i - 1) + tempRow, 9].SetValue(DateTime.Now);

                                    worksheet_temp[10 * (i - 1) + tempRow, 10].SetValue(tem_workbook.Worksheets[0][i, 4].Value.ToString());
                                    worksheet_temp[10 * (i - 1) + tempRow, 11].SetValue(tem_workbook.Worksheets[0][i, 5].Value.ToString());
                                    worksheet_temp[10 * (i - 1) + tempRow, 12].SetValue(tem_workbook.Worksheets[0][i, 1].Value.ToString());
                                }
                                if (target_datatype == "飞机")
                                {
                                    worksheet_temp[10 * (i - 1) + tempRow, 0].SetValue(10 * (i - 1));
                                    worksheet_temp[10 * (i - 1) + tempRow, 1].SetValue(dataType);
                                    worksheet_temp[10 * (i - 1) + tempRow, 2].SetValue(tem_workbook.Worksheets[0][i, 2].Value.ToString());
                                    worksheet_temp[10 * (i - 1) + tempRow, 3].SetValue(date_temp);

                                    worksheet_temp[10 * (i - 1) + tempRow, 4].SetValue(itemStrs[0].Replace("\"", ""));
                                    worksheet_temp[10 * (i - 1) + tempRow, 5].SetValue(itemStrs[1]);
                                    worksheet_temp[10 * (i - 1) + tempRow, 6].SetValue(itemStrs[2]);

                                    worksheet_temp[10 * (i - 1) + tempRow, 7].SetValue(DateTime.Now);

                                    worksheet_temp[10 * (i - 1) + tempRow, 8].SetValue(tem_workbook.Worksheets[0][i, 4].Value.ToString());
                                    worksheet_temp[10 * (i - 1) + tempRow, 9].SetValue(tem_workbook.Worksheets[0][i, 5].Value.ToString());
                                    worksheet_temp[10 * (i - 1) + tempRow, 10].SetValue(tem_workbook.Worksheets[0][i, 1].Value.ToString());
                                }
                                if (target_datatype == "火车")
                                {
                                    worksheet_temp[10 * (i - 1) + tempRow, 0].SetValue(10 * (i - 1));
                                    worksheet_temp[10 * (i - 1) + tempRow, 1].SetValue(dataType);
                                    worksheet_temp[10 * (i - 1) + tempRow, 2].SetValue(tem_workbook.Worksheets[0][i, 2].Value.ToString());
                                    worksheet_temp[10 * (i - 1) + tempRow, 3].SetValue(date_temp);

                                    worksheet_temp[10 * (i - 1) + tempRow, 4].SetValue(itemStrs[0].Replace("\"", ""));
                                    worksheet_temp[10 * (i - 1) + tempRow, 5].SetValue(itemStrs[1]);
                                    worksheet_temp[10 * (i - 1) + tempRow, 6].SetValue(itemStrs[2]);

                                    worksheet_temp[10 * (i - 1) + tempRow, 7].SetValue(DateTime.Now);

                                    worksheet_temp[10 * (i - 1) + tempRow, 8].SetValue(tem_workbook.Worksheets[0][i, 4].Value.ToString());
                                    worksheet_temp[10 * (i - 1) + tempRow, 9].SetValue(tem_workbook.Worksheets[0][i, 5].Value.ToString());
                                    worksheet_temp[10 * (i - 1) + tempRow, 10].SetValue(tem_workbook.Worksheets[0][i, 1].Value.ToString());
                                }
                                if (target_datatype == "汽车")
                                {
                                    worksheet_temp[10 * (i - 1) + tempRow, 0].SetValue(10 * (i - 1));
                                    worksheet_temp[10 * (i - 1) + tempRow, 1].SetValue(dataType);
                                    worksheet_temp[10 * (i - 1) + tempRow, 2].SetValue(tem_workbook.Worksheets[0][i, 2].Value.ToString());
                                    worksheet_temp[10 * (i - 1) + tempRow, 3].SetValue(date_temp);

                                    worksheet_temp[10 * (i - 1) + tempRow, 4].SetValue(itemStrs[0].Replace("\"", ""));
                                    worksheet_temp[10 * (i - 1) + tempRow, 5].SetValue(itemStrs[1]);
                                    worksheet_temp[10 * (i - 1) + tempRow, 6].SetValue(itemStrs[2]);

                                    worksheet_temp[10 * (i - 1) + tempRow, 7].SetValue(DateTime.Now);

                                    worksheet_temp[10 * (i - 1) + tempRow, 8].SetValue(tem_workbook.Worksheets[0][i, 4].Value.ToString());
                                    worksheet_temp[10 * (i - 1) + tempRow, 9].SetValue(tem_workbook.Worksheets[0][i, 5].Value.ToString());
                                    worksheet_temp[10 * (i - 1) + tempRow, 10].SetValue(tem_workbook.Worksheets[0][i, 1].Value.ToString());
                                }

                                matchResult = matchResult.NextMatch();

                                tempRow++;
                            }
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.Message);
                        }
                    }

                    sum++;
                    RunWithInoke(sum);
                }

                taskExecuted = true;
                workBook_temp.SaveDocument(workbook_temp_path);
            }



            XtraMessageBox.Show("所有信息已经解析完成!");
        }