Does Aspose.Cells have word conversion?
I have a requirement where from XLS output each sheet will be converted into a word document and there will be page break per Excel spreadsheet. Example 3 sheets in workbook. I like to convert into 3 page word doc.
Does Aspose.Cells interface with Aspose.Words? Do you have any sample code?
Thanks!
Thanks for re-posting here in the Aspose.word. Can someone please comment what option available beside embedding excel OLE within a word doc?
thanks!
Hi Jeremy,
Thanks for your inquiry.
*jeremyyma:
Does Aspose.Cell have word conversion? I have a requirement where from XLS output each sheet will be converted into a word document and there will be page break per Excel spreadsheet. Example 3 sheets in workbook. I like to convert into 3 page word doc. Does Aspose.Cells interface with Aspose.Words? Do you have any sample code? Thanks!*
Aspose.Cells does not convert Excel document to Word document. In your case, I suggest you to use the attached utility to convert Excel document to Word document. Hope this helps you.
ConverterXls2Doc converterXls2Doc = new ConverterXls2Doc(MyDir + "Aspose.Words.xlsx", true, "Arial", "10");
converterXls2Doc.convert(false);
Document convertedWordDoc = converterXls2Doc.getDocument();
convertedWordDoc.save(MyDir + "Out.docx");
*jeremyyma:
Thanks for re-posting here in the Aspose.word. Can someone please comment what option available beside embedding excel OLE within a word doc? thanks!*
You can use the above code to convert XLSX document to Word document. If you want to insert an embedded OLE object, please use following code example.
Document document = new Document();
DocumentBuilder docBuilder = new DocumentBuilder(document);
File iconFile = new File(MyDir + "icon.png");
BufferedImage iconBufferedImage = ImageIO.read(iconFile);
InputStream stream = new FileInputStream(MyDir + "Out.xlsx");
docBuilder.insertOleObject(stream, "", true, iconBufferedImage);
docBuilder.writeln();
document.save(MyDir + "Out.rtf");
Hope this answers your query. Please let us know if you have any more queries.
Thank you Tahir for sharing your insights. This is helpful. Can I use the utility to built an OutputStream thus allow me to send the response to the user via HTTP?
Can you also share any benchmark performance metrics of OLE embedded object, I tested with the OLE excel to PPT and notice it takes unto 15 seconds to do a simple spreadsheet.
-jeremy
Hi Jeremy,
Thanks for your inquiry.
*jeremyyma:
Can I use the utility to built an OutputStream thus allow me to send the response to the user via HTTP?*
In this case, you need to implement an HTTPServlet before you can send the document to the browser. Please check the following code example.
/**
* Called from the web-app index page (because the POST method is chosen for the input form).
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
// Get the output format selected by the user.
String formatType = "DOC";
try
{
// Open the stream. Read only access is enough for Aspose.Words to load a document.
InputStream stream = new FileInputStream(MYDir + "in.docx");
// Load the entire document into memory.
com.aspose.words.Document doc = new com.aspose.words.Document(stream);
// You can close the stream now, it is no longer needed because the document is in memory.
stream.close();
// Once we have a document, we can save it to a file, stream or send to the client’s browser.
// We just send the document to the browser in this case.
sendToBrowser(doc, "AsposeWords", formatType, true, response);
response.flushBuffer();
}
catch (Exception e)
{
throw new RuntimeException(e);
}
}
/**
* Sends the document to the client’s browser.
*/
private void sendToBrowser(Document doc, String demoName, String formatType, boolean openNewWindow, HttpServletResponse response)
throws Exception
{
String extension = formatType;
String fileName = demoName + "." + extension;
// Add the Response header
if(openNewWindow)
response.setHeader("content-disposition","attachment; filename=" + fileName);
else
response.addHeader("content-disposition","inline; filename=" + fileName);
response.setContentType("application/msword");
doc.save(response.getOutputStream(), SaveFormat.DOC);
}
*jeremyyma:
Can you also share any benchmark performance metrics of OLE embedded object, I tested with the OLE excel to PPT and notice it takes unto 15 seconds to do a simple spreadsheet.*
Unfortunately we have no benchmarks available for performance/memory tests yet. Generally, the processing time and memory usage fully depend on your documents and their complexity. Aspose.Words needs few times more memory than document size to build model of the document (DOM) in memory.
Please let us know if you have any more queries.