สร้าง xlsx ด้วย java


package testxlsx;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
/**
 * @author mossila
 */
public class Main {

 public static void main(String[] args) throws FileNotFoundException, IOException {
        FileOutputStream fos = new FileOutputStream("test.xlsx");
        XSSFWorkbook wb = new XSSFWorkbook();
        Sheet sheet = wb.createSheet("Hello sheet1");
        for (int i = 0; i < 10; i++) {
            Row row = sheet.createRow(i);
            for (int j = 0; j < 9; j++) {
                   row.createCell(j).setCellValue(i + "," + j);
            }
        }
        wb.write(fos);
        fos.close();
    }
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s