poi 导出excel2003和excel2007的不同

package Test;


import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;


import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;


public class Test {


/**
* @param args
*/
public static void main(String[] args) throws IOException {  
          
String path="E:\\test.xlsx";
if(path.contains("xlsx"))
{
XlsxExport(path);
}
else {
XlsExport(path);
}
    }  

public static void XlsxExport(String path)
{
   File fi=new File(path);  
       XSSFWorkbook wb;
try {
wb = new XSSFWorkbook(new FileInputStream(fi));
XSSFSheet sheet = wb.getSheetAt(0);  
       //在相应的单元格进行赋值  
       XSSFCell cell = sheet.createRow(1).createCell(0);  
       cell.setCellValue("测试");     
       //修改模板内容导出新模板  
       FileOutputStream out = new FileOutputStream(path);  
       wb.write(out);  
       out.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}        
}

public static void XlsExport(String path)
{
File fi=new File(path);  
        POIFSFileSystem fs;
try {
fs = new POIFSFileSystem(new FileInputStream(fi));
//读取excel模板  
       HSSFWorkbook wb = new HSSFWorkbook(fs);  
       //读取了模板内所有sheet内容  
       HSSFSheet sheet = wb.getSheetAt(0);  
       //在相应的单元格进行赋值  
       HSSFCell cell = sheet.createRow(1).createCell(0);  
       cell.setCellValue("测试");     
       //修改模板内容导出新模板  
       FileOutputStream out = new FileOutputStream(path);  
       wb.write(out);  
       out.close();  
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}  
}


}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值