以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.net/bbs/index.asp)
--  专家坐堂  (http://foxtable.net/bbs/list.asp?boardid=2)
----  为什么 导出的数据不全  (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=118409)

--  作者:xywl
--  发布时间:2018/5/2 11:51:00
--  为什么 导出的数据不全

库存明细表以前导出一直好好的 现在导出少了第一行

代码如下:

\'If _dcbb = False Then
    \'MessageBox.Show("对不起!您没有该权限,请联系管理员!", "温馨提示", MessageBoxButtons.OK, MessageBoxIcon.Warning)
    \'Return
\'End If
If Tables("库存查询_Table1").Rows.Count = 0 Then
    MessageBox.Show("暂无任何数据,不能导出Excel!", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Warning)
    Return
End If
If e.form.Controls("TabControl1").SelectedPage.text = "商品库存" Then
If FileSys.FileExists(ProjectPath & "模板\\库存清单.xls") = False Then
    Messagebox.Show("库存清单.xls模板不存在或已经被删除,导出失败!","错误提示",MessageBoxButtons.OK, MessageBoxIcon.Warning)
    Return
End If
Dim fl As String = ProjectPath & "excel\\库存清单.xls"
If FileIsOpened(fl)= True Then
    MessageBox.Show("""库存清单.xls""文件正在打开中,请先关闭再执行导出操作!","温馨提示",MessageBoxButtons.OK, MessageBoxIcon.Warning)
    Return
End If
Dim flg As New SaveExcelFlags
Dim ts As String = e.Form.Controls("提示").text
Dim Book As New XLS.Book(ProjectPath & "模板\\库存清单.xls") \'打开模板
Dim Sheet As XLS.Sheet = Book.Sheets(0)
With Sheet.PrintSetting
    .PaperKind = 9
    .MarginLeft = 8
    .MarginRight = 5
    .MarginTop = 5
    .MarginBottom = 5
    .LandScape = False
End With
    Sheet(7,0).Value = "<库存查询_Table1>"
    Sheet(4,2).Value =  Date.Today
    Sheet(8,1).Value = "制单人:" & _yhm
Sheet(7,17).Value = "<Item is not null>"  \'写入表名
 
Book.Save(fl)
e.Form.Controls("打印预览").Enabled = True
e.Form.Controls("直接打印").Enabled = True
If MessageBox.Show("导出完成,是否打开报表?", "完成提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) = 1 Then
    Dim Proc As New Process
    Proc.File = fl
    Proc.Start()
End If
ElseIf e.form.Controls("TabControl1").SelectedPage.text = "库存明细" Then
Dim idx As String = "-1,"
Dim idx_temp As String = ""
Dim pdr As DataRow = Nothing
Dim count As Integer = 0
Dim cs As String = "货品编号,货格"
For Each dr As DataRow In DataTables("商品库存明细").Select("", cs)
   
    Dim flag As Boolean = False
    If pdr IsNot Nothing Then
        For Each c As String In cs.split(",")
            If pdr(c) <> dr(c) Then
                flag = True
                Exit For
            End If
        Next
    End If
    If flag Then
        If count > 1 Then
            idx &= idx_temp
        End If
        count = 1
        idx_temp = ""
    Else
        count += 1
        idx_temp &= dr("_Identify") & ","
    End If
   
    pdr = dr
Next

If count > 1 Then
    idx &= idx_temp
End If

Tables("库存查询_table2").filter = "_Identify not in (" & idx.trim(",") & ")"
If FileSys.FileExists(ProjectPath & "模板\\库存明细.xls") = False Then
        Messagebox.Show("库存明细Excel模板不存在或已经被删除,导出失败!","错误提示",MessageBoxButtons.OK, MessageBoxIcon.Warning)
        e.Form.Controls("打印预览").Enabled = False
        e.Form.Controls("打印预览").Enabled = False
        Return
    End If
    Dim Book As New XLS.Book(ProjectPath & "模板\\库存明细.xls")
    Dim fl As String = ProjectPath & "excel\\库存明细.xls"
    If FileIsOpened(fl)= True Then
        MessageBox.Show("""库存明细.xls""文件正在打开中,请先关闭再执行导出操作!")
        e.Form.Controls("打印预览").Enabled = False
        e.Form.Controls("打印预览").Enabled = False
        Return
    End If
    Dim Sheet As XLS.Sheet = Book.Sheets(0)
    With Sheet.PrintSetting
        .PaperKind = 9
        .MarginLeft = 12
        .MarginRight = 10
        .MarginTop = 5
        .MarginBottom = 5
        .LandScape = False
    End With
    Sheet(7,0).Value = "<库存查询_Table2>"
    Sheet(4,2).Value =  Date.Today
    Sheet(8,1).Value = "制单人:" & _yhm
Sheet(7,17).Value = "<货品编号 is not null>"
    Book.Build() \'生成细节区
    Book.Save(fl) \'保存工作簿
    e.Form.Controls("打印预览").Enabled = True
    e.Form.Controls("直接打印").Enabled = True
    If MessageBox.Show("导出完成,是否打开报表?", "完成提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) = 1 Then
        Dim Proc As New Process \'打开工作簿
        Proc.File = fl
        Proc.Start()
    End If
End If


--  作者:有点甜
--  发布时间:2018/5/2 11:58:00
--  

去除重复那一段,建议修改一下,如

 

http://www.foxtable.com/bbs/dispbbs.asp?BoardID=2&ID=115079&skin=0