- 3
- 0
- 约26.48万字
- 约 60页
- 2017-06-13 发布于河南
- 举报
jxl作excel
用jxl读取excel的数据,由于excel数据在录入时的各种原因,数据后面都有空格,而且读出来以后(也许是编码原因),数据口面不是出 现?就是出现一个不知所谓的乱码符,不要考虑用替换,因为替换只有在你的项目编码方式和内存中excel数据编码方式一样的时候才能替换,否则你连保 存都会提示编码问题而保存不了。
直接用subSequence(0, cellContent.length()-1) 就可以了
同时提醒一下,读取出来的数据时Cell类型的话,直接getContent是可以得到内容的,但具体内容最好依靠下面的方法获
Java代码 ?
if?(cell.getType()?==?CellType.LABEL)?{??
????LabelCell?labelCell?=?(LabelCell)?cell;??
????String?cellContent?=?labelCell.getString();??
????cellContent?=?(String)?cellContent.subSequence(0,?cellContent.length()-1);??
????column_contents[cols]?=?cellContent;??
}else??
if?(cell.getType()?==?CellType.NUMBER)?{??
????????//number的话不用去空格就可以,我测试是这样??
????????NumberCell?numberCell?=?(NumberCell)?cell;??
????String?cellContent?=?numberCell.getContents();??
????column_contents[cols]?=?cellContent;??
}else??
if?(cell.getType()?==?CellType.DATE)?{??
????DateCell?dateCell?=?(DateCell)?cell;??
????Date?dateDemo?=?dateCell.getDate();??
????String?cellContent?=?dateDemo.toString();??
????column_contents[cols]?=?cellContent;??
}??
package com.study.poi;import java.io.File;import java.io.FileInputStream;import java.io.FileNotFoundException;import java.io.IOException;import java.io.InputStream;import java.text.DecimalFormat;import java.text.ParseException;import java.text.SimpleDateFormat;import java.util.ArrayList;import java.util.Date;import java.util.Iterator;import java.util.List;import org.apache.poi.hssf.usermodel.HSSFDateUtil;import org.apache.poi.hssf.usermodel.HSSFWorkbook;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;import com.study.entity.Emp;public class PoiExcelTest {??? public static void main(String[] args) {??? ??? Class[] clazz=new Class[]{Integer.class,String.class,String.class,Integer.class,Date.class,Double.class,Double.class,Integer.class};??? ??? ListEmp list=null;??? ??? DecimalFormat df=new Decim
原创力文档

文档评论(0)