Autosize collum after export to excel

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
6 anni tempo fa
Hello!
I add a new service with implementing IExportmanager and create new excel export.
So its look like :


namespace Nop.Plugin.ShoppingCart.BackInStockSubscription.Services
{
    public class ExportManagerBackInStockSubscription : ExportManager, IExportManagerBackInStockSubscription
    {
        private readonly ICategoryService _categoryService;
        private readonly IManufacturerService _manufacturerService;
        private readonly ICustomerService _customerService;
        private readonly IProductAttributeService _productAttributeService;
        private readonly IPictureService _pictureService;
        private readonly INewsLetterSubscriptionService _newsLetterSubscriptionService;
        private readonly IStoreService _storeService;
        private readonly IWorkContext _workContext;
        private readonly ProductEditorSettings _productEditorSettings;
        private readonly IVendorService _vendorService;
        private readonly IProductTemplateService _productTemplateService;
        private readonly IDateRangeService _dateRangeService;
        private readonly ITaxCategoryService _taxCategoryService;
        private readonly IMeasureService _measureService;
        private readonly CatalogSettings _catalogSettings;
        private readonly IGenericAttributeService _genericAttributeService;
        private readonly ICustomerAttributeFormatter _customerAttributeFormatter;
        private readonly OrderSettings _orderSettings;
        private readonly ILocalizationService _locatlizationService;

        public ExportManagerBackInStockSubscription(ICategoryService categoryService,
            IManufacturerService manufacturerService,
            ICustomerService customerService,
            IProductAttributeService productAttributeService,
            IPictureService pictureService,
            INewsLetterSubscriptionService newsLetterSubscriptionService,
            IStoreService storeService,
            IWorkContext workContext,
            ProductEditorSettings productEditorSettings,
            IVendorService vendorService,
            IProductTemplateService productTemplateService,
            IDateRangeService dateRangeService,
            ITaxCategoryService taxCategoryService,
            IMeasureService measureService,
            CatalogSettings catalogSettings,
            IGenericAttributeService genericAttributeService,
            ICustomerAttributeFormatter customerAttributeFormatter,
            OrderSettings orderSettings,
            ILocalizationService locatlizationService)
            
            : base(categoryService, manufacturerService, customerService, productAttributeService, pictureService, newsLetterSubscriptionService, storeService,
              workContext, productEditorSettings, vendorService, productTemplateService, dateRangeService, taxCategoryService,
              measureService, catalogSettings, genericAttributeService, customerAttributeFormatter, orderSettings)
        {
            this._categoryService = categoryService;
            this._manufacturerService = manufacturerService;
            this._customerService = customerService;
            this._productAttributeService = productAttributeService;
            this._pictureService = pictureService;
            this._newsLetterSubscriptionService = newsLetterSubscriptionService;
            this._storeService = storeService;
            this._workContext = workContext;
            this._productEditorSettings = productEditorSettings;
            this._vendorService = vendorService;
            this._productTemplateService = productTemplateService;
            this._dateRangeService = dateRangeService;
            this._taxCategoryService = taxCategoryService;
            this._measureService = measureService;
            this._catalogSettings = catalogSettings;
            this._genericAttributeService = genericAttributeService;
            this._customerAttributeFormatter = customerAttributeFormatter;
            this._orderSettings = orderSettings;
            this._locatlizationService = locatlizationService;
        }

        public byte[] ExportBackInStockSubscriptionToXlsx(IEnumerable<BackInStockSubscriptionModel> records)
        {
            //property array
            var properties = new[]
            {
                new PropertyByName<BackInStockSubscriptionModel>(_locatlizationService.GetResource("Plugins.ShoppingCart.BackInStockSubsription.Customer"), p => p.Customer),
                new PropertyByName<BackInStockSubscriptionModel>(_locatlizationService.GetResource("Plugins.ShoppingCart.BackInStockSubsription.Email"), p => p.Email),
                new PropertyByName<BackInStockSubscriptionModel>(_locatlizationService.GetResource("Plugins.ShoppingCart.BackInStockSubsription.SKU"), p => p.SKU),
                new PropertyByName<BackInStockSubscriptionModel>(_locatlizationService.GetResource("Plugins.ShoppingCart.BackInStockSubsription.ProductName"), p => p.ProductName),
                new PropertyByName<BackInStockSubscriptionModel>(_locatlizationService.GetResource("Plugins.ShoppingCart.BackInStockSubsription.Qty"), p => p.Qty),
                new PropertyByName<BackInStockSubscriptionModel>(_locatlizationService.GetResource("Plugins.ShoppingCart.BackInStockSubsription.CreatedDateTime"), p => p.CreatedOn.ToString("G"))
            };
            return ExportToXlsx(properties, records);
        }
    }
}




So my question is how to make collums autosize?
In exporting via the com - u can send to make autofit() method.
https://msdn.microsoft.com/en-us/vba/excel-vba/articles/range-autofit-method-excel
6 anni tempo fa
nopCommerce uses EPPlus.  Maybe this will help you
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.