V
V
vaaadimermolin2022-01-07 16:07:00
1C
vaaadimermolin, 2022-01-07 16:07:00

How to write data via com connection to DB 1s using python?

I managed to get data from the database in python, but how to implement an entry in the 1s directory?

from django.shortcuts import render

import pythoncom
import win32com.client

def index(request):
    V83_CONN_STRING = 'File="C:\\Users\\admin2\\Documents\\InfoBase18";Usr="Ермолин";Pwd="123";'
    pythoncom.CoInitialize()
    V83 = win32com.client.Dispatch("V83.COMConnector").Connect(V83_CONN_STRING)

    q = '''
    ВЫБРАТЬ
      ТестСправочник.Фамилия КАК Фамилия,
      ТестСправочник.Имя КАК Имя,
      ТестСправочник.Отчество КАК Отчество
    ИЗ
      Справочник.ТестСправочник КАК ТестСправочник
    '''

    query = V83.NewObject("Query", q)
    sel = query.Execute().Choose()

    num_category = []

    while sel.next():
        num_category.append(sel.Фамилия)
        num_category.append(sel.Имя)
        num_category.append(sel.Отчество)
        #break
    
    return render(request, 'index.html', context={'num_category':num_category},)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Konstantin Nagibovich, 2022-01-07
@vaaadimermolin

Try like this:

новЭлемент = V83.Справочники[ИмяСправочника].СоздатьЭлемент();

Well, then everything is as usual.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question