如何在Acumatica Framework上创建Excel报告?

时间:2018-08-03 14:08:37

标签: c# excel export report acumatica

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

我阅读了this文章,其中要求类似内容。但是,添加对象 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)).

谢谢。

1 个答案:

答案 0 :(得分:1)

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