PHP根据名称计算单元格数据

时间:2017-06-05 08:02:33

标签: php excel excel-vba vba

我已经对表格中的某些数据进行了一段时间的手动报告,而且我现在得到的数据量相当多,最初是50个条目现在超过500,所以我需要找到一种更简单的方法来管理它。我认为PHP程序可以使这更容易。

基本上我有以下数据,我需要按用户排序并计算每个用户有多少潜在客户。

用户名|主要来源

Pete M,Lead 1

Fiona L,Lead 2

请记住这个csv文件非常大,我想知道是否有人比我做一个手动excel公式更容易解决这个问题。

非常感谢,

2 个答案:

答案 0 :(得分:0)

我意识到问题是关于PHP的,但正如我建议的VBScript我认为如果您选择使用vbscript格式化报告,以下内容可能会有用。多年前我不得不格式化一个通常需要一个多小时的报告,因为需要再次运行源数据 - 所以我使用了vbscript并将时间减少到几分钟(vb远比这复杂得多)< / p>

我知道下面的格式看起来很奇怪,在vbscript中没有块注释所以使用单引号。无论如何,希望它可以给你一个起点。

我想我很想使用Scripting Dictionary来维护每个找到的用户的潜在客户数量。 Useful guide to scripting dictionary

OPTION EXPLICIT
Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8



' 
Const XLS_SOURCEFILE="C:\data\spreadsheet.xls"

call processxls( 1, 2, XLS_SOURCEFILE, "Sheet1")

'
' the general idea is that you supply a column index ( iKeyCol )
' and so long as there is something in that cell for each row
' the script will run ( until it hits an empty cell )
'
' the `iKeyRow` is the row to start on - if you have column headers etc
' then after that row perhaps
'
' If you set the 3rd parameter to NULL when calling the sub you will be prompted to browse for the file to use.
'
'
'
'
Sub processxls( iKeyCol, iKeyRow, filename, sheetname )
    Dim oExcel
    Dim oXLWrkBook
    Dim oXLSheet

    Dim strFilename
    Dim r: r = iKeyRow

    '*** Get the source file ***
    strFilename=getfile( filename )


    '*** Abandon if no sourcefile ***
    If( strFilename=FALSE ) Then
        Call KillObjects()
        MsgBox "Cancelled"
        Exit Sub
    End If



    '*** Create the excel object ***
    Set oExcel = CreateObject("Excel.Application")
    oExcel.Visible = True
    oExcel.DisplayAlerts = True

    Set oXLWrkBook = oExcel.Workbooks.Open(strFilename)
    Set oXLSheet = oXLWrkBook.Worksheets(sheetname)

    oXLSheet.Activate






    Do While oXLSheet.Cells( r, iKeyCol ).value <> ""
        On Error Resume Next

        '*** here is where you process your data in whatever manner you need
        data=oXLSheet.Cells( r, iKeyCol ).value



        ' increment row counter - otherwise boom!
        r=r+1
    loop



    oXLWrkBook.Save
    oExcel.Quit


    Call KillObjects()


    MsgBox "All operations completed"
End Sub






























Function getfile( explicitpath )
    if( isNull( explicitpath ) or explicitpath=false )then
        Dim oShell:Set oShell = CreateObject( "WScript.Shell" )
        If ( GetOSVersion() <= 5 ) Then
            '*** Win XP & similar ***

            Dim defaultLocalDir: defaultLocalDir = oShell.ExpandEnvironmentStrings("%USERPROFILE%") & "\Desktop"
            Set oShell = Nothing

            Set cd = CreateObject("UserAccounts.CommonDialog")
            cd.InitialDir = initialDir
            cd.Filter = "All Files|*.*"
            cd.FilterIndex = 1

            If cd.ShowOpen = True Then
                getfile = cd.FileName
            Else
                getfile = ""
            End If

            Set cd = Nothing    

        Else
            '*** Vista onwards ***
            Dim oExec:Set oExec = oShell.Exec( "mshta.exe ""about: <input type=file id=file><script>file.click();new ActiveXObject('Scripting.FileSystemObject').GetStandardStream(1).WriteLine(X.value);close();resizeTo(0,0);</script>""" )
            getfile = Replace( oExec.StdOut.ReadAll, vbCRLF, "" )
            Set oExec = Nothing
        End If
    else
        getfile=explicitpath
    end if

    Set oShell = Nothing
End Function

Function GetOSVersion()
    Dim oItem
    Dim oWMI:Set oWMI = GetObject("winmgmts:\\.\root\CIMV2")
    Dim Items:Set Items = oWMI.ExecQuery("SELECT * FROM Win32_OperatingSystem",,48)
    For Each oItem in Items
        GetOSVersion = split( oItem.Version, "." )(0)
    Next
End Function

Sub KillObjects()
    If IsObject(oExcel) Then Set oExcel=nothing
    If IsObject(oXLWrkBook) Then Set oXLWrkBook=nothing
    If IsObject(oXLSheet) Then Set oXLSheet=nothing
    If IsObject(oWMI) Then Set oWMI=nothing
End Sub

答案 1 :(得分:0)

使用数据透视表更容易,更快捷