jxl 或者 poi 控制 excel 的时候, 需要写入一个 cell 内容为 时间 00:00:10 (Sample 10秒)  格式为[h]:mm:ss ------ 小时以上累加 分秒依旧我本身用Calendar.setTimeInMillis(0); 然后格式化 [h]:mm:ss由于java的时间为1970-1-1 8:00:00 起步 所以就算去掉8小时 excel 上显示的也是 1970-1-1 00:00:10如果用String 类型写入,那么出来的结果是对的  但是 所得到的数据 不能够进行 AVERAGE函数进行计算=AVERAGE(E2:E10) 的显示结果为 #DIV/0! ----E2到E10 都是String写入并转换成 [h]:mm:ss 的数据DateFormat df = new DateFormat("[h]:mm:ss");
WritableCellFormat wcf_df = new WritableCellFormat(nf);
wcf_df.setAlignment(Alignment.CENTRE);jxl.write.Label label_H = new jxl.write.Label(7, j+8, Util.changeDateFormat(s[6]),wcf_df);
ws.addCell(label_H);============================= Util. changeDateFormat 方法如下=======================
/**
 * @category 更改整数时间到时分秒
 * @return
 */
public static String changeDateFormat(String times){

if(times!=null&&!"".equals(times)){
String rtnStr = null;
if(times!=null&&!"".equals(times.trim())){
int all_time = Integer.parseInt(times);
String hour = "";
String minite = "";
String second = "";
minite = (all_time / 60)+"";
second = (all_time % 60)+"";
hour = (all_time / 3600)+"";

if(minite.length()==1)minite="0"+minite;
if(second.length()==1)second="0"+second;
rtnStr = hour+":"+minite+":"+second;
}
return rtnStr;
}else{
return "00:00:00";
}
}

解决方案 »

  1.   

    直接写一个date的对象不可以吗?
      

  2.   

    放入Date 的对象的话  显示出的日期 会包含  1970-1-1 00:00:10
      

  3.   

    DateFormat df = new DateFormat("[h]:mm:ss"); 这个就是 jxl.write.DateFormat
      

  4.   


    直接写入对象  会在excel里 显示的值里 带上时间为 1970-1-1 的 日期
      

  5.   

    写入DateTime,不是String至于你前面的需求,没看明白
      

  6.   


    是的, 用 DateTime 我也试过, 用DateTime 写入的时候 要求输入的值是一个 Date然后输入的Date 是包括 1970 的, 这样的话  即使excel 显示的是 00:00:10但是 在上方看到这个EXCEL的值  是1970-1-1 00:00:10
      

  7.   

    我之前是  jxl.write.DateFormat df = new jxl.write.DateFormat("[h]:mm:ss");
              Calendar calendar = Calengar.getInstance();
              calendar.setTimeInMillis(Integer.parse(s[6]) * 1000);
              
              jxl.write.DateTime dataTime_H = new jxl.write.DateTime(7, j+8, calendar.getTime(),wcf_df);
              ws.addCell(dataTime_H);