https://pastein.ru/t/nyH

  скопируйте уникальную ссылку для отправки


/// <summary>
        /// ListAutoButtonOnClick
        /// </summary>
        /// <param name="portlet"></param>
        public virtual void UploadToExcelOnClick(PortletContentViewModel<TransportApplications.Content, TransportApplications.Personalization> portlet)
        {
            var allLogisticRequestInFilter = EntityManager<LogisticRequest>.Instance.Find(portlet.Context.EQLString);
            Workbook workbook = new Workbook();
            //int i = workbook.Worksheets.Add();
            Worksheet worksheet = workbook.Worksheets[0];
            // 0 - FullName
            int row = 0;
            List<string> arrayLogisticRequest = new List<string>();
            arrayLogisticRequest.AddRange(new List<string>() { "Номер заявки", "Название", "Статус", "Крайний срок доставки", "Отправитель", "Получатель", "Автор заявки", "Менеджер по логистике", "Сумма", "Проект" });
            AddRow(arrayLogisticRequest, ref worksheet, ref row);
            foreach (var item in allLogisticRequestInFilter)
            {
                arrayLogisticRequest.Clear();
                arrayLogisticRequest.Add(item.RequestNumber.HasValue ? item.RequestNumber.ToString() : "");
                arrayLogisticRequest.Add(item.Name);
                arrayLogisticRequest.Add(item.Status != null ? item.Status.Name : "");
                arrayLogisticRequest.Add(item.DeadlineDeliveryDate.HasValue ? item.DeadlineDeliveryDate.Value.ToShortDateString() : "");
                arrayLogisticRequest.Add(item.SenderOrganization != null ? item.SenderOrganization.Name : "");
                arrayLogisticRequest.Add(item.RecipientOrganization != null ? item.RecipientOrganization.Name : "");
                arrayLogisticRequest.Add(item.ApplicationAuthor != null ? item.ApplicationAuthor.FullName : "");
                arrayLogisticRequest.Add(item.LogisticManager != null ? item.LogisticManager.FullName : "");
                arrayLogisticRequest.Add(item.Sum.HasValue ? item.Sum.Value.ToString() : "");
                arrayLogisticRequest.Add(item.Project != null ? item.Project.Name : "");

                if (arrayLogisticRequest.Any())
                {
                    AddRow(arrayLogisticRequest, ref worksheet, ref row);
                }
            }
            worksheet.AutoFitRows();
            worksheet.AutoFitColumns();
            var tmpFilePath = System.IO.Path.GetTempFileName() + ".xlsx";
            workbook.Save(tmpFilePath);
            var file = InterfaceActivator.Create<BinaryFile>();
            file.Name = "Заявки на логистику.xlsx";
            file.CreateDate = DateTime.Now;
            file.ContentFilePath = tmpFilePath;
            Locator.GetServiceNotNull<IFileManager>().SaveFile(file);
            portlet.Context.Unloading = new HtmlString(string.Format("<a href=\"/SDK.Action/BinaryFiles/Download/{0}\" target=\"_blank\">{1}</a>",
                file.Uid.ToString(), file.Name));
        }

        public virtual void AddRow(List<string> arrayAuto, ref Worksheet worksheet, ref int row)
        {
            worksheet.Cells.ImportArray(arrayAuto.ToArray(), row, 0, false);
            row++;
        }