`

poi

poi 
阅读更多

导入excel需要的\poi-ooxml-schemas-3.8-20120326.jar

-------------------------------转载--------------------------------

http://yingpengfei1215.iteye.com/blog/1600585

 

excel poi

 

jar包:

 

poi-3.8-20120326.jar

poi-examples-3.8-20120326.jar

poi-ooxml-3.8-20120326.jar

poi-ooxml-schemas-3.8-20120326.jar

dom4j-1.6.1.jar

stax-api-1.0.1.jar

xmlbeans-2.3.0.jar

commons-logging-1.1.jar

junit-3.8.1.jar

log4j-1.2.13.jar

官方下载地址:http://poi.apache.org/download.html

package com.ying.hss;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.text.SimpleDateFormat;

import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFDateUtil;
import org.apache.poi.ss.usermodel.Cell;
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 ExcelImport {

    public static void main(String[] args) {
        FileInputStream in = null;
        try {
            File file = new File("my.xlsx");
            in = new FileInputStream(file);

            Workbook wb = WorkbookFactory.create(in);

            Sheet sheet = wb.getSheetAt(0);

            for (Row row : sheet) {
                int i = row.getRowNum();
                if (i == 0 || i == 1) {
                    continue;
                }
                for (Cell cell : row) {

                    switch (cell.getCellType()) {
                        case HSSFCell.CELL_TYPE_NUMERIC: // 数字 

                            Object value;
                            if (HSSFDateUtil.isCellDateFormatted(cell)) {

                                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

                                //  如果是date类型则 ,获取该cell的date值 
                                value = sdf.format(HSSFDateUtil.getJavaDate(cell
                                    .getNumericCellValue()));
                            } else { // 纯数字 
                                value = Double.parseDouble(String.valueOf(cell
                                    .getNumericCellValue()));
                            }
                            System.out.print(value + "   ");
                            break;
                        case HSSFCell.CELL_TYPE_STRING: // 字符串 
                            System.out.print(cell.getStringCellValue() + "   ");
                            break;
                        case HSSFCell.CELL_TYPE_BOOLEAN: // Boolean 
                            System.out.println(cell.getBooleanCellValue() + "   ");
                            break;
                        case HSSFCell.CELL_TYPE_FORMULA: // 公式 
                            System.out.print(cell.getCellFormula() + "   ");
                            break;
                        case HSSFCell.CELL_TYPE_BLANK: // 空值 
                            System.out.println(" ");
                            break;
                        case HSSFCell.CELL_TYPE_ERROR: // 故障 
                            System.out.println(" ");
                            break;
                        default:
                            System.out.print("未知类型   ");
                            break;
                    }
                }
                System.out.println(" ");
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {

            if (in != null) {
                try {
                    in.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }

    }
}

 

 

分享到:
评论

相关推荐

    POI导出 POI导出 POI导出

    POI导出POI导出POI导出POI导出POI导出POI导出POI导出POI导出POI导出POI导出POI导出POI导出POI导出POI导出POI导出POI导出POI导出POI导出POI导出POI导出POI导出POI导出POI导出POI导出POI导出POI导出POI导出POI导出POI...

    poi全家桶ooxml-schemas/poi/poi-examples/poi-ooxml/poi-ooxml-schemas/poi-scratchpad

    标题中的"poi全家桶ooxml-schemas/poi/poi-examples/poi-ooxml/poi-ooxml-schemas/poi-scratchpad"提及的是Apache POI项目中的多个关键组件和目录结构。Apache POI是一个开源的Java库,专门用于读写Microsoft Office...

    POI3.7/POI3.8/POI3.9

    Apache POI 是一个开源项目,专门用于处理Microsoft Office格式的文件,如Excel、Word和PowerPoint。POI库为Java开发者提供了读写Microsoft Office文档的能力,使得在Java应用程序中操作这些文件变得简单。这里提到...

    POI poi相关所有jar包 poi jar包 poi最全jar包

    Apache POI 是一个开源项目,专门用于处理Microsoft Office格式的文件,如Excel(.xlsx、.xls)、Word(.doc、.docx)和PowerPoint(.ppt、.pptx)。这个压缩包包含了POI项目中所有必要的jar包,总计十二个,确保了...

    POI中文帮助文档_POI_

    Apache POI是一个开源项目,主要用于读取和写入Microsoft Office格式的文件,如Word(.doc/.docx)、Excel(.xls/.xlsx)和PowerPoint(.ppt/.pptx)。这个“POI中文帮助文档”提供了全面的指南,帮助开发者理解和...

    poi-3.17 poi-3.16

    Apache POI 是一个开源项目,专门用于处理微软的Office文档格式,如Excel、Word和PowerPoint。POI 提供了一套 Java API,使得开发者可以在Java应用程序中读写Microsoft Office格式的文件。标题中的"poi-3.17 poi-...

Global site tag (gtag.js) - Google Analytics