Quantcast
Channel: Mendix Forum Questions
Viewing all articles
Browse latest Browse all 82411

Using Aspose.cells convert and xlsx to string, save as a .pdf, then to commit it to FileDocument Object

$
0
0

I am trying to create a java action that can take in a .xlsx FileDocument, convert it to a string in .csv format (uses commas and\n for the cells and rows) and then convert this string to a .pdf.

// Input the .xlsx FileDocument object
InputStream inputStream = Core.getFileDocumentContent(getContext(), __XLSXDocumentToClone);
// This extra method just reads the .xlsx and puts it into a .csv format string.
String inputString = readXLSXFile(inputStream);

// Write the string to a stream
InputStream testStream = new ByteArrayInputStream(inputString.getBytes("UTF-8"));

// Aspose.cells way of creating a workbook and its options
TxtLoadOptions options = new TxtLoadOptions(LoadFormat.CSV);
options.setSeparator(',');
// Create the workbook using the stream and the options given
Workbook workbook = new Workbook(testStream, options);

// Try to change the format to .pdf through saving options
ByteArrayOutputStream stream = new ByteArrayOutputStream();
workbook.save(stream,SaveFormat.PDF);

// Save the new .pdf stream to another FileDocument	object
Core.storeFileDocumentContent(getContext(), this.EmailAttachmentParameter1.getMendixObject(), new ByteArrayInputStream(stream.toByteArray()));

return true;

this works to an extent, but the .pdf file that is saved will then only be in XML format, pdf readers for some reason can't understand it.

 

Any help would be great.*


Viewing all articles
Browse latest Browse all 82411

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>