以文本方式查看主题 - Foxtable(狐表) (http://foxtable.com/bbs/index.asp) -- 专家坐堂 (http://foxtable.com/bbs/list.asp?boardid=2) ---- 导入excel数据 原始值为2021-07 导入后为2021-07-01 有没有办法确保数据为导入之前的格式 2021-07 麻烦老师看看 谢谢! (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=170319) |
-- 作者:cnsjroom -- 发布时间:2021/7/21 17:33:00 -- 导入excel数据 原始值为2021-07 导入后为2021-07-01 有没有办法确保数据为导入之前的格式 2021-07 麻烦老师看看 谢谢! 麻烦老师帮忙看看 应收月份为2021-07 导入后为2021-07-01 有没有办法确保数据为导入之前的格式 2021-07 表数据格式: 导入表代码: Dim dt As DataTable = DataTables("数据表") \'需要合并的Foxtable表 Dim dCols() As String = {"d1","d2","d3","d4","d5","d6","d7","d8"} \'Foxtable表字段 Dim sCols() As String = {"管理区","楼宇/停车场","收费项目","收费标准","资源代码","资源状态","应收月份","欠费金额"} \'Excel表字段 Dim k As Integer = 1 \'Excel表头标题是第几行,如果是第一行,即代码里的第0行 Functions.Execute("Excel",dt,dCols,sCols,k) 内部函数excel代码: Dim dt As DataTable = Args(0) \'需要合并的Foxtable表 Dim dCols() As String = Args(1) \'Foxtable表字段 Dim sCols() As String = Args(2) \'Excel表字段 Dim k As Integer = Args(3) \'Excel表头标题是第几行,默认第一行,即代码里的第0行 Dim dlg As New OpenFileDialog \'定义一个新的OpenFileDialog dlg.Filter= "Excel文件|*.xls;*.xlsx" \'设置筛选器 dlg.MultiSelect=True \'可以同时导入多个Excel表 If dlg.ShowDialog = DialogResult.Ok Then \'如果用户单击了确定按钮 Dim files() As String = dlg.FileNames Dim zd As New Dictionary(Of String, Integer) \'字典记录导入字段对应Excel第几列 For i As Integer =0 To sCols.Length -1 zd.Add(sCols(i),-1) Next Dim err As String = "" For Each file As String In files Dim Book As New XLS.Book(file) Dim Sheet As XLS.Sheet = Book.Sheets(0) Dim j As Integer = 0 \'检查Excel表头结构个数,如果都符合则 j = sCols.Length Dim Iferr As Boolean = False \'检查表头时,是否出错. For i As Integer = 0 To Sheet.Cols.Count - 1 Dim scol As String = sheet(k-1,i).value If zd.ContainsKey(scol) Then j = j + 1 If zd(scol) = -1 Then zd(scol) = i ElseIf zd(scol) <> i Then err = err & "Excel文件:【" & file & "】与其他文件Excel表结构不同;" Iferr = True Exit For End If End If Next If j <> sCols.Length AndAlso Iferr = False Then err = err & "Excel文件:【" & file & "】的表结构个数与预设不符;" End If Next If err <> "" Then \'出错了 MessageBox.Show(err) Else \'进入合并 For Each file As String In files Dim Book As New XLS.Book(file) Dim Sheet As XLS.Sheet = Book.Sheets(0) For n As Integer = 0 To Sheet.Rows.Count - k - 1 Dim nr As DataRow = dt.AddNew() For i As Integer = 0 To sCols.Length -1 If dt.DataCols(dCols(i)).IsNumeric Then Dim temp As Decimal = sheet(k+n,zd(sCols(i))).value nr(dCols(i)) = temp Else nr(dCols(i)) = sheet(k+n,zd(sCols(i))).value End If Next Next Next MessageBox.Show("导入完成") End If End If [此贴子已经被作者于2021/7/21 17:33:50编辑过]
|
-- 作者:有点蓝 -- 发布时间:2021/7/22 8:36:00 -- d7如果是日期列,到drawcell处理;d7如果是字符列,导入的时候自己格式化一下:http://www.foxtable.com/webhelp/topics/0362.htm |