以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.net/bbs/index.asp)
--  专家坐堂  (http://foxtable.net/bbs/list.asp?boardid=2)
----  [求助] 导出数据时,数据少了一行  (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=111077)

--  作者:农村人
--  发布时间:2017/12/14 16:11:00
--  [求助] 导出数据时,数据少了一行
我导出的数据表标题是两行,以下代码不知道早哪出问题,标题是有正常生成,但数据始终少了一行。

Dim dt As Table = Tables("订单列表")
Dim nms() As String = {"订单编号","快递公司","快递单号"} \'要导出的列名
Dim caps() As String = {"订单编号","快递公司(必填)","快递单号"} \'对应的列标题
Dim capt() As String = {"order_sn","shipping_name","shipping_sn"} \'对应的列标题
Dim szs() As Integer = {200,300,300} \'对应的列宽
Dim Book As New XLS.Book \'定义一个Excel工作簿
Dim Sheet As XLS.Sheet = Book.Sheets(0) \'引用工作簿的第一个工作表
For c As Integer = 0 To nms.length -1
    Sheet(0, c).Value = caps(c) \'指定列标题
    Sheet(1, c).Value = capt(c) \'指定列标题
    Sheet.Cols(c).Width = szs(c) \'指定列宽
Next
For r As Integer = 1 To dt.Rows.Count - 1 \'填入数据
    For c As Integer = 0 To nms.length -1
        Sheet(r +1, c).Value = dt.rows(r)(nms(c))
    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


--  作者:有点甜
--  发布时间:2017/12/14 16:17:00
--  
For r As Integer = 0 To dt.Rows.Count - 1 \'填入数据
    For c As Integer = 0 To nms.length -1
        Sheet(r +2, c).Value = dt.rows(r)(nms(c))
    Next
Next