以文本方式查看主题 - Foxtable(狐表) (http://foxtable.com/bbs/index.asp) -- 专家坐堂 (http://foxtable.com/bbs/list.asp?boardid=2) ---- [求助]导出excle小时分钟导出 (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=127540) |
-- 作者:湛江智 -- 发布时间:2018/11/16 11:06:00 -- [求助]导出excle小时分钟导出 下列代码导出excle时,时间time列,导出不能显示正确的 几点几分钟,显示为 1900-1-0 9:39:00 求助,怎样显示为9:39,谢谢 Dim dt As Table = Tables("工作日志") Dim nms() As String = {"省份","城市","项目名称","其他名称","项目位置","户型","项目类别","日期","创建时间","创建者","工作内容","完成情况","未完成原因","加班时间","次日工作计划","图片","附件a"} \'要导出的列名 Dim caps() As String = {"省份","城市","项目名称","其他名称","项目位置","户型","项目类别","日期","创建时间","创建者","工作内容","完成情况","未完成原因","加班时间","次日工作计划","图片","附件a"} \'对应的列标题 Dim szs() As Integer = {50,70,90,100,90,90,90,90,90,80,190,190,190,190,190,40,40} \'对应的列宽 Dim Book As New XLS.Book \'定义一个Excel工作簿 Dim Sheet As XLS.Sheet = Book.Sheets(0) \'引用工作簿的第一个工作表 Dim st As XLS.Style = Book.NewStyle \'日期列的显示格式 st.Format = "yyyy-MM-dd" For c As Integer = 0 To nms.length -1 Sheet(0, c).Value = caps(c) \'指定列标题 Sheet.Cols(c).Width = szs(c) \'指定列宽 If dt.Cols(nms(c)).IsDate Then \'如果是日期列 Sheet.Cols(c).Style = st \'设置显示格式 End If Next \'For r As Integer = 0 To dt.Rows.Count - 1 \'填入数据 \'导出的excle表的单元格 日期是1900-01-00,下面代码怎么修改呢?谢谢 \'For c As Integer = 0 To nms.length -1 \'Sheet(r +1, c).Value = dt.rows(r)(nms(c)) \'Next \'Next \'[求助]导出数据 For r As Integer = 0 To dt.Rows.Count - 1 \'填入数据 Dim dr As Row = dt.rows(r) For c As Integer = 0 To nms.length -1 If dr.IsNull(nms(c)) = False Sheet(r +1, c).Value = dr(nms(c)) End If Next Next Dim dlg As New SaveFileDialog \'定义一个新的SaveFileDialog dlg.Filter= "Excel文件|*.xls" \'设置筛选器 If dlg.ShowDialog = DialogResult.Ok Then Book.Save(dlg.FileName) Dim Proc As New Process Proc.File = dlg.FileName Proc.Start() End If [此贴子已经被作者于2018/11/16 11:30:43编辑过]
|
-- 作者:有点甜 -- 发布时间:2018/11/16 11:50:00 -- st.Format = "yyyy-MM-dd"
改成比如
st.Format = "hh:mm" |
-- 作者:湛江智 -- 发布时间:2018/11/16 12:02:00 -- 回复:(有点甜)st.Format = "yyyy-MM-dd" ... 1、 按上楼,小时分钟显示正确了,但是日期列 显示为2018-11-7 0:00:00 有问题 2、如果导出的行,要按日期排序,怎么修改呢? 谢谢 |
-- 作者:有点甜 -- 发布时间:2018/11/16 12:06:00 -- 1、修改代码,不同的列,设置不同的样式。比如判断如果列是time列,设置样式1,否则设置成样式2;
2、先对dt排序,如 dt.sort = "某列" |