//读出和写进excel表格,代码都是可以直接运行的
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_write {
static public void main(String[] args) throws Exception {
FileOutputStream fos = new FileOutputStream("d:/test.xls");
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet s = wb.createSheet();
wb.setSheetName(0, "second sheet");
for(int i=0;i<10;i++){
HSSFRow row = s.createRow(i);
for(int j=0;j<10;j++){
HSSFCell cell = row.createCell(j);
cell.setCellValue("Hello!");
}
}
wb.write(fos);
fos.close();
}
}
import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.poifs.filesystem.*;
import java.io.FileInputStream;
import java.io.IOException;
//读取Excel文件时,首先生存一个POIFSFileSystem对象,由POIFSFileSystem对象构造一个HSSFWorkbook,该HSSFWorkbook对象就代表了Excel文档。下面代码读取上面生成的Excel文件写入的消息字串:
public class PoiTest_read {
static public void main(String[] args) throws Exception {
POIFSFileSystem fs =null;
HSSFWorkbook wb = null;
double B[][] = new double[800][6];
try {
fs = new POIFSFileSystem(new FileInputStream("d:/result_desc.xls"));
wb = new HSSFWorkbook(fs);
} catch (IOException e) {
e.printStackTrace();
}
HSSFSheet sheet = wb.getSheetAt(0);
for(int i=0;i<800;i++){
HSSFRow row = sheet.getRow(i);
for(int j=1;j<7;j++){
HSSFCell cell =row.getCell(j);
//String msg =cell.getStringCellValue();
double msg =cell.getNumericCellValue();
B[i][j-1]=msg;
// System.out.print(msg+" ");
}
System.out.println();
}
for(int i=0;i<800;i++){
for(int j=0;j<6;j++){
//System.out.print(B[i][j]+" ");
}
System.out.println();
}
PO po = new PO();
po.PO_test(B);
}
}
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_write {
static public void main(String[] args) throws Exception {
FileOutputStream fos = new FileOutputStream("d:/test.xls");
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet s = wb.createSheet();
wb.setSheetName(0, "second sheet");
for(int i=0;i<10;i++){
HSSFRow row = s.createRow(i);
for(int j=0;j<10;j++){
HSSFCell cell = row.createCell(j);
cell.setCellValue("Hello!");
}
}
wb.write(fos);
fos.close();
}
}
import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.poifs.filesystem.*;
import java.io.FileInputStream;
import java.io.IOException;
//读取Excel文件时,首先生存一个POIFSFileSystem对象,由POIFSFileSystem对象构造一个HSSFWorkbook,该HSSFWorkbook对象就代表了Excel文档。下面代码读取上面生成的Excel文件写入的消息字串:
public class PoiTest_read {
static public void main(String[] args) throws Exception {
POIFSFileSystem fs =null;
HSSFWorkbook wb = null;
double B[][] = new double[800][6];
try {
fs = new POIFSFileSystem(new FileInputStream("d:/result_desc.xls"));
wb = new HSSFWorkbook(fs);
} catch (IOException e) {
e.printStackTrace();
}
HSSFSheet sheet = wb.getSheetAt(0);
for(int i=0;i<800;i++){
HSSFRow row = sheet.getRow(i);
for(int j=1;j<7;j++){
HSSFCell cell =row.getCell(j);
//String msg =cell.getStringCellValue();
double msg =cell.getNumericCellValue();
B[i][j-1]=msg;
// System.out.print(msg+" ");
}
System.out.println();
}
for(int i=0;i<800;i++){
for(int j=0;j<6;j++){
//System.out.print(B[i][j]+" ");
}
System.out.println();
}
PO po = new PO();
po.PO_test(B);
}
}