web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Export dates to excel file

(0) ShareShare
ReportReport
Posted on by 1,470

Hi to all!

I've created a file excel from Dynamics AX 2012.

In the file I have a date (DeliveryDate). I want to format the date depend on the language of the vendor, for which the excel is created.

At the moment I use the following code:

System.Globalization.DateTimeFormatInfo myDateTimeInfo = System.Globalization.DateTimeFormatInfo::get_CurrentInfo();

cells.range('M:O').numberFormat(myDateTimeInfo.get_ShortDatePattern());

But the result, in the excel file is: dd.07/yyyy

For info: the delivery date is 16.07.2015 and the language of the customer is German.

Any ideas?

Thanks

*This post is locked for comments

I have the same question (0)
  • Martina Bergamo Profile Picture
    1,470 on at

    Ok, I've resolved my problem...I've inserted the short date pattern in a string...

    str format = myDateTimeInfo.get_ShortDatePattern();
    cells.range('M:O').numberFormat(format);


     But, now, when I open the excel file, I see this:

    Aufnahme1.png

    I want only the date, without the time...

    Any ideas?

  • Suggested answer
    Community Member Profile Picture
    on at

    When you are assigning a value to an Excel cell (I presume that you're using SysExcelCells.item(..).value(<myDate>)), don't pass is as the date value, but convert it to a string (a simple strFmt("%1", <myDate>) will do).

  • Verified answer
    Martina Bergamo Profile Picture
    1,470 on at

    Texcel.png"/api/data/v9.1/msdyn_richtextfiles(843A4930-6B6E-4E84-B375-1026ACEE2AA3)/msdyn_imageblob/$value?size=full">

    static void exportExcelFile(Args _args)
    {
        SysExcelApplication     xlsApplication;
        SysExcelWorkBooks       xlsWorkBookCollection;
        SysExcelWorkBook        xlsWorkBook;
        SysExcelWorkSheets      xlsWorkSheetCollection;
        SysExcelWorkSheet       xlsWorkSheet;
        SysExcelWorksheetHelper worksheetHelper;
        SysExcelHelper          sysExcelHelper;
        VendRFQJour             vendRFQJour;
        int                     row = 1;
        str                     fileName;
        str                     worksheetName;
        Date                    deliveryDate;
    
        fileName    = "C:\\path\\Test.xlsx";
    
        vendRFQJour = VendRFQJour::find("000103");
    
        worksheetName = strfmt("%1", date2str(systemdateget(),321,DateDay::Digits2,DateSeparator::None,DateMonth::Digits2,DateSeparator::None,DateYear::Digits4, DateFlags::None));
        sysExcelHelper = SysExcelHelper::construct();
        sysExcelHelper.initialize();
        xlsWorkSheet = sysExcelHelper.addWorksheet(worksheetName);
    
        worksheetHelper = SysExcelWorksheetHelper::construct(xlsWorkSheet);
    
        worksheetHelper.addColumn(1, 'RFQ Id', Types::String);
        worksheetHelper.addColumn(2, 'Delivery date', Types::Date);
    
        worksheetHelper.setCellValue(1, row, 'RFQId');
        worksheetHelper.setCellValue(2, row, 'DeliveryDate');
        row++;
    
        worksheetHelper.setCellValue(1, row, vendRFQJour.RFQId);
        worksheetHelper.setCellValue(2, row, vendRFQJour.DeliveryDate);
    
        if(WinApi::fileExists(fileName))
            WinApi::deleteFile(fileName);
    
        sysExcelHelper.save(filename);
        sysExcelHelper.close();
    
        info(strFmt("Creato file: %1", fileName));
    }


    The method SysExcelWorksheethelper.addColumn, add a column to the excel file, aligns and formats the column based on the type.

    Martina

  • Community Member Profile Picture
    on at

    You will get a date value even when you pass the date as a string, because your column is already formatted as date by using the .numberformat() method.

    I've tried that directly with SysExcelCells class (not through Helper) and it works - it sets normal date value, so all filtering/sorting/etc. works properly.

  • JL Aguilera Profile Picture
    68 on at

    You can try format date before set value on the cell.

    for example;

    ExcelHelper.setValue(row,5,date2str(custtrans.TransDate,321, 2, 3, 2, 3, 4));

    //return 11/10/2019

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Joris dG Profile Picture

Joris dG 5

#2
Andrew Jones a1x Profile Picture

Andrew Jones a1x 2

#3
GL-01081504-0 Profile Picture

GL-01081504-0 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans