Visual Basi c Запуск QBFC13Lib, SDK, Запуск GeneralSummaryReportQuery, по Ответу, не может получить имена столбцов в виде текста - PullRequest
0 голосов
/ 30 апреля 2020

Я использую Visual Basi c для экспорта общего сводного отчета. Чтобы преуспеть в использовании Quickbooks SDK QBFC13Lib. В ответ я не могу получить заголовки столбцов. Мне нужны заголовки столбцов в виде текста для отправки в ячейку Excel. Код для заголовков столбцов находится в 'Получить значение NumColTitleRows. У меня есть текстовое поле MsgBox (ColTitle.value), которое я пытался показать заголовки столбцов, чтобы я мог видеть, что я их получаю.

enter code here

Publi c Sub WalkReportRet (ReportRet As IReportRet)

    If (ReportRet Is Nothing) Then
        Exit Sub
    End If

    'Go through all the elements of IReportRet
    'Get value of ReportTitle
    Dim ReportTitle10687 As String
    ReportTitle10687 = ReportRet.ReportTitle.GetValue()

    'Get value of ReportSubtitle
    Dim ReportSubtitle10688 As String
    ReportSubtitle10688 = ReportRet.ReportSubtitle.GetValue()

    'Get value of NumRows
    Dim NumRows10690 As Integer
    NumRows10690 = ReportRet.NumRows.GetValue()

    'Get value of NumColumns
    Dim NumColumns10691 As Integer
    NumColumns10691 = ReportRet.NumColumns.GetValue()


    'SEND TO EXCEL
    Dim appXL As Excel.Application
    Dim wbXl As Excel.Workbook
    Dim shXL As Excel.Worksheet
    Dim raXL As Excel.Range

    ' Start Excel and get Application object.
    appXL = CreateObject("Excel.Application")
    appXL.Visible = True

    ' Add a new workbook.
    wbXl = appXL.Workbooks.Add
    shXL = wbXl.ActiveSheet


    'Create an array to set multiple values at once.
    Dim qbdata(200, 10) As String
    qbdata(0, 0) = ReportTitle10687
    qbdata(0, 1) = ReportSubtitle10688
    qbdata(0, 2) = NumRows10690.ToString
    qbdata(0, 3) = NumColumns10691.ToString





    'Get value of NumColTitleRows
    Dim NumColTitleRows10692 As Integer
    NumColTitleRows10692 = ReportRet.NumColTitleRows.GetValue()

    If (Not ReportRet.ColDescList Is Nothing) Then
        Dim i10693 As Integer
        For i10693 = 0 To ReportRet.ColDescList.Count - 1
            Dim ColDesc As IColDesc
            ColDesc = ReportRet.ColDescList.GetAt(i10693)
            If (Not ColDesc.ColTitleList Is Nothing) Then
                Dim i10694 As Integer
                For i10694 = 0 To ColDesc.ColTitleList.Count - 1
                    Dim ColTitle As IColTitle
                    ColTitle = ColDesc.ColTitleList.GetAt(i10694)

                    MsgBox(ColTitle.value)

                Next i10694
            End If
            'Get value of ColType
            Dim ColType10695 As ENColType
            ColType10695 = ColDesc.ColType.GetValue()
        Next i10693
    End If



    If (Not ReportRet.ReportData Is Nothing) Then
        If (Not ReportRet.ReportData.ORReportDataList Is Nothing) Then
            Dim i10696 As Integer
            'this runs the rows
            For i10696 = 0 To ReportRet.ReportData.ORReportDataList.Count - 1
                Dim ORReportData10697 As IORReportData
                ORReportData10697 = ReportRet.ReportData.ORReportDataList.GetAt(i10696)
                If (Not ORReportData10697.DataRow Is Nothing) Then
                    If (Not ORReportData10697.DataRow Is Nothing) Then
                        If (Not ORReportData10697.DataRow.RowData Is Nothing) Then
                        End If
                        If (Not ORReportData10697.DataRow.ColDataList Is Nothing) Then
                            Dim i10698 As Integer
                            For i10698 = 0 To ORReportData10697.DataRow.ColDataList.Count - 1
                                Dim ColData As IColData
                                ColData = ORReportData10697.DataRow.ColDataList.GetAt(i10698)

                                qbdata(i10696 + 5, i10698) = ColData.value.GetValue.ToString

                            Next i10698
                        End If
                    End If
                End If
                If (Not ORReportData10697.TextRow Is Nothing) Then
                    If (Not ORReportData10697.TextRow Is Nothing) Then

                        qbdata(i10696 + 5, 0) = ORReportData10697.TextRow.value.GetValue.ToString

                    End If
                End If
                If (Not ORReportData10697.SubtotalRow Is Nothing) Then
                    If (Not ORReportData10697.SubtotalRow Is Nothing) Then
                        If (Not ORReportData10697.SubtotalRow.RowData Is Nothing) Then
                        End If
                        If (Not ORReportData10697.SubtotalRow.ColDataList Is Nothing) Then
                            Dim i10699 As Integer
                            For i10699 = 0 To ORReportData10697.SubtotalRow.ColDataList.Count - 1
                                Dim ColData As IColData
                                ColData = ORReportData10697.SubtotalRow.ColDataList.GetAt(i10699)

                                qbdata(i10696 + 5, i10699) = ColData.value.GetValue.ToString

                            Next i10699
                        End If
                    End If
                End If
                If (Not ORReportData10697.TotalRow Is Nothing) Then
                    If (Not ORReportData10697.TotalRow Is Nothing) Then
                        If (Not ORReportData10697.TotalRow.RowData Is Nothing) Then
                        End If
                        If (Not ORReportData10697.TotalRow.ColDataList Is Nothing) Then
                            Dim i10700 As Integer
                            For i10700 = 0 To ORReportData10697.TotalRow.ColDataList.Count - 1
                                Dim ColData As IColData
                                ColData = ORReportData10697.TotalRow.ColDataList.GetAt(i10700)

                                qbdata(i10696 + 5, i10700) = ColData.value.GetValue.ToString

                            Next i10700
                        End If
                    End If
                End If
            Next i10696
        End If
    End If




    ' Fill A2:B6 with an array of data
    shXL.Range("A1", "K205").Value = qbdata




    ' Make sure Excel is visible and give the user control
    ' of Excel's lifetime.
    appXL.Visible = True
    appXL.UserControl = True

    ' Release object references.
    raXL = Nothing
    shXL = Nothing
    wbXl = Nothing
    appXL.Quit()
    appXL = Nothing
End Sub

Ответы [ 2 ]

0 голосов
/ 02 мая 2020

Для справки: это должен быть универсальный код для Visual Studio Visual Basis c для экспорта сравнения баланса за предыдущий год из открытого файла компании в Excel. Несколько небольших изменений изменили бы это, чтобы экспортировать P & L. Этот код поддерживает только до 200 строк, его придется изменить для более длинного отчета. (расширен массив и расширен диапазон в excel).

пример отчета Quickbooks, экспортированного в excel

enter code here Private Sub RunChurchCashFlowReportToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles RunChurchCashFlowReportToolStripMenuItem.Click
    DoGeneralSummaryReportBalanceSheetQuery()
    DoGeneralSummaryReportProfitAndLossQuery()
    ' RunCustomSummaryReport()

End Sub
Public Sub DoGeneralSummaryReportBalanceSheetQuery()
    Dim sessionBegun As Boolean
    sessionBegun = False
    Dim connectionOpen As Boolean
    connectionOpen = False
    Dim sessionManager As QBSessionManager
    sessionManager = Nothing

    Try
        'Create the session Manager object
        sessionManager = New QBSessionManager

        'Create the message set request object to hold our request
        Dim requestMsgSet As IMsgSetRequest
        requestMsgSet = sessionManager.CreateMsgSetRequest("US", 13, 0)
        requestMsgSet.Attributes.OnError = ENRqOnError.roeContinue

        BuildGeneralSummaryReportBalanceSheetQueryRq(requestMsgSet)

        'Connect to QuickBooks and begin a session
        sessionManager.OpenConnection("", "ChurchReports")
        connectionOpen = True
        sessionManager.BeginSession("", ENOpenMode.omDontCare)
        sessionBegun = True

        'Send the request and get the response from QuickBooks
        Dim responseMsgSet As IMsgSetResponse
        responseMsgSet = sessionManager.DoRequests(requestMsgSet)

        'End the session and close the connection to QuickBooks
        sessionManager.EndSession()
        sessionBegun = False
        sessionManager.CloseConnection()
        connectionOpen = False

        WalkGeneralSummaryReportQueryRs(responseMsgSet)



    Catch e As Exception
        MessageBox.Show(e.Message, "Error")
        If (sessionBegun) Then
            sessionManager.EndSession()
        End If
        If (connectionOpen) Then
            sessionManager.CloseConnection()
        End If
    End Try
