JAVA将数据按指定格式导出为EXCEL和从EXCEL读相关的内容视频教程.rar

时间:2011-06-16 21:24:59
【文件属性】:
文件名称:JAVA将数据按指定格式导出为EXCEL和从EXCEL读相关的内容视频教程.rar
文件大小:3.78MB
文件格式:RAR
更新时间:2011-06-16 21:24:59
代码 视频教程 大家好,我是陈亮,JAVA将数据按指定格式导出为EXCEL和从EXCEL读相关的内容视频教程
1,把poi-2.5.1-final-20040804.jar复制到jdk的classpath下,我这里用的插件是POI
我已打好在包中。。

我这里JDK装到C:\jdk1.5.0_05\lib 就复制到这里。。

先看我演示。。。

先演示写出到EXCEL 看到了吧。。。。




再演示读EXCEL 这里我是把bb.xls 里面的name:后面的读出来,以及
age:后面的读出来。。。看。。。
改一下name:后面之后再读...
这里文件改为bbc.xls

用JCreator方便一点,,所以没用jbuilder
OK看到了吧。。。。
我再讲解代码

写出我已解啦,,,


再说读入。。。



代码就是这样,,谢谢。。。

希望可以和大家共同学习。。。我的msn:ediku@263.net qq:50143539


再见...代码在包里。。




















读入

import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.poifs.filesystem.*;
import java.io.*;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class read implements ActionListener
{

JFrame frame;
JLabel label1,label2;
JTextField tf1,tf2;
JButton bu;
JPanel panel;
public read()
{
frame=new JFrame("aaaa");
panel=new JPanel();

label1=new JLabel("姓名:");
tf1=new JTextField(10);
label2=new JLabel("年龄:");
tf2=new JTextField(10);
bu=new JButton("导入");


panel.add(label1);


panel.add(tf1);


panel.add(label2);


panel.add(tf2);


panel.add(bu);
frame.getContentPane().add(panel);
bu.addActionListener(this);

frame.setSize(400,400);
frame.show();
}
/**
* @param args
*/

public static void main(String args[])
{
new read();
}


public void actionPerformed(ActionEvent e)
{
if (e.getSource()==bu)
{
try
{
// TODO Auto-generated method stub

FileInputStream filein=new FileInputStream("bb.xls");
POIFSFileSystem fs=new POIFSFileSystem(filein);
HSSFWorkbook wb=new HSSFWorkbook(fs);
// POIFSFileSystem fs=new POIFSFileSystem(new FileInputStream("c:\\aa.xls"));
HSSFSheet sheet=wb.getSheetAt(0);
for (int i=0;i<7;i++)
{
HSSFRow row=sheet.getRow(i);
System.out.println("i="+i);
if (row==null)continue;

for (int j=1;j<7;j++)
{

if (row.getCell((short)j)==null)
{
System.out.println("j="+j);
continue;
}
else if(row.getCell((short)j).getStringCellValue().trim().equals("name:"))
{
int n=j+1;
System.out.println("name="+row.getCell((short)n).getStringCellValue().trim());
tf1.setText(row.getCell((short)n).getStringCellValue().trim());

}
else if(row.getCell((short)j).getStringCellValue().trim().equals("age:"))
{
int n=j+1;
System.out.println("age="+row.getCell((short)n).getNumericCellValue());
tf2.setText(String.valueOf(row.getCell((short)n).getNumericCellValue()));

}
else
{
System.out.println(row.getCell((short)j).getStringCellValue().trim());
}
}
}


filein.close();
System.out.println("aaa");
}
catch(Exception ex)
{
System.out.println("error "+ex.toString());
}

}
}

}





写入
import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.poifs.filesystem.*;
import java.io.*;

public class write {

/**
* @param args
*/
public static void main(String[] args) {
try
{
// TODO Auto-generated method stub
HSSFWorkbook wb=new HSSFWorkbook();
//POIFSFileSystem fs=new POIFSFileSystem(new FileInputStream("c:\\aa.xls"));

HSSFSheet sheet=wb.createSheet("new sheet");
HSSFRow row=sheet.createRow((short)1);
row.createCell((short)1).setCellValue(1.2);
row.createCell((short)2).setCellValue("hellow way");
row.createCell((short)3).setCellValue("aaaaa");
FileOutputStream fileout=new FileOutputStream("aa.xls");
wb.write(fileout);
fileout.close();
System.out.println("aaa");
}
catch(Exception e)
{}
}

}
【文件预览】:
060105jave
----黑鹰说明.txt(1KB)
----JAVA按指定格式导出为EXCEL和读EXCEL的内容.exe(3.84MB)
----poi-2.5.1-final-20040804.jar(783KB)
----说明.txt(4KB)
----read_excel()
--------read.java(3KB)
--------aa.xls(4KB)
--------F043A000(14KB)
--------read.class(3KB)
--------bbc.xls(14KB)
--------bb.xls(14KB)
--------write.java(929B)
--------write.class(1KB)

网友评论