How to Copy Data from Range of Cells with Style in Workbook inside Java Apps

This technical tip show how developers can Copy Range Data with Style in an Excel Workbook inside Java Applications. Copy Range Data Only explained how to copy the data from a range of cells to another range. Aspose.Cells can also copy a range complete with formatting. This article explains how to achieve this task. Aspose.Cells provides a range of classes and methods for working with ranges, for example createRange(), StyleFlag, applyStyle() etc.
//your code here... String filePath = "F:/Downloads/source.xlsx"; //Load your source workbook Workbook workbook = new Workbook(filePath); //0-byte array byte[] workbookData = new byte[0]; //Text save options. You can use any type of separator TxtSaveOptions opts = new TxtSaveOptions(); opts.setSeparator('\t'); //Copy each worksheet data in text format inside workbook data array for (int idx = 0; idx < workbook.getWorksheets().getCount(); idx++) { //Save the active worksheet into text format ByteArrayOutputStream bout = new ByteArrayOutputStream(); workbook.getWorksheets().setActiveSheetIndex(idx); workbook.save(bout, opts); //Save the worksheet data into sheet data array byte[] sheetData = bout.toByteArray(); //Combine this worksheet data into workbook data array byte[] combinedArray = new byte[workbookData.length + sheetData.length]; System.arraycopy(workbookData, 0, combinedArray, 0, workbookData.length); System.arraycopy(sheetData, 0, combinedArray, workbookData.length, sheetData.length); workbookData = combinedArray; } //Save entire workbook data into file FileOutputStream fout = new FileOutputStream(filePath + ".out.txt"); fout.write(workbookData); fout.close();

Url: http://www.aspose.com/java/excel-component.aspx

Language: Java | User: Sheraz Khan | Created: Aug 26, 2015 | Tags: Copy Range Data in workbook copy data from a range Excel cells copy data from range of cells to another range Creates a workbook Java Excel API Apply style to the data range Java Worksheet