Java Tips: Create data in Excel format

zhaozj2021-02-16  61

There is now a solution that provides Java developers to truly create an Excel file. This is the most mature part called POI ("poor chaotic implementation") in the new Jakarta project group. The EXCEL component is named HSSF ("Scary Spreadsheet Format").

Although HSSF provides many ways to interact with many engines, we focus on the discussion of simple high-level user APIs.

The following is a simple example of creating a matrix in an Excel form: import org.Apache.poi.hssf.usermodel. *; Import java.io.fileoutputstream;

// code run against the jakarta-poi-1.5.0-final-20020506.jar.public class poitest {

static public void main (String [] args) throws Exception {FileOutputStream fos = new FileOutputStream ( "foo.xls"); HSSFWorkbook wb = new HSSFWorkbook (); HSSFSheet s = wb.createSheet (); wb.setSheetName (0, " Matrix "); for (short i = 0; i <50; i ) {hssfrow rot = S.Createrow (i);

For (short j = 0; j <50; j ) {hssfcell cell = row.createcell (j); cell.setcellValue (" i ", " j);}} wb.write (fos); fos. CLOSE ();

} This code first creates a Workbook, get a table, naming, and then proceedes from the Workbook, and then proceedes to a 50X50 matrix. Finally output an Excel file called foo.xls, or even on the Apple Mac machine.

The POI project is an exciting step of Java applications, providing users with new features of Windows document integration, allowing Java developers to easily expand their products.

转载请注明原文地址:https://www.9cbs.com/read-17314.html

New Post(0)