|
import com.aspose.cells.Cells; |
|
import com.aspose.cells.License; |
|
import com.aspose.cells.Workbook; |
|
import com.aspose.cells.Worksheet; |
|
|
|
public class GenerateExcelFileInJava { |
|
|
|
public static void main(String[] args) throws Exception { |
|
// Instantiate Aspose.Cells license to avoid trial version watermark |
|
License license = new License(); |
|
license.setLicense("Aspose.Cells.lic"); |
|
|
|
// Instantiate a new Excel workbook instance |
|
Workbook ExcelWorkbook = new Workbook(); |
|
|
|
// Get reference to first worksheet in the workbook |
|
Worksheet ExcelWorksheet = ExcelWorkbook.getWorksheets().get(0); |
|
|
|
// Get reference to Cells collection in the first worksheet |
|
Cells WorksheetCells = ExcelWorksheet.getCells(); |
|
|
|
// Insert data into the worksheet using the cells collection |
|
WorksheetCells.get("A1").putValue("Customers Report"); |
|
WorksheetCells.get("A2").putValue("C_ID"); |
|
WorksheetCells.get("B2").putValue("C_Name"); |
|
WorksheetCells.get("A3").putValue("C001"); |
|
WorksheetCells.get("B3").putValue("Customer1"); |
|
WorksheetCells.get("A4").putValue("C002"); |
|
WorksheetCells.get("B4").putValue("Customer2"); |
|
WorksheetCells.get("A5").putValue("C003"); |
|
WorksheetCells.get("B5").putValue("Customer3"); |
|
WorksheetCells.get("A6").putValue("C004"); |
|
WorksheetCells.get("B6").putValue("Customer4"); |
|
|
|
// Save the workbook as XLSX |
|
ExcelWorkbook.save("ExcelFile.xlsx"); |
|
} |
|
} |