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 to Excel Range

(0) ShareShare
ReportReport
Posted on by

I have been successfully exporting data to Excel using X++, but I am concerned about the performance. 

The data is being written to each cell one at a time, but I would like to switch to setting a range of values at once.

Does anyone know the proper syntax for this? I have tried a variety of possibilities, but I think that what I am missing is the ability to pass a 2D array to the proper Excel function. 

using System.IO;
using OfficeOpenXml;
using OfficeOpenXml.Style;
using OfficeOpenXml.Table;

class ExcelTest
{
public static void main(Args args)
{
System.IO.MemoryStream memoryStream = new MemoryStream();
var package = new ExcelPackage(memoryStream);
var worksheets = package.get_Workbook().get_Worksheets();
OfficeOpenXml.ExcelWorksheet Worksheet = worksheets.Add("Export");
OfficeOpenXml.ExcelRange cells = Worksheet.get_Cells();
OfficeOpenXml.ExcelRange cell;
OfficeOpenXml.ExcelRange range;
var currentRow = 1;
;

cell = cells.get_Item(currentRow, 1);
System.String value = "Title";
cell.set_Value(value); // This works
currentRow++;

// next part tries to send an array, but it doesn't work. Instead the cells are all filled with "System.String[]"

System.String[] strArray = new System.String[9]();
strArray.SetValue("Col1",0);
strArray.SetValue("Col2",1);
strArray.SetValue("Col3",2);
strArray.SetValue("Col4",3);
range = Cells.get_Item(strfmt("A%1:D%1",currentRow));
range.set_Value(strArray);
currentRow++;

package.Save();
file::SendFileToUser(memoryStream, 'Test.xlsx');
}

}

I believe the problem is that the range.setValue() function requires a 2D array (Excel RangeValueDataType), and I cannot figure out the correct syntax to pass. Alternatively if anyone can point to an example of Microsoft exporting in bulk in the standard code, that would be great.

*This post is locked for comments

I have the same question (0)
  • André Arnaud de Calavon Profile Picture
    304,553 Super User 2026 Season 1 on at

    Hi Tom,

    Microsoft is using SSIS packages for reading from and writing data to Excel in combination with Data import export framework. This is really fast.

  • Suggested answer
    Mea_ Profile Picture
    60,286 on at

    Hi Tom Zak2,

    Try LoadFromCollection() method on the range as proposed here stackoverflow.com/.../epplus-add-values-to-a-range-of-cells

  • Rustem Galiamov Profile Picture
    8,072 on at

    Hi Tom Zak2!

    Did you solve the issue?

  • Tom Zak2 Profile Picture
    on at

    So far, I have been unable to solve the issue with the proposed solution of using range.loadfromCollection() and code like:

    var vals = new string[] { "value1", "value2", "value3" };
    var rng = sheet.Cells["A1:A3"];
    
    rng.LoadFromCollection(vals);

    In X++ the LoadFromCollection() requires me to pass in a parameter of type "System.Collections.Generic.IEnumerable`1[T]Collection" and I have so far been unable to format that data to match that data type.

  • Mea_ Profile Picture
    60,286 on at

    Just declare any .Net collection, like array and use it. You can mix c sharp code with x++.

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
CP04-islander Profile Picture

CP04-islander 39

#2
Michel ROY Profile Picture

Michel ROY 14

#3
imran ul haq Profile Picture

imran ul haq 8

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans