Free Support Forum - aspose.com

JAVA save workbook prompt user

In Java is there anyway to save a workbook object (xlsx file), and then prompt the user to open or save the xlsx file, rather than just using wb.save to save to the local file system?

something like this but for java

@jt10

Thanks for using Aspose APIs.

You can convert your workbook into array of bytes using the ByteArrayOutputStream object. Please see the following equivalent code in Java for your reference.

Java

public static byte[] GetWorkbookBuffer() throws Exception {

	Workbook workbook = new Workbook();

	Worksheet worksheet = workbook.getWorksheets().get(0);

	Cell cell = worksheet.getCells().get("A1");
	cell.putValue("ID");

	Cell cell1 = worksheet.getCells().get("A2");
	cell1.putValue("NewName");

	java.io.ByteArrayOutputStream baos = new java.io.ByteArrayOutputStream();
	workbook.save(baos, SaveFormat.XLSX);

	byte[] buffer = null;
	buffer = baos.toByteArray();

	return buffer;
}