Search code examples
c#devexpressfilemerge

how do i merge excel files with devexpress


I trying to merge two Excel files with Devexpress library. I don't have any errors but there isn't happening anything. Debug also looking good. I can see sheet names etc.

I use this manual to merge files.

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

No one working.

xlsx documents are placed in bin\Debug folder. Sheets contains Sheet1 where are different data

Code

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);


        }
    }
}

Solution

  • I think you need to use the SaveDocument method to actually persist your changes to the physical file. You should be invoking book2.SaveDocument("Text2.xlsx") to accomplish this.