我有个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”,麻烦高手帮忙解答下
jxl导入excel文件时对日期类型内容的处理问题
答案:2 悬赏:50 手机版
解决时间 2021-01-26 18:12
- 提问者网友:欲望失宠
- 2021-01-26 14:25
最佳答案
- 五星知识达人网友:何以畏孤独
- 2021-01-26 14:36
我做的一个例子 给你呵呵
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();
}
}
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();
}
}
全部回答
- 1楼网友:不甚了了
- 2021-01-26 15:04
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
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