精华内容
下载资源
问答
  • java导入excel

    2014-08-15 15:08:38
    java导入excel
  • java 导入excel

    2012-07-26 11:54:33
    java 导入excel到数据库
  • java导入EXCEL

    2010-08-15 22:49:53
    lotus BS 通过 java导入EXCEL的数据到系统当中,
  • java导入Excel

    2016-05-10 11:30:41
    完美的实现了java代码将数据导入Excel或将Excel数据导入java后台
  • Java导入Excel

    2016-09-18 18:27:33
    Java解析Excel 使用poi 下面是两个实例(Excel2007) 写入Excel package execel01; import java.io.FileOutputStream; import java.io.IOException; import org.apache.poi.ss.usermodel....

    Java解析Excel

    使用poi

    下面是两个实例(Excel2007)

    写入Excel

    package execel01;
    
    import java.io.FileOutputStream;
    import java.io.IOException;
    
    import org.apache.poi.ss.usermodel.Cell;
    import org.apache.poi.ss.usermodel.CreationHelper;
    import org.apache.poi.ss.usermodel.Row;
    import org.apache.poi.ss.usermodel.Sheet;
    import org.apache.poi.ss.usermodel.Workbook;
    import org.apache.poi.xssf.usermodel.XSSFWorkbook;
    
    
    public class WriteExcel {
    	
    	public static void main(String[] args) throws IOException {
    
    
           Workbook wb = new XSSFWorkbook();
           CreationHelper creationHelper = wb.getCreationHelper();
           Sheet sheet = wb.createSheet("第一页");
           
           //创建行
           Row row = sheet.createRow((short)0);
           //创建单元格,方法1
           Cell cell = row.createCell(0);
           cell.setCellValue("1");
           //直接创建单元个,方法2
           row.createCell(1).setCellValue(1.2);
           row.createCell(2).setCellValue(creationHelper.createRichTextString("你好啊,我是bug"));
           row.createCell(3).setCellValue(creationHelper.createRichTextString("www.baidu.com"));
    	   row.createCell(4).setCellValue(true);
    	   
    	   //写入文件
    	   FileOutputStream fileOutputStream;
    	   fileOutputStream  = new FileOutputStream("F:\\java\\bug315.xlsx");
    	   
    	   wb.write(fileOutputStream);
    	   
           fileOutputStream.close();
           System.out.println("写入成功");
           
    	}
    
    }
    

    读取Excel

    package execel01;
    
    import java.io.FileInputStream;
    import java.io.IOException;
    import java.io.InputStream;
    import java.util.Iterator;
    
    import org.apache.poi.EncryptedDocumentException;
    import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
    import org.apache.poi.ss.usermodel.Cell;
    import org.apache.poi.ss.usermodel.DateUtil;
    import org.apache.poi.ss.usermodel.Row;
    import org.apache.poi.ss.usermodel.Sheet;
    import org.apache.poi.ss.usermodel.Workbook;
    import org.apache.poi.ss.usermodel.WorkbookFactory;
    
    public class ReadExcel {
    
    	public static void main(String[] args) throws EncryptedDocumentException,
    			InvalidFormatException, IOException {
    		// TODO Auto-generated method stub
    
    		InputStream in = new FileInputStream("F:\\java\\bug315.xlsx");
    
    		Workbook wb = WorkbookFactory.create(in);
    
    	
    		for (int i = 0; i < wb.getNumberOfSheets(); i++) {
    			
    			Sheet sheet = wb.getSheetAt(i);
    			System.out.println("\n\n\n");
    			System.out.println("=========="+sheet.getSheetName()+"================");
    			Iterator iterator = sheet.rowIterator();
    
    			while (iterator.hasNext()) {
    
    				Row row = (Row) iterator.next();
    				System.out.println();
    				System.out.print("第" + (row.getRowNum() + 1)
    						+ "行: ");
    				Iterator iteratorCell = row.cellIterator();
    				while (iteratorCell.hasNext()) {
    					Cell cell = (Cell) iteratorCell.next();
    
    					// 打印单元格的数据
    					switch (cell.getCellType()) {
    					case Cell.CELL_TYPE_STRING:
    						System.out.print(cell.getRichStringCellValue()
    								.getString() + " ");
    
    						break;
    					case Cell.CELL_TYPE_NUMERIC:
    						if (DateUtil.isCellDateFormatted(cell)) {
    							System.out.print(cell.getDateCellValue() + " ");
    						} else {
    							System.out.print(cell.getNumericCellValue() + " ");
    						}
    						break;
    					case Cell.CELL_TYPE_BOOLEAN:
    						System.out.print(cell.getBooleanCellValue() + " ");
    						break;
    					case Cell.CELL_TYPE_FORMULA:
    						System.out.print(cell.getCellFormula() + " ");
    
    					default:
    						break;
    					}
    
    				}
    
    			}
    		}
    
    	}
    
    }
    


    展开全文
  • Java 导入excel

    2016-07-09 14:48:29
    package com.wt.wkbox.common; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.math.BigDecimal; import java.util.Array
    
    package com.wt.wkbox.common;
    
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileNotFoundException;
    import java.io.IOException;
    import java.math.BigDecimal;
    import java.util.ArrayList;
    import java.util.List;
    
    import net.paoding.rose.web.Invocation;
    
    import org.apache.commons.lang.StringUtils;
    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;
    
    import com.wt.wkbox.common.util.IdTool;
    import com.wt.wkbox.model.basic.biz.WkboxMoneyConsumeView;
    import com.wt.wkbox.model.userManager.WkboxUser;
    
    /**
     * ClassName:Test <br/>
     * Function:  ADD FUNCTION. <br/>
     * Reason:	  ADD REASON. <br/>
     * Date:     2016年7月9日 下午2:26:13 <br/>
     * @author   wpengfei
     * @version  
     * @since    JDK 1.6
     * @see 	 
     */
    public class Test {
    	
    
    	public static List<WkboxMoneyConsumeView> getStudentFromExcel(String excelUrl) {
    		
    		excelUrl = "E:\\wkBox\\web\\wkBox-mobile-web\\trunk\\wkBox-web\\src\\main\\webapp\\upload\\1468043253038.xls";
    		
    		List<WkboxMoneyConsumeView> list=new ArrayList<WkboxMoneyConsumeView>();
    		
    		try {
    			//把一张xls的数据表读到wb里
    			HSSFWorkbook wb = new HSSFWorkbook(new FileInputStream(new File(excelUrl)));
    			 
    			//读取第一页,一般一个excel文件会有三个工作表,这里获取第一个工作表来进行操作    
    			HSSFSheet sheet = wb.getSheetAt(0);
    			//循环遍历表sheet.getLastRowNum()是获取一个表最后一条记录的记录号,
    			//如果总共有3条记录,那获取到的最后记录号就为2,因为是从0开始的
    			for(int j=1;j<sheet.getLastRowNum()+1;j++) {
    				//创建一个行对象
    				HSSFRow row = sheet.getRow(j);
    				
    				WkboxMoneyConsumeView consume = new WkboxMoneyConsumeView();
    				
    				//把一行里的每一个字段遍历出来
    				for(int i=0;i<row.getLastCellNum();i++) {
    					//创建一个行里的一个字段的对象,也就是获取到的一个单元格中的值
    					HSSFCell cell = row.getCell(i);
    					
    					if(cell==null ){
    						continue;
    					}
    					//在这里我们就可以做很多自己想做的操作了,比如往数据库中添加数据等
    					if(i == 0){
    						consume.setId(getValue(cell));
    					}else if(i == 1 ){
    					}else if(i == 2){
    					}else if(i == 3){
    						consume.setSchoolName(getValue(cell));
    					}else if(i == 4){
    					}else if(i == 5){
    					}else if(i == 6){
    					}else if(i == 7){
    					}
    				}
    				list.add(consume);
    				
    				}
    			} catch (FileNotFoundException e) {
    				e.printStackTrace();
    			} catch (IOException e) {
    				e.printStackTrace();
    			}finally{
    				File file=new File(excelUrl);
    //				file.delete();
    			}
    		
    		return list;
    			
    	}
    	
    	public static void main(String[] args) {
    		
    		List<WkboxMoneyConsumeView> list = getStudentFromExcel("1234");
    		
    		System.out.println(list.size());
    		
    		for(WkboxMoneyConsumeView consume : list){
    			
    			System.out.println(consume.getId()+": "+consume.getSchoolName());
    		}
    	}
    	
    	@SuppressWarnings("static-access")
    	private static String getValue(HSSFCell hssfCell) {
    	       if (hssfCell.getCellType() == hssfCell.CELL_TYPE_BOOLEAN) {
    	               return String.valueOf(hssfCell.getBooleanCellValue());
    	        } else if (hssfCell.getCellType() == hssfCell.CELL_TYPE_NUMERIC) {
    	                return String.valueOf(hssfCell.getNumericCellValue());
    	        } else {
    	             return String.valueOf(hssfCell.getStringCellValue());
    	        }
    	    
    	  }
    	
    }
    
    

    展开全文
  • Java导入excel文件

    2017-12-13 15:16:17
    Java导入excel文件,里面是一个完整的Java项目,包括了需要的jar包
  • JAVA导入Excel文件

    2017-10-11 16:26:47
    JAVA导入Excel文件

    “落叶他乡树,寒灯独夜人”
    JSP:

    <div id="excelUser" title="excel导入"
         style="display: none; width: 350px; height: 150px; padding: 15px; background: #E9F1FF;">
        <form id="excelUserForm" method="post" enctype="multipart/form-data"
              action="">
            <table cellspacing='0' cellpadding='1'>
                <tr>
                    <td style="text-align: left; font-size: 12px;">选择excel文件:</td>
                    <td><input style="width: 200px;" type="file"
                               class="input easyui-validatebox" id="excelfile" name="excelfile"
                               required="required" />
                    </td>
                </tr>
                <tr>
                    <td colspan="2" style="text-align: left; font-size: 12px;"><span
                            style="color: red">注:请选择后缀名为xlsx文件,否则无法导入。</span></td>
                </tr>
            </table>
        </form>
    </div>

    JS:

    /**
     * 上传方法
     */
    function doImport() {
        $('#excelUser').show().dialog({
            modal : true,
            toolbar : [ {
                text : '提交',
                iconCls : 'icon-ok',
                handler : function() {
                    $('#excelUserForm').form('submit', {
                        url : 'controller/clientActivityHotInfoManage/import.json',
                        onSubmit : function() {
                            parent.$.messager.progress({
                                title : '提示',
                                text : '数据导入中,请稍等....'
                            });
                            var isValid = $('#excelUserForm').form('validate');
                            if (!isValid) {
                                parent.$.messager.progress('close');
                                return false;
                            }
                        },
                        success : function(response) {
                            $('#excelUser').dialog('close');
                            var response = eval('(' + response + ')');
                            parent.$.messager.progress('close');
                            if (response.success) {
                                $.messager.alert('成功', response.msg, 'info');
                                $('#subjectGrid').datagrid('reload');
                                // doAuto();
    
                            } else {
    
                                $.messager.alert('失败', response.msg, 'error');
                            }
                            $('#projectStageConfig').datagrid('load', {
                                id : $.trim($('#id').val())
                            });
                        },
                        failure : function(response) {
                            parent.$.messager.progress('close');
                            $('#excelUser').dialog('close');
                            $.messager.alert('失败', response.msg, 'error');
                        }
                    });
    
                }
    
            }, {
                text : '关闭',
                iconCls : 'icon-cancel',
                handler : function() {
                    $('#excelUser').dialog('close');
                }
            } ]
    
        });
    }

    Controller:

    @CodeComments("导入EXCEL到表中")
        @RequestMapping({"/import.json"})
        @ResponseBody
        public void importExcel(MultipartHttpServletRequest request, HttpServletRequest request1, HttpServletResponse response, ClientActivityHotInfoManage eui, Integer egroupid)
        {
            Map messages = new HashMap();
            MultipartFile file = request.getFile("excelfile");
            String inputPath = file.getOriginalFilename();
            System.out.println("inputPath=========================" + inputPath);
            String originalFile = inputPath.substring(
                    inputPath.lastIndexOf(".") + 1, inputPath.length())
                    .toLowerCase();
    
            if ("xls,xlsx".indexOf(originalFile) < 0) {
                messages.put("success", Boolean.valueOf(false));
                messages.put("msg", "文件导入类型错误,只能导入后缀名是xlsx的EXCEL文件类型!");
                toJson(response, messages);
                return;
            }
            if ("xls".equals(originalFile)) {
                messages.put("success", Boolean.valueOf(false));
                messages.put("msg", "文件导入类型错误,只能导入后缀名是xlsx的EXCEL文件类型!");
                toJson(response, messages);
                return;
            }
            if (file.getSize() > 20048576L) {
                messages.put("success", Boolean.valueOf(false));
                messages.put("msg", "文件过大,只能导入20M内文件!");
                toJson(response, messages);
                return;
            }
    
            int i = 0;
            try
            {
                InputStream fis = file.getInputStream();
            //这个方法在下面展示
                List imielist = ActivityHotInfoExcelManage.importExcelInfo(fis, eui);
    
                ClientActivityHotInfoManage order = new ClientActivityHotInfoManage();
    
    
                for (i = 0; i < imielist.size(); i++)
                {
                    ClientActivityHotInfoManage vo = (ClientActivityHotInfoManage)imielist.get(i);
                    ClientActivityHotInfoManage lx = new ClientActivityHotInfoManage();
    
                    lx.setAcId(vo.getAcId());
                    lx.setAcUrl(vo.getAcUrl());
                    lx.setStartDate(vo.getStartDate());
                    lx.setEndDate(vo.getEndDate());
                    lx.setRepeat(vo.getRepeat());
                    lx.setStatus(vo.getStatus());
                    lx.setPlotId(vo.getPlotId());
                    lx.setAcName(vo.getAcName());
    
    
    //这里就可以直接插入实体类了             this.clientActivityHotInfoManageService.insert(lx);
    
                    messages.put("success", Boolean.valueOf(true));
                    messages.put("msg", "数据导入成功!");
                }
                fis.close();
            }
            catch (Exception e) {
                messages.put("success", Boolean.valueOf(false));
                messages.put("msg", "导入异常,请在检查excel表的第" + (i + 2) + "行后,从第" + (
                        i + 2) + "行开始导入!");
                System.out.println("importExcel异常--------->" + e.getMessage());
            }
            toJson(response, messages);
        }

    importExcelInfo方法

    public static List<ClientActivityHotInfoManage> importExcelInfo(InputStream fis, ClientActivityHotInfoManage eui)
        {
            List<ClientActivityHotInfoManage> excelInfos = new ArrayList<ClientActivityHotInfoManage>();
            try
            {
                XSSFWorkbook hwb = new XSSFWorkbook(fis);
    
                XSSFSheet sheet = hwb.getSheetAt(0);
                XSSFRow row = null;
    
                System.out.println("*****总行数****" + sheet.getPhysicalNumberOfRows());
    
                for (int i = 0; i < hwb.getNumberOfSheets(); i++) {
                    sheet = hwb.getSheetAt(i);
    
                    for (int j = 1; j < sheet.getPhysicalNumberOfRows(); j++)
                    {
                        row = sheet.getRow(j);
                        ClientActivityHotInfoManage excelInfo = new ClientActivityHotInfoManage();
    
                        if ((row.getCell(1) != null) &&
                                (getCellValue(row.getCell(1)) != "")) {
    
                            excelInfo.setAcId(getCellValue(row.getCell(1)).trim());
                            excelInfo.setAcUrl(getCellValue(row.getCell(2)).trim());
                            excelInfo.setStartDate(getCellValue(row.getCell(3)).trim());
                            excelInfo.setEndDate(getCellValue(row.getCell(4)).trim());
                            excelInfo.setRepeat(Long.parseLong(getCellValue(row.getCell(5)).trim().substring(0,1)));
                            excelInfo.setStatus(Long.parseLong(getCellValue(row.getCell(6)).trim().substring(0,1)));
                            excelInfo.setPlotId((getCellValue(row.getCell(7)).trim()));
                            excelInfo.setAcName((getCellValue(row.getCell(8)).trim()));
                        }
    
                        excelInfos.add(excelInfo);
                    }
    
                }
    
                return excelInfos;
            }
            catch (Exception e) {
                System.out.println("导入EXCEL文件出错------------>" + e.getMessage());
            }
            return null;
        }
    展开全文
  • 主要介绍了java 导入Excel思路及代码示例,简要分析了设计思路,然后分享了实例代码,具有一定参考价值,需要的朋友可以了解下。
  • java导入Excel需要的jar包
  • 1.[文件] jxl-2.6.jar~645KB 下载(124)2.[代码]将excel表格内容解析为listpackage com.utils;import java.io.File;import java.util.ArrayList;import java.util.List;import jxl.Sheet;import jxl.Workbook;import ...

    1.[文件] jxl-2.6.jar ~ 645KB     下载(124)

    2.[代码]将excel表格内容解析为list

    package com.utils;

    import java.io.File;

    import java.util.ArrayList;

    import java.util.List;

    import jxl.Sheet;

    import jxl.Workbook;

    import com.jiumai.shgold.model.aboutas.AboutAs;

    public class Test {

    /**

    * 查询指定目录中电子表格中所有的数据

    * @param file 文件完整路径

    * @return

    */

    public static List getAllByExcel(String file){

    List list=new ArrayList();

    try {

    Workbook rwb=Workbook.getWorkbook(new File(file));

    Sheet rs=rwb.getSheet(0);

    int clos=rs.getColumns();//得到所有的列

    int rows=rs.getRows();//得到所有的行

    System.out.println(clos+" rows:"+rows);

    for (int i = 1; i < rows; i++) {

    for (int j = 0; j < clos; j++) {

    //第一个是列数,第二个是行数

    String id=rs.getCell(j++, i).getContents();//默认最左边编号也算一列 所以这里得j++

    String name=rs.getCell(j++, i).getContents();

    String sex=rs.getCell(j++, i).getContents();

    String num=rs.getCell(j++, i).getContents();

    AboutAs as = new AboutAs();

    as.setContent(name);

    list.add(as);

    }

    }

    } catch (Exception e) {

    // TODO Auto-generated catch block

    e.printStackTrace();

    }

    return list;

    }

    public static void main(String[] args) {

    //得到表格中所有的数据

    List listExcel=getAllByExcel("D://test.xls");

    /*//得到数据库表中所有的数据

    List listDb=StuService.getAllByDb();*/

    for (AboutAs stuEntity : listExcel) {

    System.out.println(stuEntity.getContent());

    }

    }

    }

    展开全文
  • Java导入Excel文件返回数据对应属性类字段,Java导出Excel文件如何让数据对应指定的标题字段-附件资源
  • java导入Excel 所需的jar包 内含 poi , jxl , dom4j , xmlbeans
  • java 导入excel csv

    2018-10-26 22:36:09
    简单好用的java 导入 excel csv工具类  注解类 package com.wl.poi.read.annotation; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation....
  • java导入excel工具jar包

    2013-10-12 10:47:39
    java导入excel工具包2.0。修改了许多BUG,增加了许多功能
  • JAVA 导入 Excel 报错如下:java.io.IOException: Zip bomb detected!Exception in thread "main" java.io.IOException: Failed to read zip entry sourceat org.apache.poi.openxml4j.opc.ZipPackage.(ZipPackage....
  • java导入excel文件的数据 实现java批量导入excel文件能让我们在处理数据方面带来了很多方便之处。 Apache POI是Apache软件基金会的开放源码函式库,POI提供API给Java程序对Microsoft Office格式档案读和写的功能。 ...
  • 今天小编就为大家分享一篇解决Java导入excel大量数据出现内存溢出的问题,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
  • Java导入excel到数据库

    2019-11-26 10:17:38
    Java导入excel <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi</artifactId> <version>3.17</version> </dependency> //...
  • 导入数据这边总是不熟悉,大家有没有Java导入 excel 表格到数据库的例子,详细一点,谢谢热心人啦
  • java导入excel源码下载

    2019-03-12 14:51:32
    java导入excel源码下载 解决方法: 1.下载一下java包: xmlbeans-2.3.0.jar xercesImpl.jar poi-ooxml-schemas-3.8.jar poi-ooxml-3.8.jar poi-3.8.jar dom4j-1.6.1.jar 2.源码下载:...
  • java导入excel文件.txt

    2020-01-09 11:09:46
    java实现页面导入excel文件,保存excel文件到数据库,有需要在页面上导入一个excel表的同学可以借鉴

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 8,846
精华内容 3,538
关键字:

java导入excel

java 订阅