// Заполняем лист со списком ценных бумаг public void ribbon_btnMarketListClicked() { if ((this.Application != null) && (this.Application.ActiveWorkbook != null)) { // Проверяем наличие нужного листа Excel.Worksheet ExcelListSheet = MSExcel.GetExcelSheet(this.Application.ActiveWorkbook, ExcelListName, sh => { }); if (ExcelListSheet == null) { // лист не найден - добавляем ExcelListSheet = (Excel.Worksheet) this.Application.ActiveWorkbook.Sheets.Add(); ExcelListSheet.Name = ExcelListName; } if (ExcelListSheet != null) { // заполняем лист int _count = 0; ExcelListSheet.Activate(); ExcelListSheet.Cells.ClearContents(); // заголовок _count++; ExcelListSheet.Cells[_count, ExcelList_columnTicker] = "Ticker"; ExcelListSheet.Cells[_count, 2] = "Type"; ExcelListSheet.Cells[_count, 3] = "Name"; ExcelListSheet.Cells[_count, 4] = "Lot"; ExcelListSheet.Cells[_count, 5] = "Currency"; ExcelListSheet.Cells[_count, ExcelList_columnValuteCurs] = "ValuteCurs"; this.Application.StatusBar = "Загружаем курсы валют"; LoadValuteCurs().GetAwaiter().GetResult(); this.Application.StatusBar = $"Заполняем список валют на листе {ExcelListName}"; // валюты if ((Currencies != null) && (Currencies.status == "Ok") && (Currencies.payload != null) && (Currencies.payload.instruments != null)) { foreach (var item in Currencies.payload.instruments) { if (item.ticker != "") { _count++; ExcelListSheet.Cells[_count, ExcelList_columnTicker] = item.ticker; ExcelListSheet.Cells[_count, 2] = item.InstrumentTypeName; ExcelListSheet.Cells[_count, 3] = item.name; ExcelListSheet.Cells[_count, 4] = item.lot; ExcelListSheet.Cells[_count, 5] = item.currency; ExcelListSheet.Cells[_count, ExcelList_columnValuteCurs] = item.ValuteCurs; } } } this.Application.StatusBar = "Загружаем список ценных бумаг"; //-V3008 LoadMarket().GetAwaiter().GetResult(); this.Application.StatusBar = $"Заполняем список ценных бумаг на листе {ExcelListName}"; // ценные бумаги if (ListPapers != null) { foreach (var item in ListPapers) { _count++; ExcelListSheet.Cells[_count, ExcelList_columnTicker] = item.ticker; ExcelListSheet.Cells[_count, 2] = item.InstrumentTypeName; ExcelListSheet.Cells[_count, 3] = item.name; ExcelListSheet.Cells[_count, 4] = item.lot; ExcelListSheet.Cells[_count, 5] = item.currency; } } // оформляем int max_columns = ExcelListSheet.UsedRange.Columns.Count; int max_rows = ExcelListSheet.UsedRange.Rows.Count; MSExcel.RangeAutoFit(ExcelListSheet.Cells); MSExcel.RangeAutoFilter(ExcelListSheet.Cells); MSExcel.RangeBold((Excel.Range)ExcelListSheet.Range[ExcelListSheet.Cells[1, 1], ExcelListSheet.Cells[1, max_columns]], true); MSExcel.RangeBorder((Excel.Range)ExcelListSheet.Range[ExcelListSheet.Cells[1, 1], ExcelListSheet.Cells[max_rows, max_columns]]); } } if (this.Application != null) { this.Application.StatusBar = false; } }