基于名称的PHP计算单元数据

基于名称的PHP计算单元数据,php,excel,vba,Php,Excel,Vba,我已经对表单中的一些数据做了一段时间的手动报告,现在我得到的数据量太多了,一开始是50个条目,现在超过500个,所以我需要找到一种更简单的方法来管理它。我认为一个PHP程序可能会使这更容易 基本上我有如下数据,我需要按用户排序,并计算每个用户有多少潜在客户 列 用户名|主要来源 皮特M,领队1 菲奥娜L,铅2 请记住,这个csv文件相当大,我想知道是否有人比我手动使用excel公式更容易解决这个问题 非常感谢,我意识到问题是关于PHP的,但正如我所建议的VBScript,如果您选择VBScrip

我已经对表单中的一些数据做了一段时间的手动报告,现在我得到的数据量太多了,一开始是50个条目,现在超过500个,所以我需要找到一种更简单的方法来管理它。我认为一个PHP程序可能会使这更容易

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

用户名|主要来源

皮特M,领队1

菲奥娜L,铅2

请记住,这个csv文件相当大,我想知道是否有人比我手动使用excel公式更容易解决这个问题


非常感谢,

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

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

我想我会倾向于使用
脚本字典
来维护找到的每个用户的潜在客户数量

选项显式
常数ForReading=1
写入常数=2
出现的常数=8
' 
Const XLS\u SOURCEFILE=“C:\data\spreadsheet.XLS”
调用processxls(1,2,XLS_源文件,“Sheet1”)
'
'总体思路是提供一个列索引(iKeyCol)
'只要每一行的单元格中都有一些内容
'脚本将运行(直到命中空单元格)
'
'iKeyRow'是要开始的行-如果您有列标题等
”“那么在那次争吵之后呢
'
'如果在调用sub时将第3个参数设置为NULL,则系统将提示您浏览要使用的文件。
'
'
'
'
子进程xls(iKeyCol、iKeyRow、文件名、sheetname)
暗色oExcel
暗色牛津笔记本
暗色牛津纸
Dim strFilename
尺寸r:r=iKeyRow
'***获取源文件***
strFilename=getfile(文件名)
'***如果没有源文件,则放弃***
如果(strFilename=FALSE),则
调用KillObjects()
MsgBox“已取消”
出口接头
如果结束
'***创建excel对象***
设置oExcel=CreateObject(“Excel.Application”)
oExcel.Visible=True
oExcel.DisplayAlerts=True
设置oXLWrkBook=oExcel.Workbooks.Open(strFilename)
设置oXLSheet=OxlWorkBook.Worksheets(图纸名称)
oXLSheet.激活
Do While oXLSheet.Cells(r,iKeyCol).value“”
出错时继续下一步
“***在这里,您可以根据需要以任何方式处理数据
数据=oXLSheet.Cells(r,iKeyCol).value
'增加行计数器-否则发出隆隆声!
r=r+1
环
oXLWrkBook,保存
oExcel,退出
调用KillObjects()
MsgBox“所有操作已完成”
端接头
函数getfile(显式路径)
如果(isNull(explicitpath)或explicitpath=false),则
Dim oShell:Set oShell=CreateObject(“WScript.Shell”)

If(GetOSVersion()我意识到问题是关于PHP的,但正如我所建议的VBScript,我认为如果您选择VBScript来格式化报告,以下内容可能会很有用。多年前,我必须格式化一份通常需要一个多小时的报告,并且由于源数据发生更改,因此需要再次运行—因此我使用VBScript并将时间缩短为分钟(vb远比这复杂)

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

我想我会倾向于使用
脚本字典
来维护找到的每个用户的潜在客户数量

选项显式
常数ForReading=1
写入常数=2
出现的常数=8
' 
Const XLS\u SOURCEFILE=“C:\data\spreadsheet.XLS”
调用processxls(1,2,XLS_源文件,“Sheet1”)
'
'总体思路是提供一个列索引(iKeyCol)
'只要每一行的单元格中都有一些内容
'脚本将运行(直到命中空单元格)
'
'iKeyRow'是要开始的行-如果您有列标题等
”“那么在那次争吵之后呢
'
'如果在调用sub时将第3个参数设置为NULL,则系统将提示您浏览要使用的文件。
'
'
'
'
子进程xls(iKeyCol、iKeyRow、文件名、sheetname)
暗色oExcel
暗色牛津笔记本
暗色牛津纸
Dim strFilename
尺寸r:r=iKeyRow
'***获取源文件***
strFilename=getfile(文件名)
'***如果没有源文件,则放弃***
如果(strFilename=FALSE),则
调用KillObjects()
MsgBox“已取消”
出口接头
如果结束
'***创建excel对象***
设置oExcel=CreateObject(“Excel.Application”)
oExcel.Visible=True
oExcel.DisplayAlerts=True
设置oXLWrkBook=oExcel.Workbooks.Open(strFilename)
设置oXLSheet=OxlWorkBook.Worksheets(图纸名称)
oXLSheet.激活
Do While oXLSheet.Cells(r,iKeyCol).value“”
出错时继续下一步
“***在这里,您可以根据需要以任何方式处理数据
数据=oXLSheet.Cells(r,iKeyCol).value
'增加行计数器-否则发出隆隆声!
r=r+1
环
oXLWrkBook,保存
oExcel,退出
调用KillObjects()
MsgBox“所有操作已完成”
端接头
函数getfile(显式路径)
如果(isNull(explicitpath)或explicitpath=false),则
Dim oShell:Set oShell=CreateObject(“WScript.Shell”)

如果(GetOSVersion()使用透视表越来越容易,越来越快

使用透视表越来越容易,越来越快

虽然不是PHP,但我建议使用VBScript,我也不建议使用PHP,但我会选择数据库表方法。从长远来看,这会使数据集的管理变得更容易
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