永发信息网

jxl导入excel文件时对日期类型内容的处理问题

答案:2  悬赏:50  手机版
解决时间 2021-01-26 18:12
我有个excel模板文件。里面有日期类型的列,使用
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Date date = sdf.parse(cell.getContents())
原本日期为“2008-3-24”,使用转化以后sdf.format(date)变成了“0008-3-24”
请问这个问题该怎么解决呢~

yimin = new YiminInfo();
//省略了一部分(字数被限)
yimin.setMz(cells[19].getType() == CellType.EMPTY ? null:cells[19].getContents());
yimin.setBz(cells[20].getType() == CellType.EMPTY ? null:cells[20].getContents());
yimin.setVillage(sheet.getName());

SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
yimin.setZxsj(cells[12].getType() != CellType.DATE ? null: sdf.parse(cells[12].getContents()));
yimin.setHdrq(cells[17].getType() != CellType.DATE ? null:sdf.parse(cells[17].getContents()));
yimin.setBqrq(cells[18].getType() != CellType.DATE ? null:sdf.parse(cells[18].getContents()));

dao.save(yimin);
这段代码保存到数据库以后,数据库里面保存的时间就跟我上面描述的一样
“2008-3-24”变成了“0008-3-24”,麻烦高手帮忙解答下
最佳答案
我做的一个例子 给你呵呵
package ASD;
import java.io.*;
import java.util.ArrayList;
import jxl.*;
import jxl.write.Label;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;

public class NewT {
public static int v=0;
public void painting(String test1,String test2) throws Exception {
Workbook rwb = Workbook.getWorkbook(new File(test1));
Sheet sheet = rwb.getSheet("Sheet1");// 由指定sheet名获得工作簿表单对象
OutputStream os = new FileOutputStream(test2);//输出的Excel文件URL
WritableWorkbook wwb = Workbook.createWorkbook(os);//创建可写工作薄
WritableSheet ws = wwb.createSheet("sheet1", 1);//创建可写工作表
int rowss = sheet.getRows();
int columns = sheet.getColumns();
ArrayList list =new ArrayList();
int j;
int h;

//DAO dao=new DAO();
for (j = 0; j < rowss; j++) {

for (h = 0; h < columns; h++) {

Cell cellg = sheet.getCell(0, j);
String g = cellg.getContents();
Cell cellh = sheet.getCell(h, 0);
String s = cellh.getContents();
if (s.equals("end")&&g.endsWith("end")) {
for (int k = 4; k < h; k++) {
for (int x = 1; x < j; x++) {

//System.out.println("");
Cell cells1 = sheet.getCell(0, x);//物料长代码
Cell cells2 = sheet.getCell(1, x);//项目型号
Cell cells3 = sheet.getCell(2, x);//描述
Cell cells4 = sheet.getCell(3, x); //总数
Cell cells5 = sheet.getCell(k, 0);//地址
Cell cells6 = sheet.getCell(k,x);//局点数

String cell1 = cells1.getContents();
String cell2 = cells2.getContents();
String cell3 = cells3.getContents();
String cell4 = cells4.getContents();
String cell5 = cells5.getContents();
String cell6 = cells6.getContents();
if(cell6.equals("0")){
System.out.print("");
}
else{

v++;
//System.out.print("行"+x+" 列"+k+" " );
//System.out.print(cell1+" ");
//System.out.print(cell2+" ");
// System.out.print(cell3+" ");
//System.out.print(cell4+" ");
// System.out.print(cell5+" ");
// System.out.print(cell6+" ");
Label a=new Label(0,v,cell1);
// System.out.print(cell1);
Label b=new Label(1,v,cell5);
// System.out.print(cell5);
Label c=new Label(2,v,cell6);
Label d=new Label(3,v,cell2);
Label e=new Label(4,v,cell3);
Label f=new Label(5,v,cell4);
// System.out.print(v+" ");
// System.out.println(cell6);
ws.addCell(a);
ws.addCell(b);
ws.addCell(c);
ws.addCell(d);
ws.addCell(e);
ws.addCell(f);

}

}
}
//list.add(si);
wwb.write();
wwb.close();
os.close();
//System.out.print("h:" + h);
//System.out.println("j:" + j);
}
}
}
}

public static void main(String args[]) throws Exception {

NewT t = new NewT();
//t.painting();

}
}
全部回答
Over the years, sunglasses symbolize the style quotient for people aspiring to make a statement through the apparels they wear. However, observing the trends during the recent years, it can be safely concluded that sunglass fashion changes more frequently than the minds of the people. In other words, the latest fashion starts waning within a few days of its launch. Reason? The fashionistas are innovating and experimenting with new designs of sunglasses at an alarming speed. Thus, the sunglass that you’ve bought today may not last, fashion-wise, for more than a few weeks. Thus, a need for all-season sunglasses can never be overemphasized. Latest Gucci sunglasses, however, have that style, which can last for years. You don’t have to look for a new pair of sunglasses every 3 months. Just buy one of the cheap replica Gucci sunglasses and relax for at least a year. Another major consideration that could keep the fashion conscious interested in designer inspired Gucci sunglasses instead of the authentic ones is the price that could be 10-15 times lower. Moreover, if you are looking to buy authentic Gucci sunglasses for every season, the amount of extra dollars you will be spending is anyone’s guess. The question that arises is why should you even consider buying expensive designer sunglasses? When cheap discount Gucci sunglasses are available in same quality, style and fractional prices? Though these sunnies are imitation Gucci, yet they carry the same sex appeal as Tom Cruise oozes while wearing the famous Gucci 1873 aviator style sunshades. Available in rimmed, semi-rimmed, and rimless models, inspire by Gucci sunglasses is an obvious choice for those looking to appear trendy without spending too much and without bothering about the seasons. These replicas are equally durable, if not more, as the authentic ones. In other words, the imitation Gucci sunglasses are exact copies of the authentic designer sunglasses but with an enviable price tag that is one-twelfth of the original’s cost. Moreover, to top it all, these choicest replicas will serve you season after season without compromising on your style quotient in the peer circle. The best approach is to buy 2-3 replica Gucci sunglasses and wear them alternatively so that you appear in sync with the latest fashion trends. Look Trendy All Season Long with Latest Replica Gucci Sunglasses Over the years, sunglasses symbolize the style quotient for people aspiring to make a statement through the apparels they wear
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
大学毕业后工作一年多,想换工作了,好迷茫
穿越类的历史小说,要精品的
爱吧酒吧地址在什么地方,想过去办事
关于中国、日本、印度、美国四国的说法,正确
苹果6s和plus信号都不好吗?
怎样把人造指甲弄在手上,而且固定???
迥胜的意思是什么啊?知道的请说下!
【cad成组快捷键】在派生式CAPP系统中利用分
曲江池遗址公园观光小火车怎么样
佳木斯至福州经过那些站
175的身高,怎么从130斤减到115斤。
二十年前的西铁城机械表摇一摇就可以走值多少
烈焰 鬼服
马桶胶和地板砖用玻璃胶粘住了,怎么样可以拆
以今天我发现了( )写一篇作文
推荐资讯
WOW上去之后点开别人发的一个成就或者一个专
Excel 已解决为什么我不能替换呢
增光台球厅地址在哪,我要去那里办事
按照部首检字法,"兴"字应查( )部
m2固态硬盘能否代替内存?不能通过修改bios实
宜昌市有多少人
“如果每一个人都能看透其他所有人的心思,那
胜利地板砖地址在什么地方,我要处理点事
火车头采集软件采集图片出现下面的问题,状态
现在还可以免费升级win10吗,在官网看见辅助
0.99x10.1怎么巧算
洪昭光·张永国际养生中心(衡王府路店)怎
正方形一边上任一点到这个正方形两条对角线的
阴历怎么看 ?