Beispiel #1
0
        //T: Convert to explicit operator
        public MarketplaceItem ConvertToItem()
        {
            var             currency = sell_price_text.Except((sell_price / 100.0).ToString() + ' ').FirstOrDefault();
            MarketplaceItem item     = new MarketplaceItem(
                name,
                name.Substring(name.Length - 6),
                asset_description?.name_color,
                sell_listings,
                sell_price / 100.0,
                currency
                );

            return(item);
        }
Beispiel #2
0
        //TODO: Delegate convertation to item method.
        //TODO: Catch "Too many requests", add timeout and try again.
        public static void ObjToExcel(MarketplaceList items, bool open = false)
        {
            Console.WriteLine("Creating xlsx file. This can take a while.");
            XLWorkbook   workbook  = new XLWorkbook();
            IXLWorksheet worksheet = workbook.Worksheets.Add("Coins");

            worksheet.Cell(1, 1).Value = "Link";
            worksheet.Cell(1, 2).Value = "Name";
            worksheet.Cell(1, 3).Value = "Code";
            worksheet.Cell(1, 4).Value = "Color";
            worksheet.Cell(1, 5).Value = "Amount";
            worksheet.Cell(1, 6).Value = "Price";

            worksheet.Cells(true).Style.Font.SetBold();

            for (int i = 0; i < items.Count; i++)
            {
                MarketplaceItem item = items[i];

                worksheet.Cell(i + 2, 1).Hyperlink = new XLHyperlink(@item.Link);
                worksheet.Cell(i + 2, 1).Value     = @item.Link;
                worksheet.Cell(i + 2, 2).Value     = item.Name;
                worksheet.Cell(i + 2, 3).Value     = item.Code;
                worksheet.Cell(i + 2, 4).Value     = item.ColorStr;
                worksheet.Cell(i + 2, 4).Style.Fill.BackgroundColor = XLColor.FromArgb(item.ColorHex);
                worksheet.Cell(i + 2, 5).Value = item.Amount;
                worksheet.Cell(i + 2, 6).Value = item.Price;
                worksheet.Cell(i + 2, 6).Style.NumberFormat.Format = "0.00" + item.PriceCurrency;
            }

            worksheet.Columns(2, 6).AdjustToContents(10.0, 40.0);

            DateTime current = DateTime.Now;

            string saveLocation = SaveFolder + current.ToString("yyyy.MM.dd HH.mm.ss") + ".xlsx";

            Console.WriteLine("Saving your file to {0}", saveLocation);
            workbook.SaveAs(@saveLocation);

            if (open)
            {
                string           path  = Path.Combine(Environment.CurrentDirectory, saveLocation);
                ProcessStartInfo pInfo = new ProcessStartInfo(saveLocation)
                {
                    UseShellExecute = true
                };
                Process.Start(pInfo);
            }
        }