来自Power Pivot的翻录数据(“Item.data”)

我已经收到一份工作手册,其中包含两个表格(一个大约1毫米的行,另外一个20毫米的行)。 我想撕掉这个(真的是什么 – 但是让我们说一个CSV),以便我可以在R + PostGreSQL中使用它。

由于行数超过100万行,因此无法导出到Excel表格; 和复制粘贴数据只有当我select大约200,000行时才起作用。 所以我有点卡住了! 我试图将xlsx转换成zip文件,然后在记事本++中打开“item.data”文件,但是它被encryption了。

我会很感激任何解决scheme(高兴使用VBA,Python,SQL)

编辑:我把一些工作好的VBA放在0.5毫米左右的行然而打破了17毫米的行文件:

Public Sub CreatePowerPivotDmvInventory() Dim conn As ADODB.Connection Dim sheet As Excel.Worksheet Dim wbTarget As Workbook On Error GoTo FailureOutput Set wbTarget = ActiveWorkbook wbTarget.Model.Initialize Set conn = wbTarget.Model.DataModelConnection.ModelConnection.ADOConnection ' Call function by passing the DMV name ' Eg Partners WriteDmvContent "Partners", conn MsgBox "Finished" Exit Sub FailureOutput: MsgBox Err.Description End Sub Private Sub WriteDmvContent(ByVal dmvName As String, ByRef conn As ADODB.Connection) Dim rs As ADODB.Recordset Dim mdx As String Dim i As Integer mdx = "EVALUATE " & dmvName Set rs = New ADODB.Recordset rs.ActiveConnection = conn rs.Open mdx, conn, adOpenForwardOnly, adLockOptimistic ' Setup CSV file (improve this code) Dim myFile As String myFile = "H:\output_table_" & dmvName & ".csv" Open myFile For Output As #1 ' Output column names For i = 0 To rs.Fields.count - 1 If i = rs.Fields.count - 1 Then Write #1, rs.Fields(i).Name Else Write #1, rs.Fields(i).Name, End If Next i ' Output of the query results Do Until rs.EOF For i = 0 To rs.Fields.count - 1 If i = rs.Fields.count - 1 Then Write #1, rs.Fields(i) Else Write #1, rs.Fields(i), End If Next i rs.MoveNext Loop Close #1 rs.Close Set rs = Nothing Exit Sub FailureOutput: MsgBox Err.Description End Sub 

DAX Studio将允许您在Excel工作簿中查询数据模型并输出为各种格式,包括平面文件。

您需要的查询只是:

 EVALUATE <table name> 

我发现了一个工作(VBA)的解决scheme[但是greggy也适用于我!] – >我的表太大,不能导出一个块,所以我循环过滤'月'。 这似乎工作,并产生一个1.2 GB的CSV后,我把所有在一起:

 Function YYYYMM(aDate As Date) YYYYMM = year(aDate) * 100 + month(aDate) End Function Function NextYYYYMM(YYYYMM As Long) If YYYYMM Mod 100 = 12 Then NextYYYYMM = YYYYMM + 100 - 11 Else NextYYYYMM = YYYYMM + 1 End If End Function Public Sub CreatePowerPivotDmvInventory() Dim conn As ADODB.Connection Dim tblname As String Dim wbTarget As Workbook On Error GoTo FailureOutput Set wbTarget = ActiveWorkbook wbTarget.Model.Initialize Set conn = wbTarget.Model.DataModelConnection.ModelConnection.ADOConnection ' Call function by passing the DMV name tblname = "table1" WriteDmvContent tblname, conn MsgBox "Finished" Exit Sub FailureOutput: MsgBox Err.Description End Sub Private Sub WriteDmvContent(ByVal dmvName As String, ByRef conn As ADODB.Connection) Dim rs As ADODB.Recordset Dim mdx As String Dim i As Integer 'If table small enough: 'mdx = "EVALUATE " & dmvName 'Other-wise filter: Dim eval_field As String Dim eval_val As Variant 'Loop through year_month Dim CurrYM As Long, LimYM As Long Dim String_Date As String CurrYM = YYYYMM(#12/1/2000#) LimYM = YYYYMM(#12/1/2015#) Do While CurrYM <= LimYM String_Date = CStr(Left(CurrYM, 4)) + "-" + CStr(Right(CurrYM, 2)) Debug.Print String_Date eval_field = "yearmonth" eval_val = String_Date mdx = "EVALUATE(CALCULATETABLE(" & dmvName & ", " & dmvName & "[" & eval_field & "] = """ & eval_val & """))" Debug.Print (mdx) Set rs = New ADODB.Recordset rs.ActiveConnection = conn rs.Open mdx, conn, adOpenForwardOnly, adLockOptimistic ' Setup CSV file (improve this code) Dim myFile As String myFile = "H:\vba_tbl_" & dmvName & "_" & eval_val & ".csv" Debug.Print (myFile) Open myFile For Output As #1 ' Output column names For i = 0 To rs.Fields.count - 1 If i = rs.Fields.count - 1 Then Write #1, """" & rs.Fields(i).Name & """" Else Write #1, """" & rs.Fields(i).Name & """", End If Next i ' Output of the query results Do Until rs.EOF For i = 0 To rs.Fields.count - 1 If i = rs.Fields.count - 1 Then Write #1, """" & rs.Fields(i) & """" Else Write #1, """" & rs.Fields(i) & """", End If Next i rs.MoveNext Loop CurrYM = NextYYYYMM(CurrYM) i = i + 1 Close #1 rs.Close Set rs = Nothing Loop Exit Sub FailureOutput: MsgBox Err.Description End Sub