Exemplo n.º 1
0
 def __init__(self, xlsb_doc_path):
     self._xlsb_workbook = open_workbook(xlsb_doc_path)
     self._macrosheets = None
     self._defined_names = None
     self.xl_international_flags = {XlApplicationInternational.xlLeftBracket: '[',
                                    XlApplicationInternational.xlListSeparator: ',',
                                    XlApplicationInternational.xlRightBracket: ']'}
Exemplo n.º 2
0
def add_view(request):
    if request.method == 'POST':  # si el usuario está enviando el formulario con datos
        form = ExcelForm(request.POST, request.FILES)  # Bound form
        if form.is_valid():
            excel_file = request.FILES['file']

            new_file = form.save(
                commit=False)  # Guardar los datos en la base de datos

            lstRows = []
            totalQty = 0
            promedio = 0.0
            with open_workbook(excel_file) as wb:
                with wb.get_sheet_by_index(0) as sheet:
                    for row in sheet.rows():
                        invent = []
                        for c in row:
                            invent.append(c.value)
                        lstRows.append(invent)

            items = 0
            for row in lstRows:
                items += 1
                Inventory.objects.create(serie=int(row[0]),
                                         number_elements=int(row[1]),
                                         price=row[2])
                totalQty += row[1]
                promedio += row[2]

            promedio = promedio / items

            summary = {'elementos': totalQty, 'precio_promedio': promedio}

            new_file.summary = json.dumps(summary)
            new_file.save()

            return redirect('home')
    else:
        form = ExcelForm()  # Unbound form

    return render(request, 'inventory/form_file.html', {'form': form})
Exemplo n.º 3
0
import sys
import time
from pyxlsb2 import open_workbook
from pyxlsb2.formula import Formula

a = time.time()
print('Opening workbook... ', end='', flush=True)
with open_workbook(sys.argv[1]) as wb:
    d = time.time() - a
    print('Done! ({} seconds)'.format(d))
    for s in wb.sheets:
        print('Reading sheet {}...\n'.format(s), end='', flush=True)
        a = time.time()

        with wb.get_sheet_by_name(s.name) as sheet:
            for row in sheet:
                for cell in row:
                    formula_str = Formula.parse(cell.formula)
                    if formula_str._tokens:
                        try:
                            print(formula_str.stringify(wb))
                        except NotImplementedError as exp:
                            print('ERROR({}) {}'.format(exp, str(cell)))
                        except Exception:
                            print('ERROR ' + str(cell))
        d = time.time() - a
        print('Done! ({} seconds)'.format(d))
Exemplo n.º 4
0
 def setUp(self):
     self.wb = open_workbook(os.path.join('test_files', 'dates.xlsb'))
Exemplo n.º 5
0
 def __init__(self, xlsb_doc_path):
     self._xlsb_workbook = open_workbook(xlsb_doc_path)
     self._macrosheets = None
     self._defined_names = None