JAVA small exercise-10 POI processing Excel file-write XLSX file

import java.io.IOException;

import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

public class WriteXLSX {
    
    
	public static void main(String[] args) {
    
    		
		try {
    
    
			File f = new File("C:\\Users\\Admin\\Desktop\\写入测试02.xlsx");
			FileOutputStream fop = new FileOutputStream(f);
			XSSFWorkbook xwb = new XSSFWorkbook();
			XSSFSheet xs = xwb.createSheet("写测试");
			for (int i = 0; i<10;i++){
    
    
				XSSFRow r = xs.createRow(i);
				for (int j = 0; j < 3;j++){
    
    
					XSSFCell xsc = r.createCell(j);
					xsc.setCellValue("hello"+"--"+i+"--"+j);
				}
			}
			xwb.write(fop);	
			xwb.close();
			fop.close();
		} catch ( Exception e) {
    
    
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
	
}

Insert picture description here

Guess you like

Origin blog.csdn.net/KathyLJQ/article/details/109905562