读书人

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

发布时间: 2012-10-17 10:25:46 作者: rapoo

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

用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;}elseif (cell.getType() == CellType.NUMBER) {        //number的话不用去空格就可以,我测试是这样?       NumberCell numberCell = (NumberCell) cell;String cellContent = numberCell.getContents();column_contents[cols] = cellContent;}elseif (cell.getType() == CellType.DATE) {DateCell dateCell = (DateCell) cell;Date dateDemo = dateCell.getDate();String cellContent = dateDemo.toString();column_contents[cols] = cellContent;}

读书人网 >编程

热点推荐