Excel Handle by org.apache.poi.xssf.usermodel.*

简介: <p></p><pre name="code" class="java">package shuai.study.excel.xssf;import java.io.BufferedInputStream;import java.io.File;import java.io.FileInputStream;import java.io.FileNotFoundException

package shuai.study.excel.xssf;

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;

import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

/**
 * @ClassName: ExcelHandle
 * @Description: Excel Handle
 * @author Zhou Shengshuai
 * @date 2014年9月17日 下午12:57:22
 * 
 */
public class ExcelHandle {
	private String filePath = null;

	public void setFilePath(String filePath) {
		this.filePath = filePath;
	}

	public void initialize() {
		this.excelRead();
	}

	public void destroy() {
	}

	public void excelRead() {
		File file = new File(filePath);

		if (file != null && file.exists()) {
			this.excelRead(file);
		}
	}

	private void excelRead(File file) {
		InputStream inputStream = null;

		try {
			inputStream = new FileInputStream(file);
			XSSFWorkbook xssfWorkbook = new XSSFWorkbook(new BufferedInputStream(inputStream, 65536));

			this.excelRead(xssfWorkbook);
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	private void excelRead(XSSFWorkbook xssfWorkbook) {
		for (int index = 0; index < xssfWorkbook.getNumberOfSheets(); index++) {
			XSSFSheet xssfSheet = xssfWorkbook.getSheetAt(index);

			this.excelRead(xssfSheet);
		}
	}

	private void excelRead(XSSFSheet xssfSheet) {
		XSSFCell xssfCell = null;
		XSSFRow xssfRow = null;

		for (int row = 1; row < xssfSheet.getLastRowNum(); row++) {
			xssfRow = xssfSheet.getRow(row);

			if (xssfRow != null) {
				for (int cell = 0; cell < xssfRow.getLastCellNum(); cell++) {
					xssfCell = xssfRow.getCell(cell);

					if (xssfCell != null) {
						System.out.print(xssfCell.toString() + "\t");
					} else {
						System.out.print("--" + "\t");
					}
				}

				System.out.println();
			}
		}
	}
}


相关文章
|
2天前
|
缓存 Java 网络安全
Solr7.4.0报错org.apache.solr.common.SolrException
在使用 Solr 7.4.0 时,`org.apache.solr.common.SolrException` 错误可能由多种原因引起,包括配置文件错误、核心未加载、权限问题、Java 环境问题、依赖库冲突和网络配置问题。通过检查配置文件、确保正确的权限、验证Java环境、解决依赖库冲突和检查网络配置,可以有效解决这些问题。结合日志文件、管理控制台和调试模式,可以快速定位和解决错误,确保 Solr 系统的稳定运行。
10 1
|
6月前
|
Java API Apache
Apache POI(Poor Obfuscation Implementation
Apache POI(Poor Obfuscation Implementation
149 0
|
7月前
|
Java 数据库连接 数据库
org.apache.ibatis.session.AutoMappingUnknownColumnBehavior
org.apache.ibatis.session.AutoMappingUnknownColumnBehavior
61 0
|
Java Apache
java word转html 报错org/apache/poi/xwpf/usermodel/IRunBody
java word转html 报错org/apache/poi/xwpf/usermodel/IRunBody
267 0
|
缓存 Java 编译器
【Java异常】Error:(19, 21) java: 无法访问org.apache.poi.xwpf.usermodel.ParagraphAlignment 找不到org.apache.po
【Java异常】Error:(19, 21) java: 无法访问org.apache.poi.xwpf.usermodel.ParagraphAlignment 找不到org.apache.po
363 0
|
easyexcel Java Apache
Apache POI和EasyExcel介绍
Apache POI和EasyExcel介绍
2305 0
Apache POI和EasyExcel介绍
|
数据库 数据安全/隐私保护
Java:org.apache.commons.collections4.MapUtils获取Map数据
Java:org.apache.commons.collections4.MapUtils获取Map数据
243 0