【问题标题】:How to export set of rows depending on date from datatable into multiple sheets of excel如何根据数据表中的日期将一组行导出到多张excel中
【发布时间】:2016-08-24 10:20:50
【问题描述】:

我想将特定行导出到多张 excel 表中,具体取决于 vb.net 中数据表中的日期

我的代码

我希望 17/08/2016 在一张纸上 18/08/2016 在下一张纸上。 我的表格行是这样的:

s.no date     
 1    17/08/2016    
 2    17/08/2016    
 3    17/08/2016    
 4    18/08/2016    
 5    18/08/2016
          For i = 0 To dt.Rows.Count - 2
            If dt.Rows(i).Item("AttDate") = dt.Rows(i + 1).Item("AttDate") Then
                oSheet = oBook.Worksheets(1)

                oSheet.Cells(Irow, IcolFranchisee) = dt.Rows(i).Item("Intime")
                If dt.Rows(i).Item("latein") > 0 Then
                    oSheet.Cells(Irow, IcolFranchisee + 1) = dt.Rows(i).Item("latein")
                Else
                    oSheet.Cells(Irow, IcolFranchisee + 2) = dt.Rows(i).Item("latein")
                End If
                Irow = Irow + 1
            Else
                osheet1 = oBook.Worksheets(2)

                osheet1.Cells(Irow, IcolFranchisee) = dt.Rows(i).Item("Intime")
                If dt.Rows(i).Item("latein") > 0 Then
                    osheet1.Cells(Irow, IcolFranchisee + 1) = dt.Rows(i).Item("latein")
                Else
                    osheet1.Cells(Irow, IcolFranchisee + 2) = dt.Rows(i).Item("latein")
                End If
                Irow = Irow + 1
            End If
        Next

【问题讨论】:

  • 有问题吗?
  • 你能解释一下这个问题吗?
  • 我有一组数据表中的行。在那个日期列中..我根据日期导出不同的工作表..
  • 好的...您在导出到 excel 时遇到问题吗?
  • 我知道怎么做单张

标签: vb.net excel vba


【解决方案1】:
Dim strValue As String
      For i = 0 To dt.Rows.Count - 2
        If i = 0 Then

            ' Sheet 1
            oSheet = oBook.Worksheets(1)

            oSheet.Cells(Irow, IcolFranchisee) = dt.Rows(i).Item("Intime")
            If dt.Rows(i).Item("latein") > 0 Then
                oSheet.Cells(Irow, IcolFranchisee + 1) = dt.Rows(i).Item("latein")
            Else
                oSheet.Cells(Irow, IcolFranchisee + 2) = dt.Rows(i).Item("latein")
            End If

            Irow = Irow + 1

        Else

            If dt.Rows(i).Item("AttDate") = strValue then
             ' Sheet 1
                oSheet = oBook.Worksheets(1)

                oSheet.Cells(Irow, IcolFranchisee) = dt.Rows(i).Item("Intime")
                If dt.Rows(i).Item("latein") > 0 Then
                   oSheet.Cells(Irow, IcolFranchisee + 1) = dt.Rows(i).Item("latein")
                Else
                   oSheet.Cells(Irow, IcolFranchisee + 2) = dt.Rows(i).Item("latein")
                End If

                Irow = Irow + 1

            Else

                ' Sheet 2
                osheet1 = oBook.Worksheets(2)

                osheet1.Cells(Irow, IcolFranchisee) = dt.Rows(i).Item("Intime")
                If dt.Rows(i).Item("latein") > 0 Then
                    osheet1.Cells(Irow, IcolFranchisee + 1) = dt.Rows(i).Item("latein")
                Else
                    osheet1.Cells(Irow, IcolFranchisee + 2) = dt.Rows(i).Item("latein")
                End If

            End If

            Irow = Irow + 1

        End If

        strValue = dt.Rows(i).Item("AttDate")

    Next

希望这是您正在寻找的。​​p>

【讨论】:

  • 您遇到错误了吗?如果是,错误是什么?如果不是,输出是什么?
  • 第一张纸本身都来了。第二张纸只有一行
  • 放一个断点,检查步骤和值。能否提供输出截图?
  • 你能提供邮件ID吗..我会自己发送文件
  • 编辑问题并截图,无法提供电子邮件抱歉:-(
猜你喜欢
  • 1970-01-01
  • 2019-08-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多