Base solution for your next web application
Ends in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

Excel Download File Contains Only Heading Row #9935


User avatar
0
schlarmanp created

Prerequisites

Please answer the following questions before submitting an issue. YOU MAY DELETE THE PREREQUISITES SECTION.

  • What is your product version? 6.9.0
  • What is your product type (Angular or MVC)? Angular
  • What is product framework type (.net framework or .net core)? Core

If issue related with ABP Framework

  • What is ABP Framework version?

If issue is about UI

  • Which theme are you using?
  • What are the theme settings?

Using the standard generated methods for exporting a grid to Excel, my users are frequently finding when they open the Excel file, it only contains the heading. What might be the cause here and how can I make the full file download consistently?


4 Answer(s)
  • User Avatar
    0
    zony created
    Support Team

    Hi schlarmanp, Can you provide relevant code snippets for export?

  • User Avatar
    0
    schlarmanp created

    Here is the API-side method:

    		public async Task<FileDto> GetJournalVoucherTransactionsToExcel(GetAllJournalVoucherTransactionsForExcelInput input)
             {
    			
    			var filteredJournalVoucherTransactions = _journalVoucherTransactionRepository.GetAll()
    						.WhereIf(!string.IsNullOrWhiteSpace(input.Filter), e => false  || e.CostpointProjectCode.Contains(input.Filter) || e.CostpointAccountNumber.Contains(input.Filter) || e.AccountAbbreviation.Contains(input.Filter) || e.CostpointOrganizationCode.Contains(input.Filter) || e.TransactionDescription.Contains(input.Filter) || e.TransactionNotes.Contains(input.Filter) || e.CostpointEmployeeNumber.Contains(input.Filter) || e.ProblemCodes.Contains(input.Filter) || e.TransactionState.Contains(input.Filter))
    						.WhereIf(input.MinLineNumberFilter != null, e => e.LineNumber >= input.MinLineNumberFilter)
    						.WhereIf(input.MaxLineNumberFilter != null, e => e.LineNumber <= input.MaxLineNumberFilter)
    						.WhereIf(!string.IsNullOrWhiteSpace(input.CostpointProjectCodeFilter),  e => e.CostpointProjectCode.ToLower() == input.CostpointProjectCodeFilter.ToLower().Trim())
    						.WhereIf(!string.IsNullOrWhiteSpace(input.CostpointAccountNumberFilter),  e => e.CostpointAccountNumber.ToLower() == input.CostpointAccountNumberFilter.ToLower().Trim())
    						.WhereIf(!string.IsNullOrWhiteSpace(input.AccountAbbreviationFilter),  e => e.AccountAbbreviation.ToLower() == input.AccountAbbreviationFilter.ToLower().Trim())
    						.WhereIf(!string.IsNullOrWhiteSpace(input.CostpointOrganizationCodeFilter),  e => e.CostpointOrganizationCode.ToLower() == input.CostpointOrganizationCodeFilter.ToLower().Trim())
    						.WhereIf(input.MinTransactionAmountUSDFilter != null, e => e.TransactionAmountUSD >= input.MinTransactionAmountUSDFilter)
    						.WhereIf(input.MaxTransactionAmountUSDFilter != null, e => e.TransactionAmountUSD <= input.MaxTransactionAmountUSDFilter)
    						.WhereIf(!string.IsNullOrWhiteSpace(input.TransactionDescriptionFilter),  e => e.TransactionDescription.ToLower() == input.TransactionDescriptionFilter.ToLower().Trim())
    						.WhereIf(!string.IsNullOrWhiteSpace(input.TransactionNotesFilter),  e => e.TransactionNotes.ToLower() == input.TransactionNotesFilter.ToLower().Trim())
    						.WhereIf(!string.IsNullOrWhiteSpace(input.CostpointEmployeeNumberFilter),  e => e.CostpointEmployeeNumber.ToLower() == input.CostpointEmployeeNumberFilter.ToLower().Trim())
    						.WhereIf(input.MinHoursFilter != null, e => e.Hours >= input.MinHoursFilter)
    						.WhereIf(input.MaxHoursFilter != null, e => e.Hours <= input.MaxHoursFilter)
    						.WhereIf(!string.IsNullOrWhiteSpace(input.ProblemCodesFilter),  e => e.ProblemCodes.ToLower() == input.ProblemCodesFilter.ToLower().Trim())
    						.WhereIf(input.MinJournalVoucherIDFilter != null, e => e.JournalVoucherID >= input.MinJournalVoucherIDFilter)
    						.WhereIf(input.MaxJournalVoucherIDFilter != null, e => e.JournalVoucherID <= input.MaxJournalVoucherIDFilter)
    						.WhereIf(!string.IsNullOrWhiteSpace(input.TransactionStateFilter),  e => e.TransactionState.ToLower() == input.TransactionStateFilter.ToLower().Trim());
    
    			var query = (from o in filteredJournalVoucherTransactions
                             select new GetJournalVoucherTransactionForViewDto() { 
    							JournalVoucherTransaction = new JournalVoucherTransactionDto
    							{
                                    LineNumber = o.LineNumber,
                                    CostpointProjectCode = o.CostpointProjectCode,
                                    CostpointAccountNumber = o.CostpointAccountNumber,
                                    AccountAbbreviation = o.AccountAbbreviation,
                                    CostpointOrganizationCode = o.CostpointOrganizationCode,
                                    TransactionAmountUSD = o.TransactionAmountUSD,
                                    TransactionDescription = o.TransactionDescription,
                                    TransactionNotes = o.TransactionNotes,
                                    CostpointEmployeeNumber = o.CostpointEmployeeNumber,
                                    Hours = o.Hours,
                                    ProblemCodes = o.ProblemCodes,
                                    JournalVoucherID = o.JournalVoucherID,
                                    TransactionState = o.TransactionState,
                                    Id = o.Id
    							}
    						 });
    
    
                var journalVoucherTransactionListDtos = await query.ToListAsync();
    
                return _journalVoucherTransactionsExcelExporter.ExportToFile(journalVoucherTransactionListDtos);
             }
    

    Here is the angular call:

        async exportToExcelTransactions() {
    
            //inform user
            this.notify.info(this.l('Excel file generation initiated...'));
    
            //changed this to wait for result instead of using subscribe - 
            //will hopefully solve problem of downloaded files sometimes being empty.
            var resultFile = await this._journalVoucherTransactionsServiceProxy.getJournalVoucherTransactionsToExcel(
                this.filterText,
                this.maxLineNumberFilter == null ? this.maxLineNumberFilterEmpty: this.maxLineNumberFilter,
                this.minLineNumberFilter == null ? this.minLineNumberFilterEmpty: this.minLineNumberFilter,
                this.costpointProjectCodeFilter,
                this.costpointAccountNumberFilter,
                this.accountAbbreviationFilter,
                this.costpointOrganizationCodeFilter,
                this.maxTransactionAmountUSDFilter == null ? this.maxTransactionAmountUSDFilterEmpty: this.maxTransactionAmountUSDFilter,
                this.minTransactionAmountUSDFilter == null ? this.minTransactionAmountUSDFilterEmpty: this.minTransactionAmountUSDFilter,
                this.transactionDescriptionFilter,
                this.transactionNotesFilter,
                this.costpointEmployeeNumberFilter,
                this.maxHoursFilter == null ? this.maxHoursFilterEmpty: this.maxHoursFilter,
                this.minHoursFilter == null ? this.minHoursFilterEmpty: this.minHoursFilter,
                this.problemCodesFilter,
                this.journalVoucherIdFilter == null ? this.maxJournalVoucherIDFilterEmpty: this.journalVoucherIdFilter,
                this.journalVoucherIdFilter == null ? this.minJournalVoucherIDFilterEmpty: this.journalVoucherIdFilter,
                this.transactionStateFilter
            ).toPromise();
    
            //wait a couple secs before downloading
            await this.delay(4000); //4 seconds
    
            //inform user
            this.notify.success(this.l('Excel file download starting...'));
    
            //download Excel file
            this._fileDownloadService.downloadTempFile(resultFile);
    
            //return promise to notify caller
            return new Promise(resolve => {
                resolve(resultFile);
              });
    
        }
    

    And this is the HTML:

    																<button 
    																	(click)="exportToExcelTransactions()" 
    																	class="btn btn-outline-success">
    																	<i class="fa fa-file-excel"></i> {{l("ExportToExcel")}}
    																</button>
    

    If the user requests hard refresh of page in Chrome (CTRL + F5), the file downloads completely, otherwise in normal usage, many users are consistently only receiving the header row in the downloaded spreadsheet.

    Thoughts?

  • User Avatar
    0
    schlarmanp created

    HTML:

    <button (click)="exportToExcelTransactions()" class="btn btn-outline-success"> <i class="fa fa-file-excel"></i> {{l("ExportToExcel")}} </button>

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    We had problems with EPPlus and moved to NPOI library in this PR https://github.com/aspnetzero/aspnet-zero-core/pull/3057/files. Could you try this on your version as well ?