从excel导入mysql数据库库mysql怎么输出时间与日期到excel

4453人阅读
& & & 今天项目表中需要导入好几w条数据 ,但日期由两个一个是标准时间一个为时间戳,程序中搜索是根据时间戳来搜索的,所以在网上翻箱倒柜的终于找到解决之道了,利用excel转换时间戳
时间戳转成正常日期的公式:
B1=(A1+8*+70*365+19
其中A1表示当时的数值
其中B1就是你需要的结果,B1单元格属性改成日期格式就可以了。
正常日期转为时间戳格式公式:
A1=(C1-70*365-19)*0
其中C1表示当时的数值
其中A1就是你需要的结果,A1单元格属性日期格式转成数据格式就可以了。
如图所示是把C1中的标准时间 & &10:30:00 转换为时间戳 &公式A1=(C1-70*365-19)*0
下图为A1中的时间戳转换为标准时间 &10:30:00
&&相关文章推荐
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场> 博客详情
* 将已选题信息导出为Excel文档
* @param mapping
* @param form
* @param request
* @param response
* @throws Exception
public ActionForward exExcel(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
Integer cid = Integer.valueOf(request.getParameter("cid"));
College col = collegeDao.findByID(cid);
List&Choices& list = choicesDao.findByCIDCho(col);
String filename = list.get(0).getStudent().getGrade().getGname() + "级"
+ col.getCname();
response.setContentType("text/charset=GBK");
response.setContentType("application/xml");
response.setHeader("Content-Disposition", "filename="
+ new String(filename.getBytes(), "iso-8859-1") + ".xls");
HSSFWorkbook workBook = new HSSFWorkbook(); // 创建 一个excel文档对象
HSSFSheet sheet = workBook.createSheet(); // 创建一个工作薄对象
HSSFCell cell = // 声明单元格对象
sheet.setColumnWidth(0, 4000);
sheet.setColumnWidth(1, 10000);
sheet.setColumnWidth(2, 4000);
sheet.setColumnWidth(3, 4000);
sheet.setColumnWidth(4, 5000);
sheet.setColumnWidth(5, 5000);
sheet.setColumnWidth(6, 4000);
sheet.setColumnWidth(7, 4000);
sheet.setColumnWidth(8, 5000);
sheet.setColumnWidth(9, 5000);
HSSFCellStyle style = workBook.createCellStyle(); // 创建样式对象
style.setAlignment(HSSFCellStyle.ALIGN_CENTER);
style.setAlignment(HSSFCellStyle.ALIGN_CENTER_SELECTION);// 水平居中
style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);// 垂直居中
HSSFFont font = workBook.createFont();// 创建字体对象
font.setFontHeightInPoints((short) 12);
font.setFontName("黑体");// 设置字体
style.setFont(font);
HSSFCellStyle titleStyle = workBook.createCellStyle();// 创建表头样式对象
titleStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER_SELECTION);// 水平居中
titleStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);// 垂直居中
HSSFFont titleFont = workBook.createFont();// 创建表头字体对象
titleFont.setFontHeightInPoints((short) 15);
titleFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);// 设置粗体
titleFont.setFontName("黑体");// 设置字体
titleStyle.setFont(titleFont);
// 合并单元格操作
sheet.addMergedRegion(new CellRangeAddress(0, 1, 0, 9));
sheet.addMergedRegion(new CellRangeAddress(2, 2, 0, 9));
cell = sheet.createRow(0).createCell(0);
cell.setCellStyle(titleStyle);
cell.setCellValue(new HSSFRichTextString(list.get(0).getStudent()
.getGrade().getGname()
+ "级" + col.getCname() + "学院"));
HSSFRow row = sheet.createRow(2);
row.setHeightInPoints(20);
cell = row.createCell(0);
cell.setCellStyle(style);
cell.setCellValue(new HSSFRichTextString("毕业设计选题 & & & & & & & "
+ " & & &选题总人数:" + list.size() + " 人"));
// 设置边框样式
HSSFCellStyle tableStyle = workBook.createCellStyle();
tableStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);
tableStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER_SELECTION);// 水平居中
tableStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);// 垂直居中
HSSFFont tableFont = workBook.createFont();// 创建表格字体对象
tableFont.setFontHeightInPoints((short) 11);
tableFont.setFontName("宋体");// 设置字体
tableStyle.setFont(tableFont);
// 生成表头
String[] bt = new String[] { "选题编号", "选题名", "选题学生学号", "选题学生名",
"选题学生电话", "选题学生邮箱", "指导老师编号", "指导老师名", "指导老师电话", "指导老师邮箱" };
HSSFRow tableRow = sheet.createRow(3); // 创建一个行对象
tableRow.setHeightInPoints(18);
for (int i = 0; i & bt. i++) {
cell = tableRow.createCell(i);
cell.setCellStyle(tableStyle);
cell.setCellValue(new HSSFRichTextString(bt[i]));
// 写入表格内容
for (int i = 0; i & list.size(); i++) {
tableRow = sheet.createRow(i + 4); // 创建一个行对象
tableRow.setHeightInPoints(16);
Choices cho = list.get(i);
cell = tableRow.createCell(0);
cell.setCellStyle(tableStyle);
cell.setCellValue(new HSSFRichTextString(cho.getSubject()
.getSub_ID().toString()));
cell = tableRow.createCell(1);
cell.setCellStyle(tableStyle);
cell.setCellValue(new HSSFRichTextString(cho.getSubject()
.getSub_name()));
cell = tableRow.createCell(2);
cell.setCellStyle(tableStyle);
cell.setCellValue(new HSSFRichTextString(cho.getStudent().getUser()
.getUser_name()));
cell = tableRow.createCell(3);
cell.setCellStyle(tableStyle);
cell.setCellValue(new HSSFRichTextString(cho.getStudent()
.getStu_name()));
cell = tableRow.createCell(4);
cell.setCellStyle(tableStyle);
cell.setCellValue(new HSSFRichTextString(cho.getStudent()
.getStu_tel()));
cell = tableRow.createCell(5);
cell.setCellStyle(tableStyle);
cell.setCellValue(new HSSFRichTextString(cho.getStudent()
.getStu_mail()));
cell = tableRow.createCell(6);
cell.setCellStyle(tableStyle);
cell.setCellValue(new HSSFRichTextString(cho.getTeacher().getUser()
.getUser_name()));
cell = tableRow.createCell(7);
cell.setCellStyle(tableStyle);
cell.setCellValue(new HSSFRichTextString(cho.getTeacher()
.getTea_name()));
cell = tableRow.createCell(8);
cell.setCellStyle(tableStyle);
cell.setCellValue(new HSSFRichTextString(cho.getTeacher()
.getTea_tel()));
cell = tableRow.createCell(9);
cell.setCellStyle(tableStyle);
cell.setCellValue(new HSSFRichTextString(cho.getTeacher()
.getTea_mail()));
workBook.write(response.getOutputStream()); // 将文档对象写入文件输出流
人打赏支持
码字总数 1623
支付宝支付
微信扫码支付
打赏金额: ¥
已支付成功
打赏金额: ¥tianshanju 的BLOG
用户名:tianshanju
文章数:10
访问量:7169
注册日期:
阅读量:5863
阅读量:12276
阅读量:417730
阅读量:1105505
51CTO推荐博文
从Mysql数据库导出数据到Excel文件,打开文件发现数据的时间格式均为Java格式的时间戳,为了增强数据的可读性,需把时间戳批量转换为日常日期格式。 转换原理如下:转化时间戳从微秒到天,再加上epoch Time,然后在根据所在时区+/-数值转换毫秒为天
=((((x/)/24)把结果加上Epoch
=((((x/)/24)+DATE()调整所在的GMT时区偏移,如中国时区为GMT+8:00
=((((x/)/24)+DATE()+(8/24) 上述表达式可简化为
=(A1/569+(8/24)
以 16:18:58(GMT+8:00)为例,它的Java格式的时间戳为7输入下图所示的公式,回车执行公式,把单元格的格式更改为日期格式。如需批量转换,可使用十字星拖动复制公式。参考链接:
了这篇文章
类别:┆阅读(0)┆评论(0)从数据库mysql怎么输出时间与日期到excel?
#!/usr/bin/env python
# coding: utf-8
import MySQLdb
import os
from pyExcelerator import *
def main():
'''main'''
w=Workbook()
ws=w.add_sheet('user')
mysql_conn=MySQLdb.connect(&。。。。。。。。,db=&WIREAGENT&,charset=&utf8&)
cursor=mysql_conn.cursor()
cursor.execute(&select * from student&)
results=cursor.fetchall()
#得到表的目录
results_count=len(results)
cursor.close()
mysql_conn.close()
a=results_count-1
# print results
for r in results:
[ws.write(row,i,s) for i,s in enumerate(r)]
w.save('data.xls')
if __name__ == &__main__&:
我想从mysql付出时间与日期到一个excel里面,但是遇到了问题
python type Error:arg None does not match《type str》&type long&.......................................
最后几列为空?到底该怎么办?
推荐到广播
80190 人聚集在这个小组
(资源共享吧)
(资源共享吧)
第三方登录:}

我要回帖

更多关于 mysql数据库日期函数 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信