`
小女墙
  • 浏览: 111263 次
  • 性别: Icon_minigender_2
  • 来自: 北京
社区版块
存档分类
最新评论

jxl读取excel时中文全角空格问题

    博客分类:
  • JAVA
阅读更多

用jxl读取excel的数据,由于excel数据在录入时的各种原因,数据后面都有空格,而且读出来以后(也许是编码原因),数据口面不是出现"?"就是出现一个不知所谓的乱码符,不要考虑用替换,因为替换只有在你的项目编码方式和内存中excel数据编码方式一样的时候才能替换,否则你连保存都会提示编码问题而保存不了。

直接用subSequence(0, cellContent.length()-1) 就可以了

同时提醒一下,读取出来的数据时Cell类型的话,直接getContent是可以得到内容的,但具体内容最好依靠下面的方法获

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;
}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics