Exemplo n.º 1
0
	def run(self):
		print("starting thread " + self.process_name)
		#make app/pid open book inside app
		print(xw.apps, self.pid)
		if self.pid is None:
			app = xw.apps.add()			
			self.pid = app.pid
		else:
			app = xw.apps(self.pid)
		#self.pid = app.pid
		order_sheet = app.books.open(self.file_location)
		#order_sheet = xw.Book(self.file_location)
		print("ending thread " + self.process_name)
		return order_sheet
Exemplo n.º 2
0
 def test_keys(self):
     k = xw.apps.keys()[0]
     self.assertEqual(xw.apps[k], xw.apps(k))
Exemplo n.º 3
0
def RunVBA(xlsmX, ModuleX_SubX, unitx, dayd, opt):
    global temp_logstr
    if unitx == 'month' and int(
            datetime.now().strftime('%d')) == int(dayd) or unitx != 'month':
        #RunIt = RunVBA.RunX(VBAxlsm,VBAMod)
        strToPrint = str(xlsmX)
        L = strToPrint.split('\\')
        print('Start  ' + L[-1] + '  At  ' +
              str(datetime.now().strftime('%Y-%m-%d %H:%M:%S')))
        temp_logstr = temp_logstr + 'Start  ' + L[-1] + '  At  ' + str(
            datetime.now().strftime('%Y-%m-%d %H:%M:%S')) + "\n"
        # mainframe.updatelog()
        #temp_logstr =  temp_logstr + "\n"

        timestart = datetime.now()
        xl_app = xw.App(visible=False, add_book=False)
        wb = xl_app.books.open(xlsmX)
        app_pid = xw.apps.keys()

        if unitx == 'month' and int(opt) == 1:
            info_sheet = xw.apps(app_pid[0]).books(L[-1]).sheets('Info')
            info_sheet.range('F6').value = 1
            info_sheet.range('F7').value = 1
            info_sheet.range('F8').value = 1
            info_sheet.range('F17').value = 0
        elif unitx != 'month' and int(opt) == 1:
            info_sheet = xw.apps(app_pid[0]).books(L[-1]).sheets('Info')
            info_sheet.range('F6').value = 1
            info_sheet.range('F7').value = 1
            info_sheet.range('F8').value = 0
            info_sheet.range('F17').value = 0

        wb.app.calculation = 'manual'
        wb.app.screen_updating = False
        wb.app.display_alerts = False
        run_macro = wb.app.macro(ModuleX_SubX)
        run_macro()

        if len(xw.apps) == 1:
            wb.app.calculation = 'automatic'
            wb.app.screen_updating = True
            wb.app.display_alerts = False
            xl_app.kill()
        elif len(xw.apps) > 1:
            wb.app.calculation = 'automatic'
            wb.app.screen_updating = True
            wb.app.display_alerts = False
            wb.save()
            wb.close
            xl_app.quit()
            #print(len(xw.apps))

        elapsedtime = datetime.now() - timestart
        temp_logstr = temp_logstr + 'End    ' + 'At  ' + str(
            datetime.now().strftime('%Y-%m-%d %H:%M:%S')
        ) + '   Elapsed time {}'.format(elapsedtime) + "\n"
        print('End    ' + 'At  ' +
              str(datetime.now().strftime('%Y-%m-%d %H:%M:%S')) +
              '   Elapsed time {}'.format(elapsedtime))
        temp_logstr = temp_logstr + "\n"
        #mainframe.updatelog()
        print(' ')
        print(temp_logstr)
    return
Exemplo n.º 4
0
 def test_indexing(self):
     self.assertEqual(xw.apps[0], xw.apps(1))
Exemplo n.º 5
0
# A Range can be instantiated with A1 notation, a tuple of Excel’s 1-based indices, a named range or two Range objects
xw.Range('E1').value = 'E1'
xw.Range('G1:G3').value = 'G1:G3'
tst = xw.Range('E2:F3')
for x in tst:
    x.value = 'E2:F3'
xw.Range((1, 8)).value = "'1:8"
xw.Range((1, 9), (3, 9)).value = "'1:9 to 3:9"
xw.Range('Namedrange').value = 'Namedrange'
xw.Range(xw.Range('H1'), xw.Range('H2')).value = 'H1:H2'

# Round brackets follow Excel’s behavior (i.e. 1-based indexing), while square brackets use Python’s
# 0-based indexing/slicing. As an example, the following expressions all reference the same range
xw.apps[0].books[0].sheets[0].range('J1').value = 1
xw.apps(1).books(1).sheets(1).range('J2').value = 1
xw.apps[0].books['PythonTest.xlsm'].sheets['Sheet1'].range('J3').value = 1
xw.apps(1).books('PythonTest.xlsm').sheets('Sheet1').range('J4').value = 1

# Range indexing & slicing
print('********* Index / Slice *************')
rng = wb.sheets[0].range('A1:D5')
print(rng[0, 0])
print(rng[0, 1])
print(rng[1])
print(rng[:, :])  # returns A1:D5 (all rows , all col)
print(rng[1:3, 1:3])  # returns B2:C3 (rows 2 to 3 - 1, col B to D - 1)
print(rng[1:4, :2])  # returns A2:B4 (rows 2 to 5 - 1, col A to C - 1)
print(rng[:4, :2])
print(sht['A1'])
print(sht['A1:B5'])
Exemplo n.º 6
0
wb = app.books.active   # in specific app

# Active sheet
sht = xw.sheets.active   # in active book
sht = wb.sheets.active   # in specific book

# Range on active sheet
xw.Range('A1')
xw.Range('A1:C3')
xw.Range((1,1))
xw.Range((1,1), (3,3))
xw.Range('NamedRange')
xw.Range(xw.Range('A1'), xw.Range('B2'))

xw.apps[0].books[0].sheets[0].range('A1')
xw.apps(1).books(1).sheets(1).range('A1')
xw.apps[0].books['Book1'].sheets['Sheet1'].range('A1')
xw.apps(1).books('Book1').sheets('Sheet1').range('A1')

# rng = xw.Book().sheets[0].range('A1:D5')
rng = xw.books[0].sheets[0].range('A1:D5')
rng[0,0]
rng[1]
rng[:,3:]
rng[1:3,1:3]

# rnage shortcuts
sht = xw.books[0].sheets['Sheet1']
sht['A1']
sht['A1:B5']
sht[0,1]
Exemplo n.º 7
0
 def test_keys(self):
     k = xw.apps.keys()[0]
     self.assertEqual(xw.apps[k], xw.apps(k))