End Sub

Public Sub WalkGeneralSummaryReportQueryRs(responseMsgSet As IMsgSetResponse)
    If (responseMsgSet Is Nothing) Then
        Exit Sub
    End If

    Dim responseList As IResponseList
    responseList = responseMsgSet.ResponseList
    If (responseList Is Nothing) Then
        Exit Sub
    End If

    'if we sent only one request, there is only one response, we'll walk the list for this sample
    For j = 0 To responseList.Count - 1
        Dim response As IResponse
        response = responseList.GetAt(j)
        'check the status code of the response, 0=ok, >0 is warning
        If (response.StatusCode >= 0) Then
            'the request-specific response is in the details, make sure we have some
            If (Not response.Detail Is Nothing) Then
                'make sure the response is the type we're expecting
                Dim responseType As ENResponseType
                responseType = CType(response.Type.GetValue(), ENResponseType)
                If (responseType = ENResponseType.rtGeneralSummaryReportQueryRs) Then
                    'upcast to more specific type here, this is safe because we checked with response.Type check above
                    Dim ReportRet As IReportRet
                    ReportRet = CType(response.Detail, IReportRet)
                    WalkReportRet(ReportRet)
                End If
            End If
        End If
    Next j
End Sub

Public Sub WalkReportRet(ReportRet As IReportRet)

    If (ReportRet Is Nothing) Then
        Exit Sub
    End If

    'Go through all the elements of IReportRet
    'Get value of ReportTitle
    Dim ReportTitle10687 As String
    ReportTitle10687 = ReportRet.ReportTitle.GetValue()

    'Get value of ReportSubtitle
    Dim ReportSubtitle10688 As String
    ReportSubtitle10688 = ReportRet.ReportSubtitle.GetValue()

    'Get value of NumRows
    Dim NumRows10690 As Integer
    NumRows10690 = ReportRet.NumRows.GetValue()

    'Get value of NumColumns
    Dim NumColumns10691 As Integer
    NumColumns10691 = ReportRet.NumColumns.GetValue()


    'SEND TO EXCEL
    Dim appXL As Excel.Application
    Dim wbXl As Excel.Workbook
    Dim shXL As Excel.Worksheet
    Dim raXL As Excel.Range

    ' Start Excel and get Application object.
    appXL = CreateObject("Excel.Application")
    appXL.Visible = True

    ' Add a new workbook.
    wbXl = appXL.Workbooks.Add
    shXL = wbXl.ActiveSheet


    'Create an array to set multiple values at once.
    Dim qbdata(200, 10) As String
    qbdata(0, 0) = ReportTitle10687
    qbdata(0, 1) = ReportSubtitle10688
    qbdata(0, 2) = NumRows10690.ToString
    qbdata(0, 3) = NumColumns10691.ToString


    'Get value of NumColTitleRows
    Dim NumColTitleRows10692 As Integer
    NumColTitleRows10692 = ReportRet.NumColTitleRows.GetValue()

    If (Not ReportRet.ColDescList Is Nothing) Then
        Dim i10693 As Integer
        For i10693 = 0 To ReportRet.ColDescList.Count - 1
            Dim ColDesc As IColDesc
            ColDesc = ReportRet.ColDescList.GetAt(i10693)
            If (Not ColDesc.ColTitleList Is Nothing) Then
                Dim i10694 As Integer
                For i10694 = 0 To ColDesc.ColTitleList.Count - 1
                    Dim ColTitle As IColTitle
                    ColTitle = ColDesc.ColTitleList.GetAt(i10694)
                    If (Not ColTitle.value Is Nothing) Then
                        qbdata(i10694 + 2, i10693) = ColTitle.value.GetValue.ToString
                    End If
                Next i10694
            End If
            Dim ColType10695 As ENColType
            ColType10695 = ColDesc.ColType.GetValue()
        Next i10693
    End If



    If (Not ReportRet.ReportData Is Nothing) Then
        If (Not ReportRet.ReportData.ORReportDataList Is Nothing) Then
            Dim i10696 As Integer
            'this runs the rows
            For i10696 = 0 To ReportRet.ReportData.ORReportDataList.Count - 1
                Dim ORReportData10697 As IORReportData
                ORReportData10697 = ReportRet.ReportData.ORReportDataList.GetAt(i10696)
                If (Not ORReportData10697.DataRow Is Nothing) Then
                    If (Not ORReportData10697.DataRow Is Nothing) Then
                        If (Not ORReportData10697.DataRow.RowData Is Nothing) Then
                        End If
                        If (Not ORReportData10697.DataRow.ColDataList Is Nothing) Then
                            Dim i10698 As Integer
                            For i10698 = 0 To ORReportData10697.DataRow.ColDataList.Count - 1
                                Dim ColData As IColData
                                ColData = ORReportData10697.DataRow.ColDataList.GetAt(i10698)

                                qbdata(i10696 + 5, i10698) = ColData.value.GetValue.ToString

                            Next i10698
                        End If
                    End If
                End If
                If (Not ORReportData10697.TextRow Is Nothing) Then
                    If (Not ORReportData10697.TextRow Is Nothing) Then

                        qbdata(i10696 + 5, 0) = ORReportData10697.TextRow.value.GetValue.ToString

                    End If
                End If
                If (Not ORReportData10697.SubtotalRow Is Nothing) Then
                    If (Not ORReportData10697.SubtotalRow Is Nothing) Then
                        If (Not ORReportData10697.SubtotalRow.RowData Is Nothing) Then
                        End If
                        If (Not ORReportData10697.SubtotalRow.ColDataList Is Nothing) Then
                            Dim i10699 As Integer
                            For i10699 = 0 To ORReportData10697.SubtotalRow.ColDataList.Count - 1
                                Dim ColData As IColData
                                ColData = ORReportData10697.SubtotalRow.ColDataList.GetAt(i10699)

                                qbdata(i10696 + 5, i10699) = ColData.value.GetValue.ToString

                            Next i10699
                        End If
                    End If
                End If
                If (Not ORReportData10697.TotalRow Is Nothing) Then
                    If (Not ORReportData10697.TotalRow Is Nothing) Then
                        If (Not ORReportData10697.TotalRow.RowData Is Nothing) Then
                        End If
                        If (Not ORReportData10697.TotalRow.ColDataList Is Nothing) Then
                            Dim i10700 As Integer
                            For i10700 = 0 To ORReportData10697.TotalRow.ColDataList.Count - 1
                                Dim ColData As IColData
                                ColData = ORReportData10697.TotalRow.ColDataList.GetAt(i10700)

                                qbdata(i10696 + 5, i10700) = ColData.value.GetValue.ToString

                            Next i10700
                        End If
                    End If
                End If
            Next i10696
        End If
    End If




    ' Fill A2:B6 with an array of data
    shXL.Range("A1", "K205").Value = qbdata




    ' Make sure Excel is visible and give the user control
    ' of Excel's lifetime.
    appXL.Visible = True
    appXL.UserControl = True

    ' Release object references.
    raXL = Nothing
    shXL = Nothing
    wbXl = Nothing
    appXL.Quit()
    appXL = Nothing
End Sub
Public Sub BuildGeneralSummaryReportBalanceSheetQueryRq(requestMsgSet As IMsgSetRequest)


    Dim GeneralSummaryReportQueryRq As IGeneralSummaryReportQuery
    GeneralSummaryReportQueryRq = requestMsgSet.AppendGeneralSummaryReportQueryRq()

    'Set field value for GeneralSummaryReportType
    GeneralSummaryReportQueryRq.GeneralSummaryReportType.SetValue(ENGeneralSummaryReportType.gsrtBalanceSheetPrevYearComp)

    'Set field value for DisplayReport
    GeneralSummaryReportQueryRq.DisplayReport.SetValue(True)

    'set report period
    GeneralSummaryReportQueryRq.ORReportPeriod.ReportDateMacro.SetValue(ENReportDateMacro.rdmLastYear)

    'Set field value for ReportDetailLevelFilter
    GeneralSummaryReportQueryRq.ReportDetailLevelFilter.SetValue(ENReportDetailLevelFilter.rdlfAll)

    'Set field value for ReportPostingStatusFilter
    GeneralSummaryReportQueryRq.ReportPostingStatusFilter.SetValue(ENReportPostingStatusFilter.rpsfEither)

    'Set field value for SummarizeColumnsBy
    GeneralSummaryReportQueryRq.SummarizeColumnsBy.SetValue(ENSummarizeColumnsBy.scbTotalOnly)

    'Set field value for IncludeSubcolumns
    GeneralSummaryReportQueryRq.IncludeSubcolumns.SetValue(False)

    'Set field value for ReportCalendar
    GeneralSummaryReportQueryRq.ReportCalendar.SetValue(ENReportCalendar.rcFiscalYear)

    'Set field value for ReturnRows
    GeneralSummaryReportQueryRq.ReturnRows.SetValue(ENReturnRows.rrAll)

    'Set field value for ReturnColumns
    GeneralSummaryReportQueryRq.ReturnColumns.SetValue(ENReturnColumns.rcAll)

    'Set field value for ReportBasis
    GeneralSummaryReportQueryRq.ReportBasis.SetValue(ENReportBasis.rbCash)


End Sub
0 голосов
/ 01 мая 2020

Понял! У меня был ноль в первом элементе списка, и я не обрабатывал его

enter code here

    If (Not ReportRet.ColDescList Is Nothing) Then
        Dim i10693 As Integer
        For i10693 = 0 To ReportRet.ColDescList.Count - 1
            Dim ColDesc As IColDesc
            ColDesc = ReportRet.ColDescList.GetAt(i10693)
            If (Not ColDesc.ColTitleList Is Nothing) Then
                Dim i10694 As Integer
                For i10694 = 0 To ColDesc.ColTitleList.Count - 1
                    Dim ColTitle As IColTitle
                    ColTitle = ColDesc.ColTitleList.GetAt(i10694)
                    If (Not ColTitle.value Is Nothing) Then
                        qbdata(i10694 + 2, i10693) = ColTitle.value.GetValue.ToString
                    End If
                Next i10694
            End If
            Dim ColType10695 As ENColType
            ColType10695 = ColDesc.ColType.GetValue()
        Next i10693
    End If
...