Getting error while using DOCX word document

Hi,

I am trying to get employee resume template but when using docx extension it gives me 2 errors which i have attached in files as image format. When i use doc format it is giving proper template generation.
I am also providing docx extension file. Please revert me back ASAP.

Thanks,
Shrikant

Hi Shrikant,

Thanks for your inquiry. I am afraid, I was unable to locate any problem in the attached document. Could you please upgrade to the latest version of Aspose.Words i.e. 11.2.0 and let us know how it goes on your side?

I hope, this will help.

Best Regards,

I am using the latest version only though i am facing this issue and one more thing when document gets generate, the name of document also gets change that it become new file that is “Document”[name of file], so can you please tell why this happens?
Please assist me for this two issues as early as possible.

Thanks,
Shrikant

Hi Shrikant,

Thanks for your inquiry. Unfortunately, it is difficult to say what the problem is without the code. Could you please also share the complete code here to reproduce the same problem on our side?

Best Regards,

we are using word mail merge here is the code that generates document :doc.getMailMerge().execute( new String[] { "Name", "Type", "Description", "city", "state", "account", "finalValue", "Footage" ,"industry","Category", "contactName","PersonName","Phone","Email", "ownerName","ownerPersonName","ownerPhone","ownerEmail"}, new Object[] { Name, Type, Description, city, state, account, fmt.format(fcv), nf1.format(sfv),industry,Category, contactName,PersonName, Phone,Email,ownerName,ownerPersonName,ownerPhone,ownerEmail});builder.getDocument().updateFields();

doc.save(genFolderPath+"/"+asposeInitializer.getNameOfGeneratedDocx());doc.save(genF

we are using word mail merge here is the code that generates document :doc.getMailMerge().execute( new String[] { "Name", "Type", "Description", "city", "state", "account", "finalValue", "Footage" ,"industry","Category", "contactName","PersonName","Phone","Email", "ownerName","ownerPersonName","ownerPhone","ownerEmail"}, new Object[] { Name, Type, Description, city, state, account, fmt.format(fcv), nf1.format(sfv),industry,Category, contactName,PersonName, Phone,Email,ownerName,ownerPersonName,ownerPhone,ownerEmail});builder.getDocument().updateFields();

doc.save(genFolderPath+"/"+asposeInitializer.getNameOfGeneratedDocx());

Hi
Shrikant,


Thanks for the additional information. But, could you please double check if the word document (Employee_Resume_Template.docx), i.e. attached with your first post, is the one you’re getting this problem with? I am asking this because I was unable to find any Merge Field with the name specified in the fieldnames string array parameter in Execute method.

Best Regards,

i have just provided the info on what and how we are doing it and we just need to populate data to template and render it via web, it has nothing specific to our document it happens to any document you can try for your self or if you have some time i could show to you with a sample template.

Hope this hleps.

Hi Shrikant,

Thanks for the additional information.

While using the latest version of Aspose.Words i.e. 11.3.0, I managed to reproduce this issue on my side. I have logged this issue in our bug tracking system as WORDSNET-6310. Your request has also been linked to this issue and you will be notified as soon as it is resolved.

Sorry for the inconvenience.

Best Regards,
Hi Shrikant,

It is to update you that during analyzing your issue, we have found that this is actually not an issue in Aspose.Words. I think, to resolve the problem with DOCX you should simply add Response.End() after sending document to client browser. This will resolve the problem. For some reasons when you save a DOCX document to client browser, content of web page is added at the end of the document, you can see this if open your DOCX document in any binary editor. That is why MS Word cannot open this document. If you add Response.End(), content of web page will not be added and document will be valid. Please let me know if this helps.

Best Regards,

Hi,

It seems that you think if we end the respose after writing the document to broswer we would not have this issue, but we are using out.clear which are jsp out object methods and also are using servlet output stream object method outputsteam's close and flush, but still have the issue. these methods are similar to Response.End() functionality wise.

And also the jsp does not have any html content in it, it is 100% jps which has only out.write .

Hope this helps.

Here is the complete Jsp which does not have any html :

<%@ page language="java"%>
<%@page import="org.apache.log4j.Logger"%>
<%@ page import="java.util.*,java.io.*"%>
<%@ page import="com.aspose.words.Document"%>
<%@ page import="com.aspose.words.SaveFormat"%>

<%
//read the file name.
Logger log = Logger.getLogger("docGenSuccess.jsp");
String filePath = request.getAttribute("fileLocation").toString();
String fileName = filePath.substring(filePath.lastIndexOf(File.separator)+1,filePath.length());
File f = new File (filePath);

if(fileName.contains(".doc")) {
response.setContentType ("application/msword");
response.setHeader ("Content-Disposition", "attachment;filename=\""+fileName+"\"");
}

if(fileName.contains(".docx")) {
response.setContentType ("application/vnd.openxmlformats-officedocument.wordprocessingml.document");
response.setHeader ("Content-Disposition", "attachment;filename=\""+fileName+"\"");
}

if(fileName.contains(".pdf")) {
response.setContentType ("application/pdf");
response.setHeader ("Content-Disposition", "attachment;filename=\""+fileName+"\"");
}

//get the file name
String name = f.getName().substring(f.getName().lastIndexOf(File.separator) + 1,f.getName().length());
InputStream in = null;
ServletOutputStream outs = response.getOutputStream();
if(fileName!= null && fileName.contains(".docx")) {
try{
Document outdoc = new Document(filePath);
outdoc.save(outs,SaveFormat.DOCX);
}catch(Throwable t){
t.printStackTrace(System.out);
}finally{
if(outs != null){
outs.flush();
outs.close();
}
}
} if(outs != null){
outs.flush();
outs.close();
}
}
}

out.clear();
%>

Hi Shrikant,


Thanks for the additional information. We’re working over your query and will get back to you soon.

Best Regards,

Hi
Shrikant,


Thanks for your patience.

I have attached a test WebApplication here with this post. Could you please try executing this application on your side and let us know how it goes? Moreover, it includes a simple JSP and a Servlet. When you click the Submit button, the DOCX file, i.e. generated by Aspose.Words, will be sent to client’s browser.

I hope, this will help.

Best Regards,

over riding java.io.PrintWriter calss did not make any difference, sorry to say that it did not help.

Hi Shrikant,


Thanks for the additional information. Could you please create and attach here a simple web application that enables us to reproduce this issue on our side? We will investigate the issue further and provide you more information. We apologize for your inconvenience.

Best Regards,

please use this jsp to test no web application is required:

<%@ page language="java"%>
<%@page import="org.apache.log4j.Logger"%>
<%@ page import="java.util.*,java.io.*"%>
<%@ page import="com.aspose.words.Document"%>
<%@ page import="com.aspose.words.SaveFormat"%>

<%
//read the file name.
Logger log = Logger.getLogger("docGenSuccess.jsp");
String filePath = request.getAttribute("fileLocation").toString();
String fileName = filePath.substring(filePath.lastIndexOf(File.separator)+1,filePath.length());
File f = new File (filePath);

if(fileName.contains(".doc")) {
response.setContentType ("application/msword");
response.setHeader ("Content-Disposition", "attachment;filename=\""+fileName+"\"");
}

if(fileName.contains(".docx")) {
response.setContentType ("application/vnd.openxmlformats-officedocument.wordprocessingml.document");
response.setHeader ("Content-Disposition", "attachment;filename=\""+fileName+"\"");
}

if(fileName.contains(".pdf")) {
response.setContentType ("application/pdf");
response.setHeader ("Content-Disposition", "attachment;filename=\""+fileName+"\"");
}

//get the file name
String name = f.getName().substring(f.getName().lastIndexOf(File.separator) + 1,f.getName().length());
InputStream in = null;
ServletOutputStream outs = response.getOutputStream();
if(fileName!= null && fileName.contains(".docx")) {
try{
Document outdoc = new Document(filePath);
outdoc.save(outs,SaveFormat.DOCX);
}catch(Throwable t){
t.printStackTrace(System.out);
}finally{
if(outs != null){
outs.flush();
outs.close();
}
}
} if(outs != null){
outs.flush();
outs.close();
}
}
}

out.clear();
%>

Hi
Shrikant,


Thanks for the additional information. I have modified your JSP code and attached a new JSP page here for your reference. This page works perfectly on my side. Please let us know how it goes on your side?

Best Regards,

sorry to say that the same problem still exists.

i here with attach the screen shots, please make sure you validate in weblogic so that you can easily reproduce the issue.

Hi Shrikant,


Thanks for your patience.

I have tested the scenario and have managed to reproduce the same problem. For the sake of correction, I have logged this problem as WORDSJAVA-554 in our issue tracking system. We will further look into the details of this problem and will keep you updated on the status of correction. We apologize for your inconvenience.

Best Regards,

The issues you have found earlier (filed as WORDSNET-6310) have been fixed in this .NET update and this Java update.


This message was posted using Notification2Forum from Downloads module by aspose.notifier.