On 12/23/2014 09:15 AM, Владимир Дроменко wrote:
> Thank you for your answers, Adrian!
>
> Ок, I take 'services' and 'codes' :
>
> for col_index in xrange(0,1):
> for row_index in xrange(9,sheet.nrows):
> service = "%03d" %
> (float(sheet.cell_value(row_index,col_index)))
First of why xrange(0, 1)?
Why not?:
for row_index in xrange(9,sheet.nrows):
service = "%03d" % (float(sheet.cell_value(row_index, 0))
>
> for row_index in xrange(7,8):
> for col_index in xrange(3,sheet.ncols):
> code = int(sheet.cell(row_index,col_index).value)
>
> And now I must create a dictionary.
> What key of dictionary I must use?
Not sure, it still not clear to me what you are trying to do?
Alright, went back and read your previous post, so I think:
Given
code0 code1 code2 code3 ....
service0 text value0 value0:1 value0:2 value0:3 ...
service1 text value1:0 value1:1 value1:2 value1:3 ...
and
"I must insert value, code and service into database."
then you need to build some sequence that has as each 'record' another sequence
that contains (service_value, code_value, cell_value). Not sure what your code
that inserts into the database needs to see for each record, a list, tuple or
dictionary. In any case the general principle is the same:
Untested code based on assumptions, no warranty given:)
Walk through the code header:
code_dict = {}
for col_index in xrange(3,sheet.ncols):
code = int(sheet.cell(7,col_index).value)
code_dict[col_index] = code
This builds a look up for the code values.
Then assuming dictionary records
records_list = []
for row_index in xrange(9,sheet.nrows):
service_val = sheet.cell(0, row_index).value
for col_index in xrange(4,sheet.ncols):
cell_val = sheet.cell(row_index, col_index).value
record_dict = dict(service=service_val, code=code_dict[col_index], cell=cell_val)
records_list.append(record_dict)
> <mailto:
adrian...@aklaver.com>>:
> an email to python-excel+unsubscribe@__
googlegroups.com
> <mailto:
python-excel%2Bunsu...@googlegroups.com>
> <mailto:
python-excel+...@googlegroups.com
> <mailto:
python-excel%2Bunsu...@googlegroups.com>>.
> To post to this group, send email to
>
python...@googlegroups.com <mailto:
python...@googlegroups.com>
> <mailto:
python-excel@__
googlegroups.com
> <mailto:
python...@googlegroups.com>>.
> Visit this group at
>
http://groups.google.com/__group/python-excel
> <
http://groups.google.com/group/python-excel>.
> For more options, visit
https://groups.google.com/d/__optout
> <
https://groups.google.com/d/optout>.
>
>
>
> --
> Adrian Klaver
>
adrian...@aklaver.com <mailto:
adrian...@aklaver.com>
>
> --
> You received this message because you are subscribed to a topic in
> the Google Groups "python-excel" group.
> To unsubscribe from this topic, visit
>
https://groups.google.com/d/__topic/python-excel/__cZxhlprdsQQ/unsubscribe
> <
https://groups.google.com/d/topic/python-excel/cZxhlprdsQQ/unsubscribe>.
> To unsubscribe from this group and all its topics, send an email to
> python-excel+unsubscribe@__
googlegroups.com
> <mailto:
python-excel%2Bunsu...@googlegroups.com>.
> To post to this group, send an email to
>
python...@googlegroups.com <mailto:
python...@googlegroups.com>.
>
> Visit this group at
http://groups.google.com/__group/python-excel
> <
http://groups.google.com/group/python-excel>.
> For more options, visit
https://groups.google.com/d/__optout
> <
https://groups.google.com/d/optout>.
>
>
> --
> You received this message because you are subscribed to the Google
> Groups "python-excel" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to
python-excel...@googlegroups.com
> <mailto:
python-excel...@googlegroups.com>.
> <mailto:
python...@googlegroups.com>.