Parse EXCEL usint Apache POI-HSSF and POI-XSSF

Categories: Java; Tagged with: ; @ July 27th, 2012 8:24

HSSF is the POI Project’s pure Java implementation of the Excel ’97(-2007) file format. XSSF is the POI Project’s pure Java implementation of the Excel 2007 OOXML (.xlsx) file format. HSSF and XSSF provides ways to read spreadsheets create, modify, read and write XLS spreadsheets.

 

package com.test;

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

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.xssf.usermodel.XSSFWorkbook;

public class HSSFTest {
	public static void main(String[] args) {
		String xlsName = "D:/justForTest.xlsx";
		FileInputStream fis;
		try {
			fis = new FileInputStream(xlsName);
			Workbook workbook = new XSSFWorkbook(fis);
			
			// Get the first sheet;
			Sheet sheet = workbook.getSheetAt(0);
			
			// for each row
			for(Row row : sheet) {
				Cell cell = row.getCell(0); // get the cell
				// print cell contents.
				System.out.println(cell.getStringCellValue());
			}
			
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}

数字到Excel列名对照表 Number to Excel Column Name Quick Reference Card

Categories: 分享; Tagged with: ; @ November 6th, 2011 16:39

The title tells everything.
from 0(A) to 103(CZ), one page, PDF, A4.

and the Excel Formula is:
=IF(A1>25,CHAR(INT(A1/26)+64),””)&CHAR(MOD(A1-0,26)+65)

Download Link:
Sina Weibo China: http://dl.dbank.com/s0xaqdngd8

Excel提取两列重复/不同数据

Categories: Development Notes; Tagged with: ; @ February 27th, 2011 14:30

需求: 找出两列中重复的数据, 以及差异的数据.
细节: AB两列, 找出A有B无, AB均有, A无B有数据, 分列CDE中.

A有B无: IF(COUNTIF($B:$B,A2)=0,A2,"B列中已有")
AB均有:IF(COUNTIF($B:$B,A2)>0,"AB有重复","B中无匹配")
A无B有: IF(COUNTIF($A:$A,B2)=0,B2,"A中有重复")

image

Excel字符串操作: 字符串截取

Categories: Development Notes; Tagged with: ; @ February 25th, 2011 15:38

常用方法:

MID(text,start_num,num_chars), 如: =MID(A2,3,1), 截取A2单元格: 从第3个字符开始, 截取一个.

LEFT(text,num_chars), 如:=LEFT(A2, 2),截取A2单元格左侧链两个字符; 类似的有:

RIGHT(text,num_chars).

可与Find()等方法嵌套使用, 如:

=MID(A1,1,FIND("!",A1)-1): 找到A1单元格中第一个!的位置, 进行截取.

image

更多Excel文本函数可参考: http://office.microsoft.com/zh-cn/excel-help/HP010342953.aspx

Newer Posts



// Proudly powered by Apache, PHP, MySQL, WordPress, Bootstrap, etc,.