如何在 Acumatica 框架上创建 Excel 报告?

How can I create an Excel report on Acumatica Framework?

我正在尝试使用自定义按钮创建包含页面信息的 Excel 文档。 Excel 文档应该打开,然后由用户保存它 - 与使用嵌入在某些 Acumatica 网格中的导出到 Excel 按钮所做的类似。

我阅读了 篇文章,其中要求类似内容。但是,添加对象 new PX.Export.Excel.Core.Package() 失败,因为无法识别库。也许这在最新版本中已被弃用?

我创建了这个控制台项目

using Excel = Microsoft.Office.Interop.Excel;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            var excelApp = new Excel.Application();
            // Make the object visible.
            excelApp.Visible = true; ;

            // Create a new, empty workbook and add it to the collection returned 
            // by property Workbooks. The new workbook becomes the active workbook.
            // Add has an optional parameter for specifying a praticular template. 
            // Because no argument is sent in this example, Add creates a new workbook. 
            excelApp.Workbooks.Add();

            excelApp.Cells[1, "A"] = "SNO";
            excelApp.Cells[2, "B"] = "A";
            excelApp.Cells[2, "C"] = "1122";

            Excel._Worksheet workSheet = (Excel.Worksheet)excelApp.ActiveSheet;
        }
    }
}

并且工作正常。但是在 Acumatica 中我收到以下错误

Retrieving the COM class factory for component with CLSID
{00024500-0000-0000-C000-000000000046} failed due to the 
following error: 80070005 Access is denied.
(Exception from HRESULT: 0x80070005 (E_ACCESSDENIED)).

谢谢。

您需要在扩展库中添加 PX.Export.dll 的引用(来自 AcumaticaSite -> Bin 文件夹)才能使用 PX.Export.Excel.Core.Package()