How to generate an Excel file with JSP

xiaoxiao2021-03-06  91

Jakarta_poi uses Java to read and write Excel (97-2002) files to meet most of the needs. Because there is a project to use this tool, I spent some time to translate a guide with the POI itself. There are some sections and modifications, I hope to give some people to use someone to get home help.

There are several self-projects under POI: HSSF is used to implement Excel's read and write. The following is the homepage of HSSF http://jakarta.apache.org/poi/hssf/index.html The following information is based on the following address: HTTP : //jakarta.apache.org/poi/hssf/quick-Guide.html The current version of 1.51 should be a stable version within a long time, but the hssf provided by the SAMPLE is not based on 1.51, so when used It is necessary to pay attention. In fact, several sub-projects below POI focused on different read and write Word HDF is being developed. XML's FOP (http://xml.apache.org /fop/index.html) can output PDF files, too A better tool directory: Create a Workbook Create a Sheet Create Cells Creating a Date Cells Settings Unit Format Description: The following may be required to use the following IMPORT Org.apache.poi.hssf.usermodel.hssfcell; import org.apache .poi.hssf.usermodel.HSSFCellStyle; import org.apache.poi.hssf.usermodel.HSSFDataFormat; import org.apache.poi.hssf.usermodel.HSSFFont; import org.apache.poi.hssf.usermodel.HSSFRow; import org .apache.poi.hssf.usermodel.HSSFSheet; import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.hssf.util.HSSFColor; create workbookHSSFWorkbook wb = new HSSFWorkbook (); // use the default Construction Method Creating WorkbookFileOutputStream Fileout = New FileOutputStream ("Workbook.xls"); // Specify file name wb.write (fileout); // Output to file fileout.close (); create a SheethssFworkBook WB = New HSSFWorkbook (); HSSFSheet S heet1 = wb.createSheet ( "new sheet"); // workbook created sheetHSSFSheet sheet2 = wb.createSheet ( "second sheet"); // workbook created another sheetFileOutputStream fileOut = new FileOutputStream ( "workbook.xls"); wb. Write (fileout); fileout.close (); create cellshssfworkbook wb = new hssfworkbook (); hssfsheet sheet = wb.createsheet ("new sheet"); // Note The following code Many methods of parameters are short instead of int Do a type conversion hssfrow rot = sheet.createrow ((short) 0); // Sheet creates a line hssfcell cell = row.createcell ((Short) 0); // Create a cell Cell.setcellValue (1); / / Set the value of the value of the cell // Value of the value of the value of the parameters, there are many Double, String, Boolean, Row.createcell ((Short) 1) .SetCellvalue (1.2); row.createcell ((Short) 2) .setcellValue This is a string ");

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

New Post(0)