Esempio n. 1
0
def display():
    try:
        if 'file' in request.files:
            data=request.files['file'].read()
        elif request.form['url'].startswith('http'):
            data=urlopen(request.form['url']).read()
        else:
            return redirect(url_for('select'))
        img=ImageGrid(data)
        dim=img.dimensions()
        if dim[0]<=0 or dim[1]<=0:
            return render_template('select.html',error_msg='Failed to recognize crossword grid.')
        d=TableData(img=img)
        t=Table(d)
        return render_template('convert.html',table=t,data=d.to_json())
    except ValueError:
        return render_template('select.html',error_msg='File format not recognized.')
    except URLError as e:
        return render_template('select.html',error_msg='Could not load url: {}.'.format(e.reason.strerror))
Esempio n. 2
0
def form_data_to_excel(form):
    td=TableData.from_json(form['data'])
    g=Grid(td.height,td.width)
    if 'back' in form:
        g.features.extend(td.back)
    if 'bar' in form:
        g.features.extend(td.bars)
    if form['auto']=='auto':
        g.features.extend(autonumber(g))
    elif form['auto']=='text':
        g.features.extend(td.text)
    g.features.extend(outside_bars(g))
    i=BytesIO()
    to_openpyxl(g,text_in_cells='cells' in form,text_in_comments='comments' in form).save(i)
    i.seek(0)
    return i
Esempio n. 3
0
def form_data_to_excel(form):
    td = TableData.from_json(form['data'])
    g = Grid(td.height, td.width)
    if 'back' in form:
        g.features.extend(td.back)
    if 'bar' in form:
        g.features.extend(td.bars)
    if form['auto'] == 'text':
        g.features.extend(td.text)
    g.validate()
    if form['auto'] == 'auto':
        g.features.extend(autonumber(g))
    g.features.extend(outside_bars(g))
    i = BytesIO()
    to_openpyxl(g,
                text_in_cells='cells' in form,
                text_in_comments='comments' in form).save(i)
    i.seek(0)
    return i