以文本方式查看主题 - Foxtable(狐表) (http://foxtable.net/bbs/index.asp) -- 专家坐堂 (http://foxtable.net/bbs/list.asp?boardid=2) ---- 导入excel的日期数据不能完整地显示时间 (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=192498) |
-- 作者:yankunhao -- 发布时间:2024/6/26 17:01:00 -- 导入excel的日期数据不能完整地显示时间 原文件有上面这样的时间数据,我用代码将这些数据导入 Dim Book As New XLS.Book(dlg.FileName) Dim Sheet As XLS.Sheet = Book.Sheets(0) Tables("APS排产导入").StopRedraw() \'注意以下数组中列名称的顺序,必须和Excel表中的列顺序一致 Dim nms() As String = {"目的地","订单编号","产品说明","资源名称","数量","已排程的开始日期","已排程结束日期"} \'注意下面的循环变量从1开始,而不是从0开始,因为Excel表的第一行是标题 Dim k() As Integer = {1,2,3,4,5,7,8} Dim w As Integer Dim f As String Dim q As Date Dim q1 As Date w =dlg.FileName.LastIndexOf("\\") f = dlg.FileName.SubString(w+1) q = f.SubString(7,9) For n As Integer = 2 To Sheet.Rows.Count -1 q1 = Sheet(n,7).Text.SubString(0,10) If q1 = q Then Dim r As Row = Tables("APS排产导入").AddNew() For m As Integer = 0 To nms.Length - 1 r(nms(m)) = Sheet(n,k(m)).Value r("导入文件名") = f r("文件名日期") = q Next End If Next Tables("APS排产导入").ResumeRedraw() MessageBox.Show("导入完成!") Tables("APS排产导入").DataTable.Save End If 但显示的是 ,请问应该如何做才能正常显示? [此贴子已经被作者于2024/6/26 17:04:31编辑过]
|
-- 作者:有点蓝 -- 发布时间:2024/6/26 17:05:00 -- 要使用vba导:http://www.foxtable.com/bbs/dispbbs.asp?BoardID=2&ID=65686&skin=0 |
-- 作者:yankunhao -- 发布时间:2024/6/27 10:05:00 -- Dim dlg As New OpenFileDialog \'定义一个新的OpenFileDialog dlg.Filter= "Excel2003文件|*.xls|Excel2007文件|*.xlsx" \'设置筛选器 If dlg.ShowDialog = DialogResult.Ok Then \'如果用户单击了确定按钮 Dim App As New MSExcel.Application Dim Book As MSExcel.WorkBook = App.WorkBooks.Open(dlg.FileName) \'Dim Sheet As XLS.Sheet = Book.Sheets(0) Dim Sheet As MSExcel.WorkSheet = Book.WorkSheets(1) Dim Rg As MSExcel.Range = Sheet.UsedRange Tables("APS排产导入").StopRedraw() \'注意以下数组中列名称的顺序,必须和Excel表中的列顺序一致 Dim nms() As String = {"目的地","订单编号","产品说明","资源名称","数量","已排程的开始日期","已排程结束日期"} \'注意下面的循环变量从1开始,而不是从0开始,因为Excel表的第一行是标题 Dim k() As Integer = {2,3,4,5,6,8,9} Dim w As Integer Dim f As String Dim q As Date Dim q1 As Date w =dlg.FileName.LastIndexOf("\\") f = dlg.FileName.SubString(w+1) q = f.SubString(7,9) \'For n As Integer = 2 To Sheet.Rows.Count -1 For n As Integer = 2 To rg.Rows.Count q1 = Sheet.Cells(n,8).Text.SubString(0,9) If q1 = q Then Dim r As Row = Tables("APS排产导入").AddNew() For m As Integer = 0 To nms.Length - 1 r(nms(m)) = Sheet.Cells(n,k(m)).Value r("导入文件名") = f r("文件名日期") = q Next End If Next Tables("APS排产导入").ResumeRedraw() MessageBox.Show("导入完成!") Tables("APS排产导入").DataTable.Save End If |
-- 作者:yankunhao -- 发布时间:2024/6/27 10:06:00 -- 用上面代码,现在提示这样的错语,请问是什么原因? |
-- 作者:有点蓝 -- 发布时间:2024/6/27 10:10:00 -- 应该是下面代码问题,比如这个单元格的内容字符长度小于9个,先判断一下字符长度 q1 = Sheet.Cells(n,8).Text.SubString(0,9)
|
-- 作者:yankunhao -- 发布时间:2024/6/27 13:31:00 --
|
-- 作者:有点蓝 -- 发布时间:2024/6/27 13:35:00 -- Operator:=MSExcel.XlAutoFilterOperator.xlAnd |
-- 作者:yankunhao -- 发布时间:2024/6/27 13:52:00 -- 按你提示的方法,会提示:编译错误:"Public Function AutoFilter([Field As Object],[Criteria1 AsObject], [operator AsMicrosoft.office.Interop.Excel.xlAutoFilteroperator =XlAutoFilterOperator.xlAnd], [Criteria2 As Object], [VisibleDropDown AsObject]) As Object"的参数 "Field"已有匹配的参数. 错误代码:sheet.Range("A1").AutoFilter(Field:=8, Criteria1:=">="&q.Tostring("yyyy-MM-dd"),Operator:=MSExcel.XlAutoFilterOperator.xlAnd, Field:=8,Criteria2:="<=" & q.AddDays(1).Tostring("yyyy-MM-dd"))
|
-- 作者:有点蓝 -- 发布时间:2024/6/27 14:02:00 -- 提示很明显,Field:=8使用重复了 |
-- 作者:yankunhao -- 发布时间:2024/6/27 14:25:00 -- Sheet.AutoFilterMode = False sheet.Range("A1").AutoFilter(8, ">=" & q.ToString("yyyy-MM-dd"), MSExcel.XlAutoFilterOperator.xlAnd, 8, "<=" & q.AddDays(1).ToString("yyyy-MM-dd")) Sheet.Range("A1").AutoFilter(Field:=5, Criteria1:="ZQ-03*") \'For n As Integer = 2 To rg.Rows.Count For n As Integer = 2 To Sheet.UsedRange.SpecialCells(xlCellTypeVisible).Rows.Count 会提示错误,请问应该如何处理? :编译错误:未声明”xlCellTypevisible”。它可能因其保护级别而不可访问 错误代码:Forn As Integer=2ToSheet.UsedRange.specialcells(xlcellTypeVisible).Rows.Count |