poi之Excel操作

package com.test;

import org.apache.poi2.hssf.usermodel.HSSFCell;
import org.apache.poi2.hssf.usermodel.HSSFRow;
import org.apache.poi2.hssf.usermodel.HSSFSheet;
import org.apache.poi2.hssf.usermodel.HSSFWorkbook;
import java.io.FileOutputStream;

public class CreateExcel {

	public static void main(String[] args) {
		try {
			HSSFWorkbook book = new HSSFWorkbook();
			HSSFSheet sheet = book.createSheet();
			HSSFRow row;
			HSSFCell cell;
			for (int i = 0 ; i < 10 ; i++) {
				row = sheet.createRow((short)i);
				for (int j = 0 ; j < 10 ; j++) {
					cell = row.createCell((short)j);
					cell.setCellValue("cell_"+j);
				}
			}
			FileOutputStream fos = new FileOutputStream("c:/demo.xls");
			book.write(fos);
			fos.close();
			System.out.println("OK!");
		} catch (Exception e) {
			System.out.println(e.getMessage());
		}
	}
}

 

你可能感兴趣的:(apache,C++,c,Excel,J#)