zoukankan      html  css  js  c++  java
  • java获取Excel的导入

    先准备好这2个架包

    import java.io.*;
    
    import org.apache.commons.io.FileUtils;
    import org.apache.poi.hssf.usermodel.HSSFCell;
    import org.apache.poi.hssf.usermodel.HSSFRow;
    import org.apache.poi.hssf.usermodel.HSSFSheet;
    import org.apache.poi.hssf.usermodel.HSSFWorkbook;
    
    
    public class POIExceldr {
    
    	public static void main(String[] args) throws IOException {
    		String [] title={"id","name","sex"};
    		// 创建工作簿
    		HSSFWorkbook workbook=new HSSFWorkbook();
    		//创建一个工作表sheet
    		HSSFSheet sheet =workbook.createSheet();
    		//创建第一行
    		HSSFRow row=sheet.createRow(0);
    		HSSFCell cell=null;
           //插入第一行数据,ID,name,sex
    		for(int i=0;i<title.length;i++)
    		{
    			cell=row.createCell(i);
    			cell.setCellValue(title[i]);
    		}
    		//追加数据,也就是添加第二行到第十行
    		for(int i=1;i<=10;i++)
    		{
    			HSSFRow nextrow=sheet.createRow(i);
    			HSSFCell cell2=nextrow.createCell(0);
    			cell2.setCellValue("a"+i);
    			
    			cell2=nextrow.createCell(1);
    			cell2.setCellValue("xiaowang"+i);
    			
    			cell2=nextrow.createCell(2);
    			cell2.setCellValue("女"+i);
    		}
    		File file=new File("d:/learn/poidr.xls");
    		file.createNewFile();
    		FileOutputStream out=FileUtils.openOutputStream(file);
    		workbook.write(out);
    		out.close();
    		
    		
    	}
    
    }
    

      

  • 相关阅读:
    Django项目后台不挂断运行
    Django---进阶16<XSS攻击>
    Django---进阶15
    Linux开启MySql远程连接
    Django---进阶14
    Django---进阶13
    微信公众号下载文件(避开微信浏览器的文件下载方法)
    ES5的匿名函数对应ES6的箭头函数
    ES6 数值和布尔值的解构赋值
    ES6--in的用法
  • 原文地址:https://www.cnblogs.com/wangxiaoqun/p/6346996.html
Copyright © 2011-2022 走看看