我如何将 excel 个文件与 devexpress 合并

how do i merge excel files with devexpress

我试图将两个 Excel 文件与 Devexpress 库合并。我没有任何错误,但没有发生任何事情。调试也很好看。我可以看到 sheet 个名字等等

我用这个手册来合并文件

https://docs.devexpress.com/OfficeFileAPI/120383/spreadsheet-document-api/examples/workbooks/how-to-merge-multiple-workbooks-into-one-document

没有人工作。

xlsx 文件放在 bin\Debug 文件夹中。工作表包含 Sheet1,其中有不同的数据

代码

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Data.OleDb;
using DevExpress.Spreadsheet;
using System.Drawing;
using DevExpress.XtraSpreadsheet;
using DevExpress.Docs;

namespace Merge_Files
{
    class Program
    {
        static void Main(string[] args)
        {
            // Create the first workbook.
            Workbook book1 = new Workbook();
            book1.LoadDocument("Test1.xlsx", DocumentFormat.Xlsx);

            // Create the second workbook.
            Workbook book2 = new Workbook();
            book2.LoadDocument("Test2.xlsx", DocumentFormat.Xlsx);

            // Copy all worksheets from "Document1" to "Document2".
            book2.Append(book1);


        }
    }
}

我认为您需要使用 SaveDocument 方法来实际保存对物理文件的更改。您应该调用 book2.SaveDocument("Text2.xlsx") 来完成此操作。