Bumblebee Export Diff

Criado O diff nunca expira
0 remoções
195 linhas
1 adição
196 linhas
# Copyright(c) 2016, David Mans, Konrad Sobon
# Copyright(c) 2016, David Mans, Konrad Sobon
# @arch_laboratory, http://archi-lab.net, http://neoarchaic.net
# @arch_laboratory, http://archi-lab.net, http://neoarchaic.net


import clr
import clr
import sys
import sys
import System
import System
from System import Array
from System import Array
from System.Collections.Generic import *
from System.Collections.Generic import *


clr.AddReferenceByName('Microsoft.Office.Interop.Excel, Version=11.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c')
clr.AddReferenceByName('Microsoft.Office.Interop.Excel, Version=11.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c')
from Microsoft.Office.Interop import Excel
from Microsoft.Office.Interop import Excel
System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo("en-US")
System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo("en-US")
from System.Runtime.InteropServices import Marshal
from System.Runtime.InteropServices import Marshal


pyt_path = r'C:\Program Files (x86)\IronPython 2.7\Lib'
pyt_path = r'C:\Program Files (x86)\IronPython 2.7\Lib'
sys.path.append(pyt_path)
sys.path.append(pyt_path)


from os import path
from os import path
assemblies = System.AppDomain.CurrentDomain.GetAssemblies()
assemblies = System.AppDomain.CurrentDomain.GetAssemblies()
path1 = [a.Location for a in assemblies if 'bumblebee,' in a.FullName][0]
path1 = [a.Location for a in assemblies if 'bumblebee,' in a.FullName][0]
path2 = System.IO.Path.GetDirectoryName(path1).rsplit('\\',1)[0]
path2 = System.IO.Path.GetDirectoryName(path1).rsplit('\\',1)[0]
bb_path = '%s\\extra\\' %path2
bb_path = '%s\\extra\\' %path2
sys.path.append(bb_path)
sys.path.append(bb_path)
import bumblebee as bb
import bumblebee as bb
import os
import os


#The inputs to this node will be stored as a list in the IN variable.
#The inputs to this node will be stored as a list in the IN variable.
dataEnteringNode = IN
dataEnteringNode = IN


filePath = IN[0]
filePath = IN[0]
runMe = IN[1]
runMe = IN[1]
byColumn = IN[2]
byColumn = IN[2]
data = IN[3]
data = IN[3]


if filePath != None:
if filePath != None:
if filePath.GetType() == System.IO.FileInfo:
if filePath.GetType() == System.IO.FileInfo:
filePath = filePath.FullName
filePath = filePath.FullName


def LiveStream():
def LiveStream():
try:
try:
xlApp = Marshal.GetActiveObject("Excel.Application")
xlApp = Marshal.GetActiveObject("Excel.Application")
xlApp.Visible = True
xlApp.Visible = True
xlApp.DisplayAlerts = False
xlApp.DisplayAlerts = False
return xlApp
return xlApp
except:
except:
return None
return None


def SetUp(xlApp):
def SetUp(xlApp):
# supress updates and warning pop ups
# supress updates and warning pop ups
xlApp.Visible = False
xlApp.Visible = False
xlApp.DisplayAlerts = False
xlApp.DisplayAlerts = False
xlApp.ScreenUpdating = False
xlApp.ScreenUpdating = False
return xlApp
return xlApp


def WriteData(ws, data, byColumn, origin):
def WriteData(ws, data, byColumn, origin):


def FillData(x, y, x1, y1, ws, data, origin):
def FillData(x, y, x1, y1, ws, data, origin):
if origin != None:
if origin != None:
x = x + origin[1]
x = x + origin[1]
y = y + origin[0]
y = y + origin[0]
else:
else:
x = x + 1
x = x + 1
y = y + 1
y = y + 1
if y1 != None:
if y1 != None:
ws.Cells[x, y] = data[x1][y1]
ws.Cells[x, y] = data[x1][y1]
else:
else:
ws.Cells[x, y] = data[x1]
ws.Cells[x, y] = data[x1]
ws.Columns.AutoFit()
return ws
return ws
# if data is a nested list (multi column/row) use this
# if data is a nested list (multi column/row) use this
if any(isinstance(item, list) for item in data):
if any(isinstance(item, list) for item in data):
for i, valueX in enumerate(data):
for i, valueX in enumerate(data):
for j, valueY in enumerate(valueX):
for j, valueY in enumerate(valueX):
if byColumn:
if byColumn:
FillData(j,i,i,j, ws, data, origin)
FillData(j,i,i,j, ws, data, origin)
else:
else:
FillData(i,j,i,j, ws, data, origin)
FillData(i,j,i,j, ws, data, origin)
# if data is just a flat list (single column/row) use this
# if data is just a flat list (single column/row) use this
else:
else:
for i, valueX in enumerate(data):
for i, valueX in enumerate(data):
if byColumn:
if byColumn:
FillData(i,0,i,None, ws, data, origin)
FillData(i,0,i,None, ws, data, origin)
else:
else:
FillData(0,i,i,None, ws, data, origin)
FillData(0,i,i,None, ws, data, origin)
return ws
return ws


def ExitExcel(filePath, xlApp, wb, ws):
def ExitExcel(filePath, xlApp, wb, ws):
# clean up before exiting excel, if any COM object remains
# clean up before exiting excel, if any COM object remains
# unreleased then excel crashes on open following time
# unreleased then excel crashes on open following time
def CleanUp(_list):
def CleanUp(_list):
if isinstance(_list, list):
if isinstance(_list, list):
for i in _list:
for i in _list:
Marshal.ReleaseComObject(i)
Marshal.ReleaseComObject(i)
else:
else:
Marshal.ReleaseComObject(_list)
Marshal.ReleaseComObject(_list)
return None
return None
wb.SaveAs(unicode(filePath))
wb.SaveAs(unicode(filePath))
xlApp.ActiveWorkbook.Close(False)
xlApp.ActiveWorkbook.Close(False)
xlApp.ScreenUpdating = True
xlApp.ScreenUpdating = True