Spire.Doc is a professional Word .NET library specifically designed for developers to create, read, write, convert and print Word document files. Get free and professional technical support for Spire.Doc for .NET, Java, Android, C++, Python.

Wed Oct 12, 2022 7:40 am

Hi.

I want to copy and paste sheet of excel into Doc.

I tried to solve this problem by referring to the document in this URL.
https://www.e-iceblue.com/Tutorials/Spi ... -in-C.html

But it didn't work out as I expected.

Page 1 of the attached Doc file is the page that opened the Excel, copied directly, and pasted into the word.
Page 2 is a page attempted through the method of the document URL.

Is there a way to paste the sheet of the attached Excel file while keeping the style like page 1 of doc?

Sungkyu_min
 
Posts: 36
Joined: Fri Jan 07, 2022 5:53 am

Wed Oct 12, 2022 10:02 am

Hello,

Thanks for your inquiry.
You can use the following code to achieve your requirement.
If you have any issue, just feel free to contact us.

Code: Select all
  Workbook workbook = new Workbook();
            workbook.LoadFromFile(@"../../data/om.xlsx");
            MemoryStream ms = new MemoryStream();
            workbook.Worksheets[0].SaveToPdfStream(ms);

            PdfDocument pdf = new PdfDocument();

            pdf.LoadFromStream(ms);

            pdf.SaveToFile(@"../../output/result.docx", Spire.Pdf.FileFormat.DOCX);


Sincerely
Abel
E-iceblue support team
User avatar

Abel.He
 
Posts: 1010
Joined: Tue Mar 08, 2022 2:02 am

Mon Oct 31, 2022 6:54 am

Hello,

Greeting from E-iceblue.
Does the code I provided meet your requirement? Could you give some feedback in your free time? Thanks for your assistance in advance. Have you a nice day!

Sincerely
Abel
E-iceblue support team
User avatar

Abel.He
 
Posts: 1010
Joined: Tue Mar 08, 2022 2:02 am

Return to Spire.Doc