Open Closed

Localization inside GetListAsExcelFileAsync() method #6667


User avatar
0
icoretchi created
  • ABP Framework version: v8.0.3
  • UI Type: Blazor WASM
  • Database System: EF Core (SQL Server)
    • Tiered (for MVC) or Auth Server Separated (for Angular): microservice
  • Exception message and full stack trace:
  • Steps to reproduce the issue:

Hi,

I am trying to localize the column names of the exported excel file that happend in GetListAsExcelFileAsync() of any generated ApplicationServices. I've noticed that the StringLocalizer L that is inherited from the base ApplicationService is not workig properly in this method for any other language beside the default "en". Any ideas?

Markdown supported.
Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)

9 Answer(s)
  • User Avatar
    0
    liangshiwei created
    Fullstack Developer

    Hi,

    ABP internally uses Miniexcel to export Excel file.

    You need to use dynamic column names to support localization https://github.com/mini-software/MiniExcel?tab=readme-ov-file#7-dynamiccolumnattribute

    for example:

    var config = new OpenXmlConfiguration
    {
        DynamicColumns = new DynamicExcelColumn[] { 
            new DynamicExcelColumn("id") {Name = L["Id"]},
            new DynamicExcelColumn("name") {Name = L["Name"]},
            new DynamicExcelColumn("createdate") {Name = L["Createdate"]},
            new DynamicExcelColumn("point") {Name = L["Point"]},
        }
    };
    
    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
  • User Avatar
    0
    icoretchi created

    I know that. You didn't understand the question. The problem is in L, as StringLocalizer. It's not working properly. Try the example that you suggested to localize the colums for different language beside english.

    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
  • User Avatar
    0
    liangshiwei created
    Fullstack Developer

    Hi,

    Could you share some code? I will check it.

    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
  • User Avatar
    0
    icoretchi created

    Once again. Just try the code you have suggested:

    var config = new OpenXmlConfiguration { DynamicColumns = new DynamicExcelColumn[] { new DynamicExcelColumn("id") {Name = L["Id"]}, new DynamicExcelColumn("name") {Name = L["Name"]}, new DynamicExcelColumn("createdate") {Name = L["Createdate"]}, new DynamicExcelColumn("point") {Name = L["Point"]}, } };

    I am doing absolutly the same.

    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
  • User Avatar
    0
    liangshiwei created
    Fullstack Developer

    Hi,

    This is a problem, You can open the AppService.Extended.cs class to update the LocalizationResource

    We will enhance the suite in the next version, your ticket was refunded.

    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
  • User Avatar
    0
    icoretchi created

    In my context the LocalizationResource is properly assigned for the Application Service and localization for exporting to excel it's not working. And I have to mention that for microservices template all the application services are inherited from the base class which properly assign the LocalizationResource. I think the problem is in this specific method GetListAsExcelFileAsync() how is called from UI (in my case from Blazor). I reiterate again the L, as StringLocalizer is working properly from any method of the ApplicationService, besides the GetListAsExcelFileAsync.

    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
  • User Avatar
    0
    liangshiwei created
    Fullstack Developer

    Hi,

    Sorry, I can confirm this issue. we will fix it.

    You can try to update the DownloadAsExcelAsync method. for example:

    private  async Task DownloadAsExcelAsync()
    {
        var token = (await BooksAppService.GetDownloadTokenAsync()).Token;
        var remoteService = await RemoteServiceConfigurationProvider.GetConfigurationOrDefaultOrNullAsync("Qa") ??
        await RemoteServiceConfigurationProvider.GetConfigurationOrDefaultOrNullAsync("Default");
        var currentCulture = CultureInfo.CurrentUICulture.Name ?? CultureInfo.CurrentCulture.Name;
        if(!currentCulture.IsNullOrEmpty())
        {
            currentCulture = "&culture=" + currentCulture;
        }
        NavigationManager.NavigateTo($"{remoteService?.BaseUrl.EnsureEndsWith('/') ?? string.Empty}api/app/books/as-excel-file?DownloadToken={token}&FilterText={Filter.FilterText}&Name={Filter.Name}&Title={Filter.Title}{currentCulture}", forceLoad: true);
    }
    
    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
  • User Avatar
    0
    icoretchi created

    It's still not working properly.

    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
  • User Avatar
    0
    liangshiwei created
    Fullstack Developer

    I could not reproduce the problem

    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
Boost Your Development
ABP Live Training
Packages
See Trainings
Mastering ABP Framework Book
The Official Guide
Mastering
ABP Framework
Learn More
Mastering ABP Framework Book
Made with ❤️ on ABP v10.8.0-preview. Updated on September 16, 2026, 14:50
1
ABP Assistant
🔐 You need to be logged in to use the chatbot. Please log in first.