JXL 写excel文件时string和nubmer类型混乱,网上都搜不到解决办法WritableSheet sheet = wb.createSheet(sheeetName, this.currentSheetIndex);
Label label = new Label(columnIndex, lineIndex, "001111");
label.addCellFeatures();
sheet.addCell(label);label 加入sheet中, "00111"在excel只能看到111,好象是被认为数字型的了,查了很多资料都找不到解决的办法,不知道大家有没有碰到过这个问题
Label label = new Label(columnIndex, lineIndex, "001111");
label.addCellFeatures();
sheet.addCell(label);label 加入sheet中, "00111"在excel只能看到111,好象是被认为数字型的了,查了很多资料都找不到解决的办法,不知道大家有没有碰到过这个问题
解决方案 »
- 哎,,百度上查不到,还是上来问问!
- 我想下载Access2003工具
- 急!请教java+servlet+jdbc+ecplice+tomcat网站后台制作问题
- 高手帮忙!
- 我的jxl.jar(jexcelapi)包不能import导入,究竟是什么原因啊?
- 关于jmf框架中的rtp视频编码、解码程序如何编写
- 怎么显示不正确啊?请指点!
- 我装了Tomcat4.1.24和Apache2.0.48,现在我想装一个IIS,怎么配置?
- 帮帮忙:)
- ==和equals()有多少区别,为什么if (chkfj=="you")和if (chkfj.equals(you))结果不一样
- html转成JSP格式乱码问题!
- java开发的局域网web项目中如何嵌入类似QQ的即时通讯功能?
查了很多资料,还是没有找到实现 CellFormat的 text类型的类, 谁有这样的例子,可以给一个吗
import java.io.File;
import java.io.IOException;import jxl.CellView;
import jxl.Workbook;
import jxl.WorkbookSettings;
import jxl.format.Colour;
import jxl.write.Label;
import jxl.write.WritableCellFormat;
import jxl.write.WritableFont;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;
import jxl.write.WriteException;public class TEST {
private static void writeLabelsSheet(WritableSheet ws) throws WriteException {
ws.getSettings().setProtected(true);
ws.getSettings().setPassword("jxl");
ws.getSettings().setVerticalFreeze(5);
ws.getSettings().setDefaultRowHeight(25 * 20);
WritableFont wf = new WritableFont(WritableFont.ARIAL, 12);
wf.setItalic(true);
WritableCellFormat wcf = new WritableCellFormat(wf);
CellView cv = new CellView();
cv.setSize(25 * 256);
cv.setFormat(wcf);
ws.setColumnView(0, cv);
ws.setColumnView(1, 15);
for (int i = 0; i < 10; i++) {
Label l1 = new Label(0, i, "00455");
Label l2 = new Label(1, i, "Distinct label number " + i);
ws.addCell(l1);
ws.addCell(l2);
}
Label l3 = new Label(0, 10, "Common Label", wcf);
Label l4 = new Label(1, 10, "1-1234567890", wcf);
Label l5 = new Label(2, 10, "2-1234567890", wcf);
ws.addCell(l3);
ws.addCell(l4);
ws.addCell(l5);
wf = new WritableFont(WritableFont.TIMES, 10, WritableFont.BOLD);
wf.setColour(Colour.RED);
WritableCellFormat wcf2 = new WritableCellFormat(wf);
wcf2.setWrap(true);
Label l = new Label(0, 12, "Different format", wcf2);
ws.addCell(l);
Label l6 = new Label(5, 2, "A column for autosizing", wcf2);
ws.addCell(l6);
l6 = new Label(5, 4, "Another label, longer this time and in a different font");
ws.addCell(l6);
CellView cf = new CellView();
cf.setAutosize(true);
ws.setColumnView(5, cf);
} public static void main(String[] args) {
WorkbookSettings ws = new WorkbookSettings();
WritableWorkbook workbook;
try {
workbook = Workbook.createWorkbook(new File("t.xls"), ws);
WritableSheet s = workbook.createSheet("Labels", 0);
writeLabelsSheet(s);
workbook.write();
workbook.close();
} catch (IOException e) {
e.printStackTrace();
} catch (WriteException e) {
e.printStackTrace();
}
}
}
一个是在label构造的时候,指定为处理文字型的构造器
一个是构造好了以后再设定单元格属性,比如类似于
label.setCellStyle(CellStyle.STRING); 楼主可以找一下,相信一定有的
WritableFont wf = new WritableFont(WritableFont.ARIAL, 12);
wf.setItalic(true);
WritableCellFormat wcf = new WritableCellFormat(wf);
Label label = new Label(columnIndex, lineIndex, "001111", wcf);
后,输出在excel的内容显示是没有问题了,但是当我在excel中编辑CELL ("001111") TO ("00222"), 离开ell后,就又变成了"222"
所以上面的方法也不是完美的!
感谢这位朋友的宝贵意见,中午我试了下POI,如你所说,是可以的,而且没有我说的第二个问题(在excel中编辑CELL ("001111") TO ("00222"), 离开ell后,就又变成了"222")
因为对程序中出现问题很执着,所以要是有朋友有JXL更正确的解决方法请贡献出来与大家分享一下,我不是偷懒,自己和几个同事已经一起帮忙找了很久,所以你要是碰到过,那就赶快...:)