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.

Thu Mar 20, 2014 9:20 am

Hello, I'm currently working at a program that must be able to murge multiple word files in to one but now I have 1 little problem. my code is not giving me any error but when i try to exicute it it gives me this :

Image

this is the code I'm currently working / using:

Code: Select all
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Microsoft.Office.Interop.Word;
using System.Runtime.InteropServices;
using Novacode;
using System.Diagnostics;
using System.IO;
using Spire.Doc;
using Spire.Doc.Documents;

namespace copy_form_fiel_to_file
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        //teller
        int teller = 0;
       
       
        //file paths
        string een = "C:\\Users\\Sebastiaan.EXIT-REIZEN\\Desktop\\test map\\1.docx";
        string twee = "C:\\Users\\Sebastiaan.EXIT-REIZEN\\Desktop\\test map\\2.docx";
        string drie = "C:\\Users\\Sebastiaan.EXIT-REIZEN\\Desktop\\test map\\3.docx";
        //switch verwijzingen
        string doc1;
        string doc2;
        string doc3;

        private void btn_klaar_Click_1(object sender, EventArgs e)
        {
            Spire.Doc.Document DocOne = new Spire.Doc.Document();
            DocOne.LoadFromFile(doc1, FileFormat.Docx);
            Spire.Doc.Document DocTwo = new Spire.Doc.Document();
            DocTwo.LoadFromFile(doc2, FileFormat.Docx);
            Spire.Doc.Document Docthree = new Spire.Doc.Document();
            Docthree.LoadFromFile(doc3, FileFormat.Docx);

            //Merge
            foreach (Spire.Doc.Section sec in DocTwo.Sections)
            {
                DocOne.Sections.Add(sec.Clone());
            }

            //Merge
            foreach (Spire.Doc.Section sec in Docthree.Sections)
            {
                DocOne.Sections.Add(sec.Clone());
            }

            //save and launch
            DocOne.SaveToFile(@"C:\Users\Sebastiaan.EXIT-REIZEN\Desktop\test map/5.docx", FileFormat.Docx);
            System.Diagnostics.Process.Start(@"C:\Users\Sebastiaan.EXIT-REIZEN\Desktop\test map/5.docx");
        }

        private void btn_document1_Click(object sender, EventArgs e)
        {
            teller = +1;

            switch (teller)
            {
                case 1:
                    doc1 = een;
                    break;
                case 2:
                    doc2 = een;
                    break;
                case 3:
                    doc3 = een;
                    break;
            }
        }

        private void btn_document2_Click(object sender, EventArgs e)
        {
            teller = +1;

            switch (teller)
            {
                case 1:
                    doc1 = twee;
                    break;
                case 2:
                    doc2 = twee;
                    break;
                case 3:
                    doc3 = twee;
                    break;
            }
        }

        private void btn_document3_Click(object sender, EventArgs e)
        {
            teller = +1;

            switch (teller)
            {
                case 1:
                    doc1 = drie;
                    break;
                case 2:
                    doc2 = drie;
                    break;
                case 3:
                    doc3 = drie;
                    break;
            }
        }
    }
}

pietersen9
 
Posts: 1
Joined: Wed Mar 05, 2014 12:31 pm

Fri Mar 21, 2014 2:53 am

Hi,

Thanks for your inquiry.

Please use "++teller" or "teller+=1" to replace "teller=+1" before the switch to solve the problem.
If you have otherquestions, welcome to get it back to us.

Sincerely,
Lisa
E-iceblue support team
User avatar

lisa.chen
 
Posts: 21
Joined: Thu Mar 20, 2014 2:31 am

Thu Mar 15, 2018 10:07 am

i pass combination of PDF and docx file to server...
I want to merge all these document to WORD FILE DOCX format..

for this firstofall i convert all pdf files to docx and then
collect all docx file from directory
but while passing docx file which is originally converted from PDF file
throws exception i.e.

The string 'on' is not a valid Boolean value.
System.FormatException: The string 'on' is not a valid Boolean value.


please help me to solve this issues..here is code used to convert and merge to docx..

public async Task<ActionResult> MergeDocxFiles()
{
try
{
await Task.Delay(10000);
Random num = new Random();
string Filebase64 = "";
List<OpenXmlPowerTools.Source> sources = new List<OpenXmlPowerTools.Source>();
byte[] fileBytes;
string newFileName = String.Format("{0}.docx", Guid.NewGuid().ToString());
string mainDirectory = "MergeDir" + num.Next(1, 99999);
Directory.CreateDirectory(_appFolders.TempFileDownloadFolder + "\\" + mainDirectory);

string resultFilePath = Path.Combine(_appFolders.TempFileDownloadFolder + "\\" + mainDirectory, newFileName);

string mainpath = Path.Combine(_appFolders.TempFileDownloadFolder + "\\" + mainDirectory);
if (Request.Form.Files.Count >= 0)
{
foreach (var fileobj in Request.Form.Files)
{

var filePath = Path.Combine(mainpath, fileobj.FileName);

var stream = fileobj.OpenReadStream();
fileBytes = stream.GetAllBytes();

FileStream fs = System.IO.File.Create(filePath);
fs.Write(fileBytes, 0, fileBytes.Length);
fs.Dispose();
fs.Close();
fileBytes=new byte[0];
}

string[] documents = Directory.GetFiles(mainpath);

foreach (string file in documents)
{
string ext = Path.GetExtension(file);
if (ext == ".pdf")
{
string filename = Path.GetFileNameWithoutExtension(file);
var existfileBytes = new byte[0];
PdfDocument doc = new PdfDocument(file);
doc.SaveToFile(mainpath + "\\" + filename + ".docx", Spire.Pdf.FileFormat.DOCX);
doc.Dispose();
doc.Close();
System.IO.File.Delete(file);
existfileBytes = new byte[0];
}
}

List<string> files = new List<string>();


foreach (var fileobj in Request.Form.Files)
{
foreach (string file in Directory.EnumerateFiles(mainpath, "*.docx"))
{
if (Path.GetFileNameWithoutExtension(fileobj.FileName) == Path.GetFileNameWithoutExtension(file))
{
files.Add(file);
}
}
}

List<Spire.Doc.Document> WordFiles = new List<Spire.Doc.Document>();


foreach(string file in files)
{
Spire.Doc.Document Worddoc = new Spire.Doc.Document(file,Spire.Doc.FileFormat.Docx);
WordFiles.Add(Worddoc);
}

for (int i = 1; i < WordFiles.Count; i++)
{
foreach (Section sec in WordFiles[i].Sections)
{
WordFiles[0].Sections.Add(sec.Clone());
}
}

WordFiles[0].SaveToFile(resultFilePath,Spire.Doc.FileFormat.Docx);

var mergefileBytes = System.IO.File.ReadAllBytes(resultFilePath);

Filebase64 = System.Convert.ToBase64String(mergefileBytes);

//docX.Dispose();
//docX.Close();
//Directory.Delete(mainpath);
}

return Content(Filebase64);
}
catch (UserFriendlyException ex)
{
return Content(ex.Message);
}
}

suraj92
 
Posts: 12
Joined: Thu Mar 15, 2018 9:57 am

Fri Mar 16, 2018 5:06 am

Please help me....

suraj92
 
Posts: 12
Joined: Thu Mar 15, 2018 9:57 am

Fri Mar 16, 2018 6:10 am

Hello,

Thanks for your post. In order to investigate the issue, please share us with your input Pdf files and docx files.

Best regards,
Simon
E-iceblue support team
User avatar

Simon.yang
 
Posts: 620
Joined: Wed Jan 11, 2017 2:03 am

Fri Mar 16, 2018 6:33 am

I have attached sample files..please look at this..

suraj92
 
Posts: 12
Joined: Thu Mar 15, 2018 9:57 am

Fri Mar 16, 2018 7:00 am

Hello,

I can't find your attachment. Please first zip them and upload it.

Best regards,
Simon
E-iceblue support team
User avatar

Simon.yang
 
Posts: 620
Joined: Wed Jan 11, 2017 2:03 am

Fri Mar 16, 2018 7:14 am

I have send you an EMAIL on Support Email ID..please check..

SAMPLE FILES FOR MERGE from user SURAJ92

suraj92
 
Posts: 12
Joined: Thu Mar 15, 2018 9:57 am

Fri Mar 16, 2018 9:01 am

Hello,

Thanks for your sharing. I have reproduced the issue when loading the converted docx file from Pdf and forwarded it to our DEV team. If there is any update, we will let you know.

Best regards,
Simon
E-iceblue support team
User avatar

Simon.yang
 
Posts: 620
Joined: Wed Jan 11, 2017 2:03 am

Mon Mar 19, 2018 1:57 pm

I am using Trial VERSION, could i used it to run on SERVER?
I tested it on localhost now i want to publish it on server to check is it working properly or not?

Please tell me..

suraj92
 
Posts: 12
Joined: Thu Mar 15, 2018 9:57 am

Tue Mar 20, 2018 1:23 am

Hello,

Thanks for your inquiry.
You could use it to run on SERVER. Just go ahead.

Best regards,
Simon
E-iceblue support team
User avatar

Simon.yang
 
Posts: 620
Joined: Wed Jan 11, 2017 2:03 am

Fri Apr 20, 2018 1:02 am

Hello suraj92,

Glad to inform you that the issue has been fixed. Please download Spire.Office Platinum Version:3.0 and give it a try.

Best regards,
Simon
E-iceblue support team
User avatar

Simon.yang
 
Posts: 620
Joined: Wed Jan 11, 2017 2:03 am

Tue Apr 24, 2018 3:36 am

Hello,

Has the hotfix resolved your issue?
We will appreciate it if you could give us some feedback.

Best regards,
Simon
E-iceblue support team
User avatar

Simon.yang
 
Posts: 620
Joined: Wed Jan 11, 2017 2:03 am

Return to Spire.Doc